Game Development Reference
In-Depth Information
Figure 3.13. Constraints for collision response.
3.4.1 Overview of Solver Calculation
In the iterative method, one row of linear equations represents one constraint. A
row of equations is solved and its output is used immediately by other rows. Then,
by repeating the calculation for all rows, a result will be close to the suitable
solution. Calculation continues until the calculation times reach the specified
iteration limit, and a result will be a solution.
for( int i=0;i < iterationLimit ; i++) {
for( int n=0;n < numConstraints ;n++) {
Constraint &constraint = constraintArray[n];
RigidBody &rigidbodyA = constraint . getRigidBodyA ();
RigidBody &rigidbodyB = constraint . getRigidBodyB ();
solveConstraintRow ( constraint , rigidbodyA , rigidbodyB );
}
}
Listing 3.3. Example code for the solver iteration.
Information about two related rigid bodies is necessary to calculate one con-
straint (see Figure 3.13 ) . An output is applied to two related rigid bodies immedi-
ately in calculation, but there are dependencies between rigid bodies when some
constraints share rigid bodies. We can't parallelize this solver calculation simply
to assign divided constraints into each SPU.