Game Development Reference
In-Depth Information
To implement the flight model, you first need to prepare a rigid-body structure to en‐
capsulate all of the data required to completely define the state of the rigid body at any
instant during the simulation. We've defined a structure called RigidBody for this pur‐
pose:
typedef struct _RigidBody {
float fMass; // total mass
Matrix3x3 mInertia; // mass moment of inertia
// in body coordinates
Matrix3x3 mInertiaInverse; // inverse of mass moment of inertia
Vector vPosition; // position in earth coordinates
Vector vVelocity; // velocity in earth coordinates
Vector vVelocityBody; // velocity in body coordinates
Vector vAngularVelocity;// angular velocity in body coordinates
Vector vEulerAngles; // Euler angles in body coordinates
float fSpeed; // speed (magnitude of the velocity)
Quaternion qOrientation; // orientation in earth coordinates
Vector vForces; // total force on body
Vector vMoments; // total moment (torque) on body
} RigidBody, *pRigidBody;
You'll notice that it is very similar to the RigidBody2D structure that we used in the 2D
hovercraft simulation. One significant difference, however, is that in the 2D case, ori‐
entation was a single float value, and now in 3D it's a quaternion of type Quaternion .
We discussed the use of quaternions for tracking rigid-body orientation in the previous
chapter, and Appendix C contains a complete definition of the Quaternion class.
The next step in defining the flight model is to prepare an initialization function to
initialize the airplane at the start of the simulation. For this purpose, we've prepared a
function called InitializeAirplane :
RigidBody Airplane; // global variable representing the airplane
.
.
.
void InitializeAirplane(void)
{
float iRoll, iPitch, iYaw;
// Set initial position
Airplane.vPosition.x = −5000.0f;
Airplane.vPosition.y = 0.0f;
Airplane.vPosition.z = 2000.0f;
// Set initial velocity
Airplane.vVelocity.x = 60.0f;
Airplane.vVelocity.y = 0.0f;
Airplane.vVelocity.z = 0.0f;
Search Nedrilad ::




Custom Search