Game Development Reference
In-Depth Information
and moments acting on it. This RigidBody2D class is very similar to the Particle class
from Chapter 8 , but with some additions mostly dealing with rotation. Here's how we
did it:
class RigidBody2D {
public:
float fMass; // total mass (constant)
float fInertia; // mass moment of inertia
float fInertiaInverse; // 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
float fSpeed; // speed
float fOrientation; // orientation
Vector vForces; // total force on body
Vector vMoment; // total moment on body
float ThrustForce; // Magnitude of the thrust force
Vector PThrust, SThrust; // bow thruster forces
float fWidth; // bounding dimensions
float fLength;
float fHeight;
Vector CD; // location of center of drag in body coordinates
Vector CT; // location of center of propeller thrust in body coords.
Vector CPT; // location of port bow thruster thrust in body coords.
Vector CST; // location of starboard bow thruster thrust in body
// coords.
float ProjectedArea; // projected area of the body
RigidBody2D(void);
void CalcLoads(void);
void UpdateBodyEuler(double dt);
void SetThrusters(bool p, bool s);
void ModulateThrust(bool up);
};
The code comments briefly explain each property, and so far you've seen all these prop‐
erties somewhere in this topic, so we won't explain them again here. That said, notice
that several of these properties are the same as those shown in the Particle class from
Chapter 8 . These properties include fMass , vPosition , vVelocity , fSpeed , vForces ,
and fRadius . All of the other properties are new and required to handle the rotational
motion aspects of rigid bodies.
Search Nedrilad ::




Custom Search