При повороте квадрата по оси Z, он перемещается немного в сторону и вверх
Вот код GLRenderer :
@Override
public void onSurfaceCreated (GL10 gl10, EGLConfig eglConfig) {
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
square = new Square(100, 100, 100, 100);
}
@Override
public void onDrawFrame (GL10 gl10) {
// Draw background color
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// Set the camera position (View matrix)
Matrix.setLookAtM(ViewMatrix, 0, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
// Calculate the projection and view transformation
Matrix.multiplyMM(MVPMatrix, 0, ProjectionMatrix, 0, ViewMatrix, 0);
// Квадрат без поворота
drawShape(square, MVPMatrix);
Matrix.setIdentityM(ModelMatrix, 0);
Matrix.rotateM(ModelMatrix, 0, 10.0f, 0.0f, 0.0f, 1.0f);
Matrix.multiplyMM(MVPMatrix, 0, MVPMatrix, 0, ModelMatrix, 0);
// Квадрат с поворотом
drawShape(square, MVPMatrix);
}
@Override
public void onSurfaceChanged (GL10 gl10, int width, int height) {
// Adjust the viewport based on geometry changes,
// such as screen rotation
GLES20.glViewport(0, 0, width, height);
Matrix.orthoM(ProjectionMatrix, 0, 0.0f, width, 0.0f, height, 0.0001f, 1.0f);
}