Reputation: 165
glTranslatef(-camerax, -cameray,
-cameraz)
glRotatef(camangle, camrotx,
camroty, camrotz)
Then i render the objects starting here between pushmatrix & popmatrix commands.
Everything working, translating and rotating well. Until i try to move camera in the rotated modelview matrix. I want to translate the camera moves toward (int its own object space).
I added this line into onKeyDown
method of UP key: glTranslatef(0f,
0f, 1f);
But with this command, the cam moves toward -z axis of modelview matrix, not toward -z axis of its own space.
I could not figure out how to make the object translation in its own toward direction. Can somebody explain me how it shoud be done.
Upvotes: 0
Views: 642
Reputation: 165
posz += (zdif * (float)(Math.cos(Math.toRadians(yrot))));
glTranslatef(0f, 0f, posz);
did make the necessary translation.
Upvotes: 0
Reputation: 4482
It's all about multiplication order (as matrix multiplication is not commutative). It makes a big difference do step 4 before or after step 2! One is in screen space, the other is world space.
Upvotes: 1