First Person Camera Control - Tangent & Quake BSP's

Two questions:

  1. I’d like to mouse freelook and be able to go forwards or backwards along my looking direction (w & s keys). I can freelook and move within a plane w /no problems but this is not what I want. I’ve included a rough outline of my code. For <> I’ve tried a composition of angles via matrix & a composition of quaternions via multiplies. No luck. When my rotX and rotY are much less than 90 degrees, things appear to work. When I get around 90 flakey things start to happen. This sounds like a gimble locking problem. Rather than dig, I was hoping somebody would be able to point me to some working code. Not sure if it’s an incorrect of viewing transform and tangent calculation or what…

  2. I just parsed a quake 3 bsp file and noticed that my orientation is as if I have a 90deg roll. I wasn’t expecting this. Anybody know why is this? I’ve heard that D3D uses a different coordinate system than opengl and was wondering if this is the reason - q3 maps were made for d3d coordinates? If so, what transform is necessary?

NOTE: Using JOGL.

Any help appreciated,

Monty

////////
Vector3f position = new Vector3f();

keyboard() {
Vector3f tangent = <<what function??>>(rotX, rotY);
switch (keycode)
case ‘w’: // forward along camera tangent
position += tangent
case ‘s’: // reverse along camera tangent
position -= tangent;
}

void mouseEvent() {
if (left/right)
rotY +/-= value;
if (up/down)
rotX +/-= value;
}

display(GLAutoDrawable drawable) {
gl.rotate(rotX,1,0,0)
gl.glRotate(rotY,0,1,0);
gl.translate(posX,posY,posZ);

drawQuake faces.
}

rotX should be clamped to something like <-89, 89> degrees. You don’t want to walk upside down. <<what function??>> should use rotY to generate a direction vector in the xz plane:


Vector3f tangent = new Vector3f(Math.cos(rotY), 0, Math.sin(rotY));

Also the rotate and translate calls in display may mess things up. If you rotate first the translation will be in the rotated coordinate system. Although I’m not completely sure about this. Always forget how it works.

Q3 file format may use a coordinate system where z is up. Then you have to swap y and z and mess with their signs when parsing the files. Have a look at one of the many Q3 parsers out there and see how they did it. Source to one of them can be found here:
http://www.jmonkeyengine.com/jmeforum/index.php?topic=2597.0

Thanks Tom,

The Z Y conversion did the trick. The following tangent calcs now work for me.

forward:
posX += sin(rotY)
posY -= sin(rotX)
posZ -= cos(rotY)

Monty