Game Development Reference
In-Depth Information
// create the collision body, which specifies the shape of the object
btBoxShape * const boxShape
= new btBoxShape( Vec3_to_btVector3( Vec3(dim,dim,dim) ) );
// triggers are immovable. 0 mass signals this to Bullet.
btScalar const mass = 0;
// set the initial position of the body from the actor
Mat4x4 triggerTrans = Mat4x4::g_Identity;
triggerTrans.SetPosition( pos );
ActorMotionState * const myMotionState
= GCC_NEW ActorMotionState( triggerTrans );
btRigidBody::btRigidBodyConstructionInfo
rbInfo( mass, myMotionState, boxShape, btVector3(0,0,0) );
btRigidBody * const body = new btRigidBody(rbInfo);
m_dynamicsWorld->addRigidBody( body );
// a trigger is just a box that doesn't collide with anything. That's
// what “CF_NO_CONTACT_RESPONSE” indicates.
body->setCollisionFlags(
body->getCollisionFlags() j btRigidBody::CF_NO_CONTACT_RESPONSE );
m_actorIdToRigidBody[pStrongActor->GetId()] = body;
m_rigidBodyToActorId[body] = pStrongActor->GetId();
}
Of course, as long as the mesh components are convex, you can create a complicated
trigger zone on virtually any shape at all. Zones like that can be quite useful if you
want something to fire the trigger when it is in exactly the right place and yet not
intruding on other spaces, perhaps behind walls.
Applying Force and Torque
So far, the only force that would be represented in the physics simulation is gravity,
which Bullet sets for you automatically to Earth-gravity, 9.8m/s 2 , in the direction of
negative Y, which is exactly how our game world is set up. Getting anything to move
requires the application of a linear force, or a torque. Here are the two methods for
doing that:
void BulletPhysics::VApplyForce(const Vec3 &dir, float newtons, ActorId aid)
{
btRigidBody * pRigidBody = FindBulletRigidBody(actorId);
GCC_ASSERT(pRigidBody);
 
 
Search WWH ::




Custom Search