Game Development Reference
In-Depth Information
This class makes it easy to convert the transform matrices returned from Bullet to the
one used in the game engine, Mat4x4 . The conversion functions themselves aren ' t all
that exciting, so you can look them up in the GameCode4 source code. Now you can
take a look at how VSyncVisibleScene() works:
void BulletPhysics::VSyncVisibleScene()
{
// check all the existing actor
s bodies for changes.
// If there is a change, send the appropriate event for the game system.
for ( ActorIDToBulletRigidBodyMap::const_iterator it =
m_actorBodies.begin();
it != m_actorBodies.end();
++it )
'
{
ActorId const id = it->first;
// Get the ActorMotionState. This object is updated by Bullet.
// It
s safe to cast the btMotionState to ActorMotionState,
// because all the bodies in m_actorBodies were created through
// AddShape()
ActorMotionState const * const actorMotionState =
static_cast<ActorMotionState*>
(it->second->getMotionState());
GCC_ASSERT( actorMotionState );
'
StrongActorPtr pGameActor =
MakeStrongPtr(g_pApp->m_pGame->VGetActor(id));
if (pGameActor && actorMotionState)
{
shared_ptr<TransformComponent> pTransformComponent =
MakeStrongPtr(pGameActor->GetComponent<TransformComponent>
(TransformComponent::g_Name));
if (pTransformComponent)
{
if (pTransformComponent->GetTransform() !=
actorMotionState->m_worldToPositionTransform)
{
// Bullet has moved the actor
s physics object.
// Sync the transform and inform the game an actor has moved
pTransformComponent->SetTransform(
actorMotionState->m_worldToPositionTransform);
IEventManager::Get()->VQueueEvent(
GCC_NEW EvtData_Move_Actor(id,
actorMotionState->m_worldToPositionTransform) );
'
Search WWH ::




Custom Search