Android with OpenGL using the setLookAtM method

As a newbie to android and openGL 2.0 es, I test simple things and see how this happens.

I downloaded the sample at http://developer.android.com/training/graphics/opengl/touch.html .

I changed the code to check whether it is possible to animate the rotation of the camera around the (0,0,0) point, the center of the square.

So, I did this:

public void onDrawFrame(GL10 unused) {
    // Draw background color
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    // Set the camera position (View matrix)
    long time = SystemClock.uptimeMillis() % 4000L;
    float angle = ((float) (2*Math.PI)/ (float) 4000) * ((int) time);
    Matrix.setLookAtM(mVMatrix, 0, (float) (3*Math.sin(angle)), 0, (float) (3.0f*Math.cos(angle)),     0 ,0, 0,     0f, 1.0f, 0.0f);

    // Calculate the projection and view transformation
    Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);

    // Draw square
    mSquare.draw(mMVPMatrix);
}

I expected that the camera will always look in the center of the square (point 0,0,0), but this is not what is happening. The camera does rotate around the square, but the square does not remain in the center of the screen. Instead, it moves along the X axis ...: enter image description hereenter image description here

I also expected that if we give eyeX and eyeY the same values ​​as centerX and centerY, like this:

Matrix.setLookAtM(mVMatrix, 0, 1, 1, -3,     1 ,1, 0,     0f, 1.0f, 0.0f);

( , , , ), , :

enter image description here

:

float ratio = (float) width / height;

// this projection matrix is applied to object coordinates
// in the onDrawFrame() method
Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 2, 7);

?

+4
1

, , , .

, OpenGL ,

transformed vertex = projMatrix * viewMatrix * modelMatrix * input vertex

, , :

" gl_Position = vPosition * uMVPMatrix;"

. , OpenGL, , lhs/rhs .

, :

" gl_Position = uMVPMatrix * vPosition;"

, .

+8

All Articles