Physics Engine
Physics Engine
Force Generators
Some forces are applied because of the type of object, some are
applied because of the environment that the object is located in, and others
are applied because of their connection to other objects (There are also
cases that involve the AI applying forces). Also, some forces are constant
while most others are always changing. The physics engine needs to be able
to deal with these different types of forces because of their different types of
calculation mechanics so I am using a consistent interface to allow for the
accumulation of applied forces at each frame. This allows for the addition of
new forces without changing code in the physics engine.
Resting Contacts
Instead of calculating a set of reaction forces at each frame, I
implement microcollisions which replace the reaction forces with a series of
impulses. One issue with this system is that it makes resting contacts appear
to vibrate because the separation speed at the contact point is calculated as
a fixed ratio (coefficient of restitution) in the opposite direction because the
resting contact is treated as a collision and given a separating velocity. This
is solved by removing any velocity that is built up from acceleration in
previous updates and artificially lowering the coefficient of restitution when
the collision involves very low speeds. This solves the issue for some
simulations but others may still result in vibration.
Friction
To implement friction into the physics engine, we must first understand
what friction is doing in terms of velocity and impulses. An object with static
friction should stop that object from moving by removing the sliding velocity
and keeping the velocity at zero along the contact plane. This is exactly how
we are implementing microcollisions, but instead of removing collision
velocity we need to worry about the sliding velocity.
Sleep State
Contact Resolution/Grouping
The contact resolver algorithm checks for all possible contacts and
resolves the most severe contacts first while also checking if a contact has
been affected by a previous resolution. The problem with this system is that
larger lists of contacts take significantly more time to resolve. My solution to
this problem was to group the contacts that involve the same objects and
send these groups for resolution until all contacts have been handled.