# LookAt Rotation function

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

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

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633759
• Total Posts
3013720
×