Game Development Reference
In-Depth Information
triggerTrans.setOrigin(btVector3(0,1.5,0));
m_pTrigger->setWorldTransform(triggerTrans);
// flag the trigger to ignore contact responses
m_pTrigger->setCollisionFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE);
// add the trigger to our world
m_pWorld->addCollisionObject(m_pTrigger);
The previous code creates a trigger volume hovering just above the ground plane.
We don't want these trigger volumes to be rendered during runtime since these
kinds of triggers usually remain invisible to the player. So we avoided using our
CreateGameObject() function (which would have added it to the list of objects
and automatically render it), and instead we built it manually.
However, even though it is invisible to the player, we can still observe it through the
debug renderer. If we enable wireframe mode (the W key), Bullet will draw the shape
for us so that we can visualize the trigger volume in the space.
Meanwhile, BasicDemo includes an override for CollisionEvent() which
checks if the two objects involved are the box and the trigger, and if so, it spawns a
large box besides it. Note that we don't necessarily know if pBody0 or pBody1 rep-
resents either object, so we need to check both pointers:
void BasicDemo::CollisionEvent(btRigidBody*
pBody0, btRigidBody* pBody1) {
// did the box collide with the trigger?
if (pBody0 == m_pBox->GetRigidBody() &&
pBody1 == m_pTrigger ||
pBody1 == m_pBox->GetRigidBody() && pBody0
== m_pTrigger) {
// if yes, create a big green box nearby
CreateGameObject(new
btBoxShape(btVector3(2,2,2)), 2.0,
btVector3(0.3, 0.7, 0.3), btVector3(5, 10, 0));
}
}
Search WWH ::




Custom Search