PDA

View Full Version : Rotation problem



Gelidus
05-14-2014, 03:31 AM
Hello. I am making a 3D tank (just for learning 3d programming) (using this tutorials: spacesimulator(dot)net/wiki/index.php?title=3d_Engine_Programming_Tutorials ) I made two 3ds models, the body of the tank, and the turret. Now I can move with my tank, I can play with the lights etc. and I can rotate the turret. But if I rotate the turret, and then I wanted to move the tank in any direction, the turret move into its own direction, and the body too.

For example: -> this is the direction of the tank, and <- this is the direction of the turret after the rotation. So in this example, the tank will go to right, and the turret will go to left (while i am only pushing the right button). I want the turret to go with my tank's body, to the right.

Of course without rotation, its working. I know I have to use glPushMatrix() and glPopMatrix() but i dont know where should I paste these commands.

ps.: my source is almost the same as in the tutorial: "Print fonts using display lists"(link)


void keyboard_s (int p_key, int p_x, int py)
{
switch (p_key)
{
case GLUT_KEY_UP:
ObjTranslate(&object[0],0,0.2,0);
ObjTranslate(&object[1],0,0.2,0);
break;
case GLUT_KEY_DOWN:
ObjTranslate(&object[0],0,-0.2,0);
ObjTranslate(&object[1],0,-0.2,0);
break;
case GLUT_KEY_LEFT:
ObjRotate(&object[0],0,0,3);
ObjRotate(&object[1],0,0,3);
break;
case GLUT_KEY_RIGHT:
ObjRotate(&object[0],0,0,-3);
ObjRotate(&object[1],0,0,-3);
break;
case GLUT_KEY_PAGE_UP:
ObjRotate(&object[1],0,0,5);
break;
case GLUT_KEY_PAGE_DOWN:
ObjRotate(&object[1],0,0,-5);
break;
}
}

object 0 = body, ovject 1 = turret