Skip to content

A physics engine with 3D rigid-body dynamics and collision detection (with impulse-based resolution)

License

Notifications You must be signed in to change notification settings

levilindsey/physx

Repository files navigation

physx

A physics engine with 3D rigid-body dynamics and collision detection (with impulse-based resolution).

DISCLAIMER: This has some rough edges and should probably not be used directly within production apps.

See this in use at levi.dev/dynamics!

This framework only defines physics logic. If you also need a 3D rendering framework, checkout grafx. Or checkout gamex, a game engine that ties the grafx and physx frameworks together.

Notable Features

The engine consists primarily of a collection of individual physics jobs and an update loop. This update loop is in turn controlled by the animation loop. However, whereas the animation loop renders each job once per frame loop—regardless of how much time actually elapsed since the previous frame—the physics loop updates its jobs at a constant rate. To reconcile these frame rates, the physics loop runs as many times as is needed in order to catch up to the time of the current animation frame. The physics frame rate should be much higher than the animation frame rate.

It is very important for a PhysicsJob to minimize the runtime of its update step.

Collision Detection

This physics engine also includes a collision-detection pipeline. This will detect collisions between collidable rigid bodies and update their momenta in response to the collisions.

  • Consists of an efficient broad-phase collision detection step followed by a precise narrow-phase step.
  • Calculates the position, surface normal, and time of each contact.
  • Calculates the impulse of a collision and updates the bodies' linear and angular momenta in response.
  • Applies Coulomb friction to colliding bodies.
  • Sub-divides the time step to more precisely determine when and where a collision occurs.
  • Supports multiple collisions with a single body in a single time step.
  • Efficiently supports bodies coming to rest against each other.
  • Bodies will never penetrate one another.
  • This does not address the tunnelling problem. That is, it is possible for two fast-moving bodies to pass through each other as long as they did not intersect each other during any time step.
  • This only supports collisions between certain types of shapes. Fortunately, this set provides reasonable approximations for most other shapes. The supported types of shapes are:

Code Coverage

The collision and geometry logic is tested (with Karma and Jasmine).

Acknowledgements / Technology Stack

The technologies used in this library include:

Many online resources influenced the design of this library. Some of these include:

Developing / Running the Code

See Getting Set Up or Understanding the Code for more info.

License

MIT

About

A physics engine with 3D rigid-body dynamics and collision detection (with impulse-based resolution)

Resources

License

Stars

Watchers

Forks