Game Development Reference
In-Depth Information
}
}
}
}
}
In Bullet, each physics actor has a btMotionState that manages how the physics sys-
tem communicates with the game engine. As Bullet processes the physics world, it
updates the position and orientation stored in each btMotionState for each actor.
The class ActorMotionState converts the Bullet
'
s transform matrices to Mat4x4 .
So once you get to VSyncVisibleScene , you loop through all the motion states.
Each actor with a motion state should also have a TransformComponent , which
stores just one data member, a Mat4x4 , representing an actor
s position and orientation.
For each motion state that has different data from the TransformComponent ,the
physics system overwrites the actor
'
'
s transform and sends an event to any game system
that cares about the object moving.
You might wonder if this breaks the game view and game logic architecture. It does
not, and here ' s why. When you hand an object over to the physics system, it becomes
the de facto authority on the movements of that actor. Other subsystems like the ren-
derer simply need to know that the actor has moved.
Creating a Simple Physics Object
Bullet represents all nondynamic physical bodies with the btRigidBody class. Let
'
stake
alookathowyou
'
d create a sphere object, given a radius and a related game actor:
void BulletPhysics::VAddSphere(float const radius, WeakActorPtr pGameActor,
const std::string& densityStr, const std::string& physicsMaterial)
{
StrongActorPtr pStrongActor = MakeStrongPtr(pGameActor);
if (!pStrongActor)
return;
// create the collision body, which specifies the shape of the object
btSphereShape * const collisionShape = new btSphereShape( radius );
// calculate absolute mass from specificGravity
float specificGravity = LookupSpecificGravity(densityStr);
const float volume = (4.f / 3.f) * GCC_PI * radius * radius * radius;
const btScalar mass = volume * specificGravity;
AddShape(pStrongActor, collisionShape, mass, physicsMaterial);
}
 
 
Search WWH ::




Custom Search