May 15, 2006, 03:58 PM

I've set myself a task to try and replicate the flight model found in space fighting games. I had a basic flight model working over a terrain, however in space things are a bit more complicated, especially if you take into consideration the Z rotation of the player. (Which some space fighters dont seem to - I've seen it working in some games though)

I was hoping that someone else has succeeded because I'm having a few troubles. I'd love some advice, pointers to algorithms, tutorials or source code for examples.

My overall design basically tracks the players x,y,z location and their x,y,z angle/rotation. Is this how others do it?

Current algorithm/concept:

// Take the movement of the trackpad (DeltaHoriz and DeltaVert) to generate the change in X and Y Angles

deltaY = deltaHoriz*cos(Zrot * PI/180) + deltaVert*sin(Zrot * PI/180);

deltaX = deltaVert*cos(Zrot * PI/180) + deltaHoriz*sin(Zrot * PI/180);

(I know this is wrong, but its close and it works in some situations)

//Code to set the X and Y rotation, and cope with the transition over 360 degrees.

// Then theres the basic movement code to move the player based on their rotations (the boolean differentiates between forward and back which may be removed in future - who's ever heard of a spaceship flying backwards? )

if (Direction == true)

{

newX = X + sin(Yrot * PI/180)*BASE_SPEED*Ind_SpeedModifier;

newZ = Z - cos(Yrot * PI/180)*BASE_SPEED*Ind_SpeedModifier;

newY = Y - sin(Xrot * PI/180)*BASE_SPEED*Ind_SpeedModifier;

}

else

{

newX = X - sin(Yrot * PI/180)*BASE_SPEED*Ind_SpeedModifier;

newZ = Z + cos(Yrot * PI/180)*BASE_SPEED*Ind_SpeedModifier;

newY = Y + sin(Xrot * PI/180)*BASE_SPEED*Ind_SpeedModifier;

}

It's rather annoying - The trackpad code may work when the Zrot is up, but may be flipped at 90 degrees and fine when at 180 etc. So Im sure theres something wrong with my trackpad code's trig.

I was hoping that someone else has succeeded because I'm having a few troubles. I'd love some advice, pointers to algorithms, tutorials or source code for examples.

My overall design basically tracks the players x,y,z location and their x,y,z angle/rotation. Is this how others do it?

Current algorithm/concept:

// Take the movement of the trackpad (DeltaHoriz and DeltaVert) to generate the change in X and Y Angles

deltaY = deltaHoriz*cos(Zrot * PI/180) + deltaVert*sin(Zrot * PI/180);

deltaX = deltaVert*cos(Zrot * PI/180) + deltaHoriz*sin(Zrot * PI/180);

(I know this is wrong, but its close and it works in some situations)

//Code to set the X and Y rotation, and cope with the transition over 360 degrees.

// Then theres the basic movement code to move the player based on their rotations (the boolean differentiates between forward and back which may be removed in future - who's ever heard of a spaceship flying backwards? )

if (Direction == true)

{

newX = X + sin(Yrot * PI/180)*BASE_SPEED*Ind_SpeedModifier;

newZ = Z - cos(Yrot * PI/180)*BASE_SPEED*Ind_SpeedModifier;

newY = Y - sin(Xrot * PI/180)*BASE_SPEED*Ind_SpeedModifier;

}

else

{

newX = X - sin(Yrot * PI/180)*BASE_SPEED*Ind_SpeedModifier;

newZ = Z + cos(Yrot * PI/180)*BASE_SPEED*Ind_SpeedModifier;

newY = Y + sin(Xrot * PI/180)*BASE_SPEED*Ind_SpeedModifier;

}

It's rather annoying - The trackpad code may work when the Zrot is up, but may be flipped at 90 degrees and fine when at 180 etc. So Im sure theres something wrong with my trackpad code's trig.