Collision Resolution - SC-SGS/surviving-sarntal GitHub Wiki
When a collision between two polygons is detected, the colliding objects are displaced to restore the validity of the current world state. Additionally, appropriate reactive impulses are applied.
In addition to transferring the world back to a valid state, displacement serves the purpose of approximating the first point of contact between two objects.
Only there, impulses can be applied accurately.
Once a collision occurs, the colliding polygons are moved apart by the collision depth
If the collision was found by substepping, we first set the polygons to their positions at the time of the collision substep and then apply displacement from there.
Not every contact is necessarily a collision.
Only when rocks are moving towards one another at a contact point, we consider it a collision requiring the application of impulses.
Fig. \ref{fig:CR} shows that this is the case, when the relative velocity $\vec{v}{rel}$ at the contact point $\vec{c}$ is opposed to the normal $\vec{n}$, i.e.:
$$
\left<\vec{n},\vec{v{rel}}\right> = \left<\vec{n},\vec{v_{inc}}(\vec{c})-\vec{v_{ref}}(\vec{c})\right> < -\epsilon
$$
where
$$
\vec{v}(\vec{c}) = \frac{\vec{P}}{m} + \frac{L}{I}
\left(\begin{array}{c c}
0 & -1\
1 & 0
\end{array}\right)
(\vec{c} - \vec{x})
$$
Finally, the impulse is applied to both the incident and the reference polygon.
The formula for the magnitude
For terrain collisions, impulse and displacement are evidently only applied to the polygon and not on the terrain triangles which are static.
Figure: On the left, the polygons have been displaced to their first point of collision. $\vec{v}{rel}^{,-}$ is opposed to $\vec{n}$. The right side shows how the collision is resolved by applying impulses $\pm j\vec{n}$, so that $\vec{v}{rel}^{,+}$ is no longer opposed to