Game Development Reference
In-Depth Information
btVector3 localPivot =
m_pPickedBody->getCenterOfMassTransform().inverse()
* output.hitPoint;
We mentioned earlier how we would create the constraint at the exact point of the
click, which is exactly what the previous calls do, except it does so in a rather convo-
luted way.
Constraints must be defined in local space coordinates, for example, let's say we
have two objects positioned at (0,3,0) and (0,10,0) in world space coordinates.
But, from the first object's perspective, it is always positioned at (0,0,0) in its own
local space, regardless of where it is in world space. Also, as far as the first box is
concerned, the other box is positioned at (0,7,0) in its local space. Meanwhile,
from the second object's perspective, it is also positioned at (0,0,0) in its local
space, and the other box is located at (0,-7,0) in its local space.
It's possible to obtain these values mathematically by multiplying the vector repres-
enting a point in world space by the inverse of an object's transformation matrix.
Therefore in the preceding code, we multiply the hit point by the inverse transform
of the box's center of mass, giving us the hit point coordinates from the box's local
space perspective.
Tip
The previous mathematical calculation is a very important and useful feature of
matrices that is worth remembering for the future.
Next we create our constraint object:
btGeneric6DofConstraint* dof6 = new
btGeneric6DofConstraint(*m_pPickedBody, pivot,
true);
The constraint requires us to provide the body in question, the pivot point (again, in
local space coordinates), and a bool value. This boolean tells the constraint wheth-
Search WWH ::




Custom Search