vec_to_angle (ANGLE* ang, VECTOR* dir);
Computes the pan and tilt angles of a direction vector, and places them into the pan and tilt parameters of an Euler angle. Very useful for trading an angle for a direction, thus computing the angles to a target.
Parameters:
ang |
Euler angle to be calculated. |
dir |
direction vector. |
Returns:
Length of the vector
Modifies:
ang
Speed:
Fast
Algorithm:
ANGLE.pan = atan(VECTOR.y/VECTOR.x);
ANGLE.tilt = asin(VECTOR.z/length(VECTOR));
Example:
function turn_towards_target()
{
// get the direction from the entity MY to the entity YOU
vec_set(temp,your.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp); // now MY looks at YOU
}
See also:
pan, tilt, roll, ang_add, vec_rotate, vec_for_angle
► latest version online