Game Development Reference
In-Depth Information
// add the points to the shape one at a time
for ( int ii=0; ii<numPoints; ++ii )
shape->addPoint( Vec3_to_btVector3( verts[ii] ) );
// approximate absolute mass using bounding box
btVector3 aabbMin(0,0,0), aabbMax(0,0,0);
shape->getAabb( btTransform::getIdentity(), aabbMin, aabbMax );
const btVector3 aabbExtents = aabbMax - aabbMin;
const float volume = aabbExtents.x() * aabbExtents.y() * aabbExtents.z();
const btScalar mass = volume * specificGravity;
AddShape( pStrongActor, shape, mass, physicsMaterial );
}
Notice we
re using our friend AddShape() to avoid duplicating work.
What this does is add the vertices of the convex mesh one by one, and Bullet will
create a shrink-wrap of polygons that represents the minimum volume object that
contains all the points. It will even reorder the polygons from your rendering repre-
sentation, so it might turn out more efficient for the collision system
'
'
s algorithms.
That
s cool!
The aabbMin and aabbMax are the extents of the shape
'
'
s axis-aligned bounding
box. It isn
'
tagreatmeasureofactualvolumebyanystretch,butit
'
sbetterthan
nothing, and it
'
s a good thing to know how to get these values from Bullet if you
need them.
Creating a Trigger
Another useful object is the trigger. A trigger is something that gives you a callback if
objects enter or leave it, which can be very useful for many things. For example, you
can spawn some AIs when the player moves through a certain doorway.
Bullet triggers are the same as other objects, except they have no mass, and they don
'
t
collide with anything. Not colliding means that objects will move straight through
them as if they
re not even there. The only thing they need to do is generate an
event for the game system when something touches them.
'
void BulletPhysics::VCreateTrigger(WeakActorPtr pGameActor,
const Vec3 &pos, const float dim)
{
StrongActorPtr pStrongActor = MakeStrongPtr(pGameActor);
if (!pStrongActor)
return;
 
 
Search WWH ::




Custom Search