Game Development Reference
In-Depth Information
Although we could implement it in this way, there is a faster way of doing it. If we
have a matrix multiplication
abc
def
ghi
x
y
z
then the x component of the result is xa
+
yb
+
zc . This is equivalent to the scalar
product
·
a
b
c
x
y
z
where the vector
a
b
c
is the contact normal, as we saw when creating the basis matrix. So we can replace the
full matrix transformation with code of the form
real angularComponent =
velocityPerUnitImpulse * contactNormal;
There is another way to think of this final step. The velocityPerUnitImpulse is
given in world coordinates. Performing the scalar product is equivalent to finding the
component of this value in the direction of the contact normal, where the contact
normal as a vector is also given in world coordinates.
It is better, in my opinion, to think in terms of the change of coordinates, because
as we introduce friction in the next chapter, the simple scalar product trick can no
longer be used. It is important to realize that we are going through the same process in
the non-friction case: finishing with a conversion from world to contact coordinates.
Putting It Together
So for each object in the collision we can now find the change in velocity of the contact
point per unit impulse.
For contacts with two objects involved we have four values: the velocity caused by
linear motion and by angular motion for each object. For contacts where only one
rigid body is involved (i.e., contacts with immovable fixtures such as the ground), we
have just two values.
In both cases we add the resulting values together to get an overall change in
velocity per unit impulse value. The whole process can be implemented in this way:
Search Nedrilad ::




Custom Search