Game Development Reference
In-Depth Information
pectation being that our selected object would move with the constraint, and keep
the same relative position until it is freed from its influence.
There are a handful of different objects which Bullet provides in order to implement
the constraint system. We'll cover the btGenericDof6Constraint object, the
most generic of the available options (hence the name). Its purpose is to give us an
interface to limit the six degrees of freedom ( Dof6 for short) of an object; these refer
to the three axes of both linear and angular motion. This constraint can either be
used to hook two rigid bodies together, or hook a single object to a single point in
space.
Building a constraint
We've seen raycasting in action earlier in this chapter, so all we need to cover is
the creation, update, and destruction of the constraint itself. CreatePickingCon-
straint() is a very large function, so we'll explore some code snippets one step
at a time:
if (!Raycast(m_cameraPosition,
GetPickingRay(x, y), output))
return;
This instruction should look familiar, since we used it earlier in this chapter. It per-
forms a raycast and returns true if it finds anything, pushing the relevant data into the
output variable.
m_pPickedBody->setActivationState(DISABLE_DEACTIVATION);
Here we're ensuring the picked object doesn't fall asleep while attached to our con-
straint. We covered activation states back in Chapter 4 , Object Management and
Debug Rendering and the last thing we want is our picked object to freeze in place
while we still have it selected!
// get the hit position relative to the body
we hit
Search WWH ::




Custom Search