PDA

View Full Version : Rotating character

Fred F
01-19-2008, 10:27 PM
I am writting a program that moves robots around the screen and I use glulookat to move the camera to make them rotate but once I move them away from the orgin they then rotate around that. I have tried doing the opposite of the translation before the glulookat but then the robots don't move at all. How can I make them rotate around just the spot they are standing?

-NiCo-
01-20-2008, 05:51 AM
You probably ordered your transformation calls incorrectly. The last matrix operation call is performed first, so

glTranslate(..)
glRotate(..)

first rotates about the origin and then translates the object, while

glRotate(..)
glTranslate(..)

first translates the object away from the origin and then rotates about the origin.

N.

Fred F
01-20-2008, 10:15 PM
Thanks and I have tried changing the order but then after I rotate the character and try to have then walk in the direction they are facing they still walk straight at the camera and not in the direction they are facing. How can I get them to rotate around the spot they are standing and still walk in the direction they are facing?

Korval
01-21-2008, 11:31 AM
We're going to need to see some code to find out what you're doing wrong at this point. Don't forget the [ code ][ /code ] tags.

Fred F
01-21-2008, 05:35 PM
Here is the code I wrote

[ 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();
}

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 ]

Fred F
01-24-2008, 09:16 AM
Does anyone have any ideas how I can get the robots to rotate around whatever point they are at and not the orgin and still move in the direction they are facing?