0% found this document useful (0 votes)
187 views

Physics Engine

The physics engine source code is available online. It handles different types of forces through a consistent interface to allow new forces to be added easily. Microcollisions are used instead of reaction forces, applying impulses to solve issues with resting contacts appearing to vibrate. Friction is implemented by removing sliding velocity to stop object movement along contact planes, similar to microcollisions. Objects are put into a sleep state when resting to improve performance by restricting simulation, similar to culling in graphics engines. Contact resolution is optimized by grouping contacts involving the same objects to resolve more severe contacts first in less time than resolving a large list of all contacts.

Uploaded by

api-290095349
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
187 views

Physics Engine

The physics engine source code is available online. It handles different types of forces through a consistent interface to allow new forces to be added easily. Microcollisions are used instead of reaction forces, applying impulses to solve issues with resting contacts appearing to vibrate. Friction is implemented by removing sliding velocity to stop object movement along contact planes, similar to microcollisions. Objects are put into a sleep state when resting to improve performance by restricting simulation, similar to culling in graphics engines. Contact resolution is optimized by grouping contacts involving the same objects to resolve more severe contacts first in less time than resolving a large list of all contacts.

Uploaded by

api-290095349
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Physics Engine

Source Code: https://bitbucket.org/twntduff/physicsengine/src/dcde17bf58cc293665e90fe09162a3630833d0cf?at=master

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

When objects are resting or in a stable configuration, I put them in a


sleep state to restrict the simulation of the object. This helps improve the
performance of the physics engine in the same way that frustum culling
helps improve the performance of a graphics engine. The difference being
that objects that are not in view of the camera are not rendered on the
graphics side, but they will still simulate physics until they are no longer
reaching the threshold for movement or the sleep epsilon.

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.

You might also like