Jump to content
  • Advertisement
Sign in to follow this  
acid2

LookAt Rotation function

This topic is 4705 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

Hi, I'm not quite sure what to google for, so if you can tell me what that would be nice (always nicer to do things myself). I have been requested by a designer to create a camera system for our game so that it runs a long a track. I have created a spline system so the camera can move along a track, but it would be nice if I could have a target to point the camera at. Basically, how can I, give a point L and point T (Location and target) calculate a quaternion (preferably) or matrix representing the rotation?

Share this post


Link to post
Share on other sites
Advertisement
If camera is at P and should look at T (two points), and has current orientation v (a direction vector) then compute a pivot axis (by cross product) and angle (by dot product) from them.
pivot := norm(v,P-T)
angle := acos(dot(norm(v),norm(P-T))
I assume you have already routines for computing a rotation matrix or unit quaternion from these parameters. If not, this is for q quat

quat.w = cos(angle*0.5f);
quat.ix = sin(angle*0.5f)*pivot.x;
quat.iy = sin(angle*0.5f)*pivot.y;
quat.iz = sin(angle*0.5f)*pivot.z;


(not optimized).

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!