# Rigid body game physics 3

25 Nov 2019part 1 part 2 part 3 part 4 part 5 part 6

The following article is based on Hubert Eichner's article on inequality constraints.

## Inequality Constraints for Resting Contacts

Contact points (resting contacts) are represented as inequality constraints.
In contrast to a joint, a resting contact can only create repellent forces and no attracting forces.
Similar to a joint constraint, the resting contact is represented using a function *C(y(t))*.
Here *C* is one-dimensional and it is basically the distance of the two objects at the contact point.
The inequality constraint of the resting contact is
with the matrix *J* having one row and twelve columns.
Instead of anchor points, one uses vectors *ri* and *rj* from the center of each object to the contact point.
Using the contact normal *n* the inequality constraint becomes:
The rotational component can be simplified as shown below:
Thus the linear components of *J* are
And the angular components of *J* are
The correction term depends on the distance *d*.
I.e. if the distance is negative, a correction is required so that the objects do not penetrate each other any more.

## Sequential Impulses (updated)

The impulses generated by contact constraints and joint constraints are accumulated in a loop.
The (cumulative) *λ* obtained for contact constraint furthermore is clipped to be greater or equal to zero.
Note that it has to be the cumulative value which is clipped.
The algorithm for solving the joint and contact constraints becomes:

- for each iteration
- for each joint
- compute Jacobian
*J*and correction vector*b* - predict speed
*u* - compute
*λ* - compute the impulse
*P* - add
*P*to accumulated impulses of the two objects

- compute Jacobian
- for each resting contact
- subtract old impulses
*P*from previous iteration from accumulated impulses of the two objects - compute Jacobian
*J*and correction vector*b* - predict speed
*u* - compute new
*λ*and clip it to be greater or equal to zero - compute the impulse
*P* - add
*P*to accumulated impulses of the two objects

- subtract old impulses

- for each joint
- use impulses and external forces to perform Runge Kutta integration step

The sequential impulse iterations have to be performed four times when using the Runge-Kutta method.