PDA

View Full Version : Third person transforms



MrMister
05-15-2001, 10:30 PM
I wonder if someone could help me with my transforms:

I have a setup where the eye is just over and behind the player model (a tank, similar style to the arcade game Cybersled)

I can strafe and move forward/backward with the tank, and the objects around me translate correctly...but if i move the player model away from the objects and rotate...they seem to stay in place and rotate around each other (around origin 0,0,0), not around the player position...

My code looks like the following:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// setup initial camera view, slightly above and behind the player model
gluLookAt(0, 80, -80,
0, 20, 60,
0.0, 1.0, 0.0);

glTranslatef(-player->pos[0], 0, -player->pos[2]);
glRotatef(-yrot,0.0f,1.0f,0.0f);

// draw scene objects
obj = glist;
while (obj != NULL) {
glPushMatrix();

glTranslatef(obj->pos[0], obj->pos[1], obj->pos[2]);
glCallList(obj->dlist);

glPopMatrix();

obj = obj->next;
}

// draw player model
glRotatef(yrot, 0.0f, 1.0f, 0.0f);
glTranslatef(player->pos[0], 0, player->pos[2]);
glCallList(player->dlist);

again, the code works in translating the objects, but rotations are not relative to the player position. any ideas?

Tomasz Zielinski
05-15-2001, 10:43 PM
I think, that you must reverse order of the transformations.
For example:

glRotate
glTranslate

This codeTRANSLATES first, while this code

glTranslate
glRotate

ROTATES first!

MrMister
05-15-2001, 11:12 PM
You were right. Thanks a lot. That totally fixed it. now to code the rest of the game =)