Game Development Reference
In-Depth Information
We have inserted a new step between 5 and 6, checking whether the impulse respects
the static friction equation and using dynamic friction if it doesn't.
Step 2 requires modification. Currently it works out the change in velocity given a
unit impulse in the direction of the contact normal. We are now dealing with all three
contact directions. We need to calculate the change in velocity given any combination
of impulses in the three contact directions. The impulse can be expressed as a vector
in contact coordinates:
Vector3 contactImpulse;
The x component represents the impulse in the direction of the contact normal, and
the y and z components represent the impulse in the plane of the contact.
The result of step 2 will be a matrix: it will transform a vector (the impulse) into
another vector (the resulting velocity). With this matrix the rest of the algorithm is
simple. In step 3 we will find the inverse of the matrix (i.e., the matrix that transforms
the desired change in velocity into a required impulse), and in step 5 we will transform
the desired velocity vector to get the contactImpulse vector.
So how do we calculate the matrix? We follow through the same steps we saw in
section 14.2.2. We calculate the velocity change as a result of angular motion, and the
velocity change as a result of linear motion.
Velocity from Angular Motion
In section 14.2.2 we saw the algorithm for calculating rotation-derived velocity from
Vector3 torquePerUnitImpulse =
relativeContactPosition % contactNormal;
Vector3 rotationPerUnitImpulse =
Vector3 velocityPerUnitImpulse =
rotationPerUnitImpulse % relativeContactPosition;
Vector3 velocityPerUnitImpulseContact =
The first stage calculates the amount of torque for a unit impulse in the direction
of the contact normal. The second stage converts this torque into a velocity using
the inertia tensor. The third stage calculates the linear velocity of the contact point
from the resulting rotation. And the final stage converts the velocity back into contact
Search Nedrilad ::

Custom Search