Skip to main content
gamedev.net
🔒 Locked

Calculating direction angle

Started by budipro 2 replies 750+ views
Original Post
budipro
budipro
Hi all, I have two vectors: the direction vector (vector from eye point to lookat point), and vector from eye point to a point on the leftmost of the screen. How to calculate the angle between them? Is a camera field of view angle covers the width or the height of the screen? Cause a monitor''s width is longer than its height. Thanks very much.
McGuireV10
McGuireV10
I wrote this C# function to find the axis-angle matrix between two vectors. You can just use the angle part if that''s all you need, and you can probably adapt it to any language without much effort.


public Matrix AxisAngle(Vector3 v1, Vector3 v2)
{
Vector3 nv1 = Vector3.Normalize(v1);
Vector3 nv2 = Vector3.Normalize(v2);
float angle = (float)System.Math.Acos((double)Vector3.Dot(nv1,nv2));
Vector3 axis = Vector3.Normalize(Vector3.Cross(nv1,nv2));
return Matrix.RotationAxis(axis, angle);
}

budipro
budipro
thanks for your reply.

Sorry, I didn''t put my question correctly. I already know how to calculate the angle between two vectors.

All I want to ask now is how to find the vector from the eye point to a point on the leftmost of the screen.
I had tried to Unproject the point (0, viewport.width / 2, 1), into world space. Then I subtract this point with my eye point to get the vector.

But the result is not quite right, cause the angle is changing all the time, which I think it should be always the same.

Is my way to calculate the angle correct? Or is my vector calculation correct?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.