Game Development Reference
In-Depth Information
void BulletPhysics::AddShape(StrongActorPtr pGameActor,
btCollisionShape* shape, float mass, const std::string& physicsMaterial)
{
GCC_ASSERT(pGameActor);
ActorId actorID = pGameActor->GetId();
GCC_ASSERT(m_actorIdToRigidBody.find( actorID ) ==
m_actorIdToRigidBody.end() &&
Actor with more than one physics body?
);
// lookup the material
MaterialData material(LookupMaterialData(physicsMaterial));
// localInertia defines how the object
s mass is distributed
btVector3 localInertia( 0.f, 0.f, 0.f );
if ( mass > 0.f )
shape->calculateLocalInertia( mass, localInertia );
'
Mat4x4 transform = Mat4x4::g_Identity;
shared_ptr<TransformComponent> pTransformComponent =
MakeStrongPtr(pGameActor->GetComponent<TransformComponent>
(TransformComponent::g_Name));
GCC_ASSERT(pTransformComponent);
if (!pTransformComponent)
// Physics can't work on an actor that doesn't have a TransformComponent!
return;
transform = pTransformComponent->GetTransform();
// set the initial transform of the body from the actor
ActorMotionState * const myMotionState =
GCC_NEW ActorMotionState(transform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(
mass, myMotionState, shape, localInertia );
// set up the material properties
rbInfo.m_restitution = material.m_restitution;
rbInfo.m_friction
= material.m_friction;
btRigidBody * const body = new btRigidBody(rbInfo);
m_dynamicsWorld->addRigidBody( body );
// add it to the collection to be checked for changes in VSyncVisibleScene
m_actorIdToRigidBody[actorID] = body;
m_rigidBodyToActorId[body] = actorID;
}
Search WWH ::




Custom Search