I try to rotate a .obj 3d model around its own axis using glRotatef. But it's not working as I wish.
Code
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glEnable(GL10.GL_LIGHTING);
gl.glLoadIdentity();
gl.glTranslatef(0f, -1.2f, -z);
gl.glRotatef(xrot, 1f, 0f, 0f);
gl.glRotatef(yrot, 0f, 1f, 0f);
model.draw(gl);
}
Problem
The first rotation yrot works pretty good : no matter the position of the model, it always rotates around its own z (well, I ask to rotate around y so it's not perfect. But at least it uses one of its own axis!)
Now when I ask for 'xrot' it rotates around x screen axis. Not its own x. Does someone know why?
Remarks
- I noticed that onDrawFrame is constantly running. However the model is not constantly translating by 1.2f on y. Only when z != 0. (I don't know why)..
- I read we cound use trigonometry to get the right x vector. But this does not make sens to me. If the apps is able to keep in memory the position of the model to make right the yrot, why can't it do the same for xrot?