Game Development Reference
In-Depth Information
const std::string& densityStr,
const std::string& physicsMaterial) override;
virtual void VAddBox(const Vec3& dimensions, WeakActorPtr pGameActor,
const std::string& densityStr,
const std::string& physicsMaterial) override;
virtual void VRemoveActor(ActorId id) override;
// Debugging
virtual void VRenderDiagnostics()override;
// Physics world modifiers
virtual void VCreateTrigger(WeakActorPtr gameActor, const Vec3 &pos,
const float dim) override;
virtual void VApplyForce(const Vec3 &dir, float newtons,
ActorId aid) override;
virtual void VApplyTorque(const Vec3 &dir, float newtons,
ActorId aid) override;
virtual bool VKinematicMove(const Mat4x4 &mat, ActorId aid) override;
};
You
ll notice our new class wraps the Bullet data structures for the SDK and a set of
components, including a world, a collision dispatcher, a constraint solver, and other
components of the Bullet physics system. They are created separately, so the user
(that ' s you!) can easily customize the various behaviors of Bullet.
For our example, we
'
ll use the most common default components that Bullet provides:
btBroadphaseInterface ,
'
btCollisionDispatcher ,
btConstraintSolver ,
and btDefaultCollisionConfiguration .I
'
ll describe these components in more
detail in a second.
You
ll also notice when you look at the code that our physics system uses a physics
system-specific vector class, btvec , and a transform matrix, btTransform .Itis
quite common for a physics system to have its own data structures or classes for
common fundamental mathematics: vectors, matrices, and so on. This can be some-
what annoying, but it is a small price to pay for not having to write your own physics
system from scratch.
The next data structures hold the density and materials tables, which are read in from
XML during initialization. This is a great way to let your physics materials be data
driven. These data structures are accompanied by some helper functions, Lookup-
SpecificGravity() and LookupMaterialData() , which return data for match-
ing a name with the floating-point density or the restitution and friction, respectively.
Two std::map structures come next. The game engine refers to actors by their ID,
which needs to be mapped to the core Bullet representation of an actor,
'
the
Search WWH ::




Custom Search