PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

HELP: 6DOF / FLIGHT SIM CAMERA FOR POCKETGL

pocketguest · 08 May 2006, 13:22 UTC
If you use PocketGL, Quark3D or a good 3d programmer please help! :cry:

PocketGL has a demo10 (walkaround quake map, 1st person camera) which shows how to do Y-axis rotation and XYZ movement by forward vector (FPS camera). The code for this is below.

I need to add another (2nd) Axis rotation to that like Z-axis roatation (Flight Sim camera).

The problem is to rotate the other axis so the rotations are always local so when you turn somewhere your rotations are always right/left, up/down to your screen.

For example when you rotate around Y your Z should rotate and now you rotate around Z and your Y will rotate then again Y etc..

I can't seem to figure out how to put it all together with PocketGL matrixes.

(There is no gluLookAt or anything like it too)

Please help! :cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry:


Part of Demo10 (Y rotation and XYZ movement):

Code:
CMatrix44 M;
Vector4s DeltaMove;

// rotations
PlayerRot.y += (RotateSpeed*dTimeFilter) >> 9;

M.DefRotateY(PlayerRot.y); // define Y rotation matrix

// forward move
DeltaMove.Init(M.Dir()); // get forward direction vector
int Fwd = (ForwardSpeed*dTimeFilter) >> 9;
PlayerPos.x += (DeltaMove.x * Fwd) >> COS_SIN_SHIFT; // unit vector is scaled
PlayerPos.y += (DeltaMove.y * Fwd) >> COS_SIN_SHIFT; //*** unit vector is scaled
PlayerPos.z += (DeltaMove.z * Fwd) >> COS_SIN_SHIFT;

// straf move
DeltaMove.Init(M.Left()); // get left direction vector
PlayerPos.x += (DeltaMove.x * StrafSpeed) >> COS_SIN_SHIFT;
PlayerPos.y += (DeltaMove.y * StrafSpeed) >> COS_SIN_SHIFT; //*** unit vector is scaled
PlayerPos.z += (DeltaMove.z * StrafSpeed) >> COS_SIN_SHIFT;

MatrixStack.PushMatrix();

// define scene move as inverse of camera move (camera is always fixed at origin and look on -z)
MatrixStack.CurrentMatrix->Pos()->Init(0, 0, 0);
MatrixStack.CurrentMatrix->DefRotateY(-PlayerRot.y);

MatrixStack.CurrentMatrix->Translate(-PlayerPos.x, -PlayerPos.y, -PlayerPos.z);

// draw fixed objects with BSP
// the renderer states (HRS, ZCorrection), are affected by this function
// so you have to reset state to requested value if you wand to draw other objects (mobile objects)
Bsp.DrawFixedObjectsSubDiv();

MatrixStack.PopMatrix();
This thread on gamedev.net might be of use to you:

http://www.gamedev.net/community/forums ... _id=391805
You're rotating then translating. Try translating first.

Dan East