Sign in to follow this  
acid2

LookAt Rotation function

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this