Game Development Reference
In-Depth Information
'
probably describing most of the readers of this topic, let
s discuss this important
integration task.
Note that the code presented in this section is only a tiny part of integrating a phys-
ics SDK into a complete game. The functionality here won
'
t get you much past
bouncing balls on a ground plane, so don
t expect more than that. The goal is to
show you how a third-party physics system fits into the game architecture presented
in this topic. It
'
s up to you to extend this class for additional functionality or use a
different SDK than the one I chose.
It helps to discuss an interface class for a simple physics system. The interface shown
here creates a few objects and manages their movements. If you want to abstract an
entire physics system, you
'
'
d extend this class quite a lot. Actually, you
'
dextendthisinter-
'
face and probably create a few new ones. We
ll keep it simple for now, just to get you
started. After the interface discussion, we ' ll implement it using the Bullet Physics SDK
available from www.bulletphysics.com, which is available for free under the Zlib license.
class IGamePhysics
{
public:
// Initialization and Maintenance of the Physics World
virtual bool VInitialize()=0;
virtual void VOnUpdate( float deltaSeconds ) = 0;
virtual void VSyncVisibleScene() = 0;
// Initialization of Physics Objects
virtual void VAddSphere(float radius,
WeakActorPtr actor, const Mat4x4& initialTransform,
const std::string& densityStr, const std::string& physicsMaterial)=0;
virtual void VAddBox(const Vec3& dimensions,
WeakActorPtr gameActor, const Mat4x4& initialTransform,
const std::string& densityStr, const std::string& physicsMaterial) = 0;
virtual void VRemoveActor(ActorId id)=0;
// Debugging
virtual void VRenderDiagnostics() = 0;
// Physics world modifiers
virtual void VCreateTrigger(WeakActorPtr gameActor, const Vec3 &pos,
const float dim)=0;
virtual void VApplyForce(const Vec3 &dir, float newtons, ActorId aid)=0;
virtual void VApplyTorque(const Vec3 &dir, float newtons, ActorId aid)=0;
virtual bool VKinematicMove(const Mat4x4 &mat, ActorId aid)=0;
}
 
Search WWH ::




Custom Search