Game Development Reference
In-Depth Information
iterationsUsed++;
}
}
The number of iterations we use to resolve interpenetration might not necessarily be
the same as the number used in resolving collisions. We could implement the function
to use a different limit in each case.
In practice there is rarely any need to have different values: we can pass the same
for both. As a simulation gets more complex, with interacting objects, the number
of collision iterations needed will increase at roughly the same rate as the number of
interpenetration iterations. In the preceding function I've used one iteration limit for
both parts.
The recalculation of the closing velocity and interpenetration depth at each iter-
ation is the most time consuming part of this algorithm. For very large numbers of
contacts this can dominate the execution speed of the physics engine. In practice most
of the updates will have no effect: one contact may have no possible effect on another
contact. In chapter 16 we'll return to this issue and optimize the way collisions are
resolved.
7.3.2
T IME -D IVISION E NGINES
There is another approach to creating a physics engine that avoids having to resolve
interpenetration or generate a sensible resolution order for the contacts. Rather than
have one single update of the physics engine per frame, we could have many updates,
punctuated by collisions.
The theory goes like this:
When there are no collisions, objects are moving around freely, using just the
laws of motion and force generators we saw in the last chapter.
When a collision occurs, it is at the exact point that two objects touch. At this
stage there is no interpenetration.
If we can detect exactly when a collision occurs, we can use the normal laws
of motion up to this point, then stop, then perform the impulse calculations,
and then start up with the normal laws of motion again.
If there are numerous collisions, we process them in order; and between each
collision, we update the world using the normal laws of motion.
In practice this kind of engine has this algorithm:
1. Let the start time be the current simulation time and the end time be the end of
the current update request.
2. Perform a complete update for the whole time interval.
3. Run the collision detector and collect a list of collisions.
4. If there are no collisions, we are done: exit the algorithm.
Search Nedrilad ::




Custom Search