I’m doing some OpenGl coding and am trying to get a normalized forward, right, and up vector based on the current viewAngles (yaw, pitch, roll ). I’ve seen a function to do this in the Quake source code, but Quake has a convention where Y and Z are swapped in relation to how Y and Z are typically used in OpenGL…and so I’m not sure if I would have to do some conversion on the Quake function so it will work properly. If needed I can provide the Quake function if that would help someone convert it. Thanks so much in advance!

As you say, Quake uses a system where z-axis is running from upwards/downwards. And if know how Quake is doind it, just swap all y-coords and z-coords and it should work. Maybe you have to flip one or two axes though. If it doesn’t work, just post the code here.

Ok, here’s the code from Quake I, but it doesn’t quite seem to work because the Y and Z axis are swapped in Quake (my math skills aren’t great, so perhaps the solution is easy??):

void AngleVectors( vec3_t ang, vec3_t fwd, vec3_t right, vec3_t up) {

float angle;

float sr, sp, sy, cr, cp, cy;

```
angle = ang[YAW] * (M_PI*2/360);
sy = sin(angle);
cy = cos(angle);
angle = ang[PITCH] * (M_PI*2/360);
sp = sin(angle);
cp = cos(angle);
angle = ang[ROLL] * (M_PI*2/360);
sr = sin(angle);
cr = cos(angle);
if( fwd ) {
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;
}
```

}

[This message has been edited by El Jefe (edited 06-08-2000).]

Bob, gave your suggestions a whirl last night but it didn’t seem to work. I was able to work out the forward vector, but the right and up vectors are still messed up.

Argh! Someone help, this problem has been holding up my development for a week!

Heh heh, ok, I’ve calmed down now. Seriously, if anyone can help, I’d greatly appreciate it.

Thanks.

El Jefe,

Here’s some sample code using my “glh” library - which uses a BSD license and consists only of header files, so use or copy at your discretion.

I’m going to assume that:

yaw is rotation about the y axis

pitch is rotation about the x axis

roll is rotation about the negative z axis

*AND* the rotations are performed

roll then pitch then yaw

It should be easy to modify this code fragment if those assumptions are incorrect.

rotationf roll(vec3f(0,0,-1), roll_radians);

rotationf pitch(vec3f(1,0,0), pitch_radians);

rotationf yaw(vec3f(0,1,0), yaw_radians);rotationf composite = yaw;

composite *= pitch;

composite *= roll;matrix4f m;

composite.get_value(m);vec3f forward, right, up;

m.mult_matrix_vec(vec3f(0,0,-1), forward);

m.mult_matrix_vec(vec3f(1,0,0), right);

m.mult_matrix_vec(vec3f(0,1,0), up);

Hope this helps…

[This message has been edited by cass (edited 06-09-2000).]

Many thanks to anyone who offered tips on how to solve this problem.

I found the Euler Angles rotation matrix at:

http://cadd.cern.ch/cad_geant_int/ddt_long/node11.html

but I had to do some reworking for it to work?? Anyway, if anyone would like the solution I used, I guess let me know?

Thanks again!

El Jefe