Game Development Reference
In-Depth Information
τ
=
p f ×
f
(i.e., equation 10.1, which we saw earlier). For each torque applied we accumulate just
the torque (torques have no corresponding force component).
Someforces,suchasgravity,willalwaysapplytothecenterofmassofanobject.
In this case there is no point trying to work out their torque component because they
can never induce rotation. We allow this in our engine by providing a third route:
adding a force with no position of application. In this case we merely add the force to
the force accumulator and bypass torque accumulation. In code this looks like this:
Excerpt from include/cyclone/body.h
class RigidBody
{
// ... Other RigidBody code as before ...
/**
* Adds the given force to the center of mass of the rigid body.
* The force is expressed in world coordinates.
*
* @param force The force to apply.
*/
void addForce(const Vector3 &force);
};
Excerpt from src/body.cpp
void RigidBody::addForce(const Vector3 &force)
{
forceAccum += force;
}
In addition, when we perform our per-frame setup of the body, we zero the torque:
Excerpt from include/cyclone/body.h
class RigidBody
{
// ... Other RigidBody code as before ...
};
Excerpt from src/body.cpp
void RigidBody::integrate(real duration)
{
// Clear accumulators.
clearAccumulators();
}
Search Nedrilad ::




Custom Search