Game Development Reference
In-Depth Information
The RigidBody2D constructor is straightforward, as shown next, and simply initializes
all the properties to some arbitrarily tuned values we decided worked well. In Chap‐
ter 17 , you'll see how we model a more realistic hovercraft.
RigidBody2D::RigidBody2D(void)
{
fMass = 100;
fInertia = 500;
fInertiaInverse = 1/fInertia;
vPosition.x = 0;
vPosition.y = 0;
fWidth = 10;
fLength = 20;
fHeight = 5;
fOrientation = 0;
CD.x = −0.25*fLength;
CD.y = 0.0f;
CD.z = 0.0f;
CT.x = −0.5*fLength;
CT.y = 0.0f;
CT.z = 0.0f;
CPT.x = 0.5*fLength;
CPT.y = −0.5*fWidth;
CPT.z = 0.0f;
CST.x = 0.5*fLength;
CST.y = 0.5*fWidth;
CST.z = 0.0f;
ProjectedArea = (fLength + fWidth)/2 * fHeight; // an approximation
ThrustForce = _THRUSTFORCE;
}
As in the particle simulator of Chapter 8 , you'll notice here that the Vector class is
actually a triple (that is, it has three components—x, y, and z). Since this is a 2D example,
the z components will always be 0, except in the case of the angular velocity vector where
only the z component will be used (since rotation occurs only about the z-axis). The
class that we use in this example is discussed in Appendix A . The reason we didn't write
a separate 2D vector class, one with only x and y components, is because we'll extend
this code to 3D later and wanted to get you accustomed to using the 3D vector class.
Besides, it's pretty easy to create a 2D vector class from the 3D class by simply stripping
out the z component.
As with the particle example of Chapter 8 , we need a CalcLoads method for the rigid
body. As before, this method will compute all the loads acting on the rigid body, but
now these loads include both forces and moments that will cause rotation. CalcLoads
looks like this:
Search Nedrilad ::




Custom Search