PDA

View Full Version : OpenGL Maths - Angle between 2 Vectors



06-12-2001, 02:37 AM
Hi,
I want the camera to have a 360 degree view, if i take a constant facing north and then a second value of where the player is looking, calculating the angle between the two for moving in the correct direction.
I am using gluLookAt, that is why i need to do it this way, i would be most grateful for any help. Thanks

Paul

Gavin
06-12-2001, 11:38 AM
Are you asking for the formula for the angle between two vectors?

gav

Handkor
06-12-2001, 04:56 PM
Since v1 dot v2 = |v1|*|v2|cos(theta)

you can solve for theta with

theta = acos((v1 dot v2)/(|v1|*|v2|))

P.S. |v| is the magnitude of a vector and dot refers to the dot product.

06-12-2001, 09:34 PM
Hi,
Thanks, it was the formula for calculating the angle between two vectors that i was looking for. Thnaks again.

Paul