PDA

View Full Version : Model rotation

Fred F
02-03-2008, 09:21 AM
I am working on a program that displays 4 robots drawn using cylinders and spheres and they move foward and backward and side to side using the arrow keys and the mouse rotates them. I am having trouble geting them to rotate around the point they are standing at. After I move them away from their starting position when I rotate them they rotate around the starting point but I want them to rotate around the point they are standing at. If I reverse the glrotate and gltranslate they rotate correctly but no longer move in the direction they are facing. Is there even a way to get the robots to walk the way they are facing and still rotate around the point they are standing?
Here is some of my code
[ code ]
{
glPushMatrix();
glTranslatef(sidedistance,1.3,distance);//sidedistance is distance up and down x axis and distance is distance up and down z axis
glRotatef(90.0,1.0,0.0,0.0);
glPopMatrix();
}
//Other parts drawn and omitted

void Robot::DrawRobot(float x, float y, float z)//draws the character
{
glTranslatef(x,y,z);
gluLookAt(sin(angle*0.0174532925),0.0,cos(angle*0. 0174532925),0.0,0.0,0.0,0.0,1.0,0.0);// angle is the amount of rotation
glColor3fv(color);
if ((armsraised)&&(!walking)&&(!sidestep))
DrawRobotArmsRaised();
if ((armslowered)&&(!walking)&&(!sidestep))
DrawRobotArmsLowered();
if ((walking)&(!sidestep))
DrawRobotWalking();
if ((sidestep)&&(!walking))
DrawRobotSideStep();
if ((!walking)&&(!armsraised)&&(!armslowered)&&(!sidestep))
DrawRobotStanding();
}
[ /code ]