Game Development Reference
dir *= m_oldPickingDist;
btVector3 newPivot = m_cameraPosition + dir;
// set the position of the constraint
It was mentioned earlier that it was possible to get data from the constraint in a form
which is relative to one of the two objects involved in the constraint (called A and
B). We use the getFrameOffsetA() function to get the transform position of the
constraint relative to the first object, and then update it with the new value. This is
the equivalent to updating the position of the constraint's pivot point. Thus in the next
simulation step, the constraint will attempt to move the box to the new position of the
mouse, keeping the same distance from the camera as when it was first picked.
The last thing to mention is the RemovePickingConstraint() function, which
makes sure that we have an existing constraint before attempting to destroy it. If so,
we must remove it from the world, destroy the object in memory, nullify the pointers.
The re-enable the ability of the picked up object to go back to sleep.
In this section's application we can pick up one of our objects with the left mouse but-
ton and move it around. The following screenshot shows that the first box has been
moved on top of the second box of to our mouse clicking constraint: