Answer the question
In order to leave comments, you need to log in
How to rotate an object in opengl es 2.0 without moving?
When you rotate the square on the Z axis, it moves slightly to the side and up.
Here is the GLRenderer code:
@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);
}
Answer the question
In order to leave comments, you need to log in
The fact is that you are rotating about the center of coordinates, but you need to - about the center of the object.
Entii, I understand that. Can you please explain how to rotate around the center of an object?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question