turning model in 3rd person view

Started by
7 comments, last by Tera_Dragon 19 years, 6 months ago
I have my camera set up in 3d person view around a model. However I have been having trouble getting the model to turn with the camera, so as to always appear to be facing away from the camera. I have the position of the camera and model, and the view vector of the camera.How would I do this? Tera_Dragon
____________________________________________________________Programmers Resource Central
Advertisement
turn the actor, not the camera. then place the camera so it's always behind the actor :)

Everything is better with Metal.

Assuming your character is always upright, and you use a right-handed coord system with x=left, y=up, z=fwd:

1. The characters "up vector" is just the world up direction, (0, 1, 0)

2. Calculate the cross product of the up direction with the camera view direction and normalise the result - this gives the characters "left vector".

3. the character's look vector is the cross product of its "left" and "up" vectors.

Then the characters 3x3 orientation matrix is given by the three vectors just calculated.
How would I be able to rotate the model depening upon it's view vector?
Could I use glRotate or would I have to do some thing a bit more complex?
____________________________________________________________Programmers Resource Central
If you have the objects transformation matrix use glMultMatrix

If your model only rotates around the "up" axis, then calculate the direction (using something like atan2(camera_look.x(), camera_look.z()) and use glRotate around the world "up" axis
I have no idea how to do that, even after looking at msdn...
____________________________________________________________Programmers Resource Central
I've had another look at atan2, and hav come up with this line of code to rotate the model:
float rot = atan2(g_Camera.View.x, g_Camera.View.z);
glRotatef( rot, 0.0f, 1.0f, 0.0f);


However it looks as though this does nothing. What am I doing wrong?
____________________________________________________________Programmers Resource Central
glRotatef() takes degrees, the C++ trig functions use radians. Multiply by 180 / pi.
I now have this:
Vector3 temp = g_Camera.View;
float rot = atan2(temp.x, temp.z) * 180 / 3.14;
glRotatef( rot, 0.0f, 0.0f, 1.0f);//have to spin around z (for some reason..)


However the model only faces the same way as the origin when I it is running counter clockwise around the origin. What am I doing wrong?
____________________________________________________________Programmers Resource Central

This topic is closed to new replies.

Advertisement