# 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 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).

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628379
• Total Posts
2982353

• 10
• 9
• 15
• 24
• 11