PDA

View Full Version : 3rd person view...



Geniuz
05-07-2001, 11:55 AM
Hi there,
k.. I want a 3rd person view...
I have box, which has to move like a car. And I got the camera always looking to one side of the box (the car's back if you wish)... And I want the world to rotate around the box, instead of rotating around the camera...

this is my code

Player.px/py/pz -> coords of box
Player.rot -> y-rotation of box
Camera.px/py/pz -> coords of cam

glLoadIdentity();
glTranslatef(Player.px-Camera.px,Player.py-Camera.py,Player.pz-Camera.pz);
glCallList(box);

glLoadIdentity();
glRotatef(Player.rot,0,1,0);
glTranslatef(-Camera.px,-Camera.py,-Camera.pz);

... Fine... but it's 1st person view...

I guess it's just a little addition.. but my mind is completely blocked...
agagagagaga


thx... Geniuz

05-08-2001, 12:03 AM
Add this:
glPushMatrix();
/* your original code */
glPopMatrix();

Geniuz
05-08-2001, 04:01 AM
glPushMatrix();
glLoadIdentity();
glTranslatef(Player[0].px-Camera.px,Player[0].py-Camera.py,Player[0].pz-Camera.pz);
glCallList(box);
glLoadIdentity();
glRotatef(Player[0].rot,0,1,0);
glTranslatef(-Camera.px,-Camera.py,-Camera.pz);
glPopMatrix();

Wow... now it does not move at all... and it's not, where I want it to be...

Gonna work on it...

Geniuz
05-08-2001, 04:16 AM
Got it !!

glLoadIdentity();
glTranslatef(Player[0].px-Camera.px,Player[0].py-Camera.py,Player[0].pz-Camera.pz);
glCallList(box);

glLoadIdentity();
glTranslatef(-Camera.px+Player[0].px,-Camera.py+Player[0].py,-Camera.pz+Player[0].pz);
glRotatef(Player[0].rot,0,1,0);
glTranslatef(-Camera.px,-Camera.py,-Camera.pz);

Simple.. lol.. new day, new way... fine...

Geniuz
05-08-2001, 04:34 AM
Even better:
glLoadIdentity();
glTranslatef(0,-Camera.height,-Camera.distance);
glCallList(box);
glRotatef(Player[0].rot,0,1,0);
glTranslatef(-Camera.px,-Camera.py,-Camera.pz);