Jump to content
  • Advertisement
Sign in to follow this  
Tera_Dragon

turning model in 3rd person view

This topic is 5408 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!