# what does AngleVectors method in quake 3 source code does

I know some of some linear algebra(basic vector math ie: dot,cross product).
However I can't decipher what below method does, I know what is yaw,pitch and roll.
But I can't connect these with vector.
Worse, I'm not sure this fall under what math 'category', so I don't really know how to google.
Hence the question here.
Anyone?

``````void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up) {
float       angle;
static float        sr, sp, sy, cr, cp, cy;
// static to help MS compiler fp bugs

angle = angles[YAW] * (M_PI*2 / 360);
sy = sin(angle);
cy = cos(angle);
angle = angles[PITCH] * (M_PI*2 / 360);
sp = sin(angle);
cp = cos(angle);
angle = angles[ROLL] * (M_PI*2 / 360);
sr = sin(angle);
cr = cos(angle);

if (forward)
{
forward[0] = cp*cy;
forward[1] = cp*sy;
forward[2] = -sp;
}
if (right)
{
right[0] = (-1*sr*sp*cy+-1*cr*-sy);
right[1] = (-1*sr*sp*sy+-1*cr*cy);
right[2] = -1*sr*cp;
}
if (up)
{
up[0] = (cr*sp*cy+-sr*-sy);
up[1] = (cr*sp*sy+-sr*cy);
up[2] = cr*cp;
}
}
``````

ddddd

-

It just computes a (slightly wacky, because of Quake's "entity pitches are negative" thing) 3x3 rotation matrix, with each column (or row, depending on your preference) being one of the forward/right/up vectors. This can then be used to position various objects/effects/etc relative to the view; Quake uses it for pushing muzzleflashes slightly forwards and for sprite billboarding, for example.

Compare with the matrix described at http://blogs.msdn.com/b/mikepelton/archive/2004/10/29/249501.aspx

-
ah yes, the rotation matrix.It made sense now.I can't "read" math in code form, so I can't connect the dot. – kypronite Nov 7 '12 at 5:39

The function takes angles and calculates vectors that point in directions relative to `angles`.

For angles, and the operations `sin` `cos` and `tangent`, you'll want to look up trigonometry.

Multiplying an angle in degrees by `M_PI*2 / 360` converts degrees to radians. (M_PI = 3.14).

`forward` is a vector that points in the direction that the angles form to create the forward facing direction.

`right` is a vector pointing to the right of where the `angles` representation is facing, and `up' points directly up.

If `angles` represented the angles that you are looking at currently (i.e. your head), `forward` would point straight ahead of you, `right' would point to your right, and`up` would point up from where your head is oriented.

-
I forgotten about rotation matrix, so I think I got confused how angle relates to vector. – kypronite Nov 7 '12 at 5:41