Game Development Reference
In-Depth Information
impulseContact.y /= planarImpulse;
impulseContact.z /= planarImpulse;
impulseContact.y *= friction * impulseContact.x;
impulseContact.z *= friction * impulseContact.x;
Dividing by planarImpulse scales the y and z components so that they have a unit
size; this is done to preserve their direction while removing their size. Their size is
given by the friction equation— friction * impulseContact.x . Multiplying the di-
rection by the size gives the new values for each component.
In the previous section I glossed over how we might calculate the impulses needed to
remove velocity in the plane of the contact. We already have code that does this for
the contact normal, and we could simply duplicate this for the other directions.
Unfortunately, along with being very long-winded, this wouldn't work very well.
An impulse in one direction can cause an object to spin, and its contact point can
begin moving in a completely different direction. As long as we were only interested
in velocity in the direction of the contact normal, this didn't matter. Now we need to
handle all three directions at the same time, and we need to take into account the fact
that an impulse in one direction can increase the velocity of the contact in a differ-
ent direction. To resolve the three velocities we need to work through the resolution
algorithm for each simultaneously.
The resolution algorithm has the following steps, as before:
1. We work in a set of coordinates that are relative to the contact: this makes much
of the mathematics a lot simpler. We create a transform matrix to convert into
and out of this new set of coordinates.
2. We work out the change in velocity of the contact point on each object per unit
impulse. Because the impulse will cause linear and angular motion, this value
needs to take account of both components.
3. We will know the velocity change we want to see (in the next step), so we invert
the result of the last stage to find the impulse needed to generate any given velocity
4. We work out what the separating velocity at the contact point should be, what
the closing velocity currently is, and the difference between the two. This is the
desired change in velocity.
5. From the change in velocity we can calculate the impulse that must be generated.
6. We split the impulse into its linear and angular components and apply them to
each object.
Search Nedrilad ::

Custom Search