3

I trying to display object with opengl es 3. Everything works till i trying to set camera view. When I multiply my vPMatrix with camera matrix and projection matrix object just disapears.

            float[] projectionMatrix = new float[16];
            float[] vPMatrix = new float[16];
            float[] camera = new float[16];
            Matrix.frustumM(
                    projectionMatrix,
                    0,
                    -1,
                    1,
                    -1,
                    1,
                    3,
                    7
            );

            Matrix.setLookAtM(
                    camera
                    , 0
                    //where i am
                    , 0f
                    , 0f
                    , 1f
                    //what i looking for
                    , 0f
                    , 0f
                    , -1f
                    //where is top
                    , 0f
                    , 1f
                    , 0f
            );


            Matrix.multiplyMM(
                    vPMatrix,
                    0,
                    projectionMatrix,
                    0,
                    camera,
                    0
            );
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Bogus
  • 283
  • 1
  • 2
  • 13

2 Answers2

0

I fixed that bug by setting camera as below:

Matrix.setLookAtM(
                    camera
                    , 0
                    //where i am
                    , 0f
                    , 0f
                    , 5f
                    //what i looking for
                    , 0f
                    , 0f
                    , 0f
                    //where is top
                    , 0f
                    , 1f
                    , 0f
            );

but i dont understand why old version was bad (what i looking for z). If enyone can explain me this then please post youre answer.

Bogus
  • 283
  • 1
  • 2
  • 13
0

Moste likely the geometry is clipped by the near plane of the Viewing frustum. Note, if the geometry is not between the near and far plane, the geoemtry is clipped.

You specified a distance to the near plane of 3 and a distance to the far plane of 7 when setting the perspective projection:

Matrix.frustumM(projectionMatrix, 0, -1, 1, -1, 1, 3, 7);

But the distance of the point of view to the the center fot the worlds is just 1:

Matrix.setLookAtM(camera, 0, 0f, 0f, 1f, ...);

You have 2 options. Either change the point of view:

Matrix.setLookAtM(camera, 0, 0f, 0f, 5f, ...);

Or change the near and far plane. For instance:

Matrix.frustumM(projectionMatrix, 0, -1, 1, -1, 1, 0.1, 100);
Rabbid76
  • 202,892
  • 27
  • 131
  • 174