Hello…

I’ve got a bit of a problem/question regarding directional vectors…

After messing around with Quake’s AngleVectors() function (which creates a directional vector from YAW,PITCH & ROLL)…well here it is (Quake’s) to begin with:

```
float angle;
float sr, sp, sy, cr, cp, cy;
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);
forward[0] = cp*cy;
forward[1] = cp*sy;
forward[2] = -sp;
```

As I was saying, after modifying the code so that it can work with OpenGL’s world coordination (i.e. Y-axis being up, instead of Quake’s Z-up axis)…I ended up with:

```
float sr,sp,sy,cr,cp,cy;
float radians;
radians = (angle[YAW]+180)*(PI/180);
sy = sin(radians);
cy = cos(radians);
radians = -angle[PITCH]*(PI/180);
sp = sin(radians);
cp = cos(radians);
radians = angle[ROLL]*(PI/180);
sr = sin(radians);
cr = cos(radians);
vec[0] = cp*sy;
vec[2] = cp*cy;
vec[1] = -sp;
~~~~~~~~~~~~~~~~~~~
My question is....HOW DOES IT WORK?????
I know how to do ray projection, clipping, plane work....but I can't understand this relatively simple code....
I would have thought that you would have done Matrix rotation...but when i did that..it would mess up my forward direction when aiming up a bit (it would go right a bit)....and im sure that my matrix code is correct.....
Sorry to post all the code and this message, but I really need to figure this little thing out.....
If anyone can explain why you do the cos(angle)*sin(angle), etc calculations, or any explanations, I would GREATLY appreciate it,
Thanks [img]http://www.opengl.org/discussion_boards/ubb/smile.gif[/img]
```