What's next on nphysics 0.8
 
So it's been a while since my last update. This video shows some features I am working on for the new design (aka. complete rewrite) of nphysics. What you see are some of the new joint types implemented using a reduced coordinates approach. You can also see examples of joint motors and a kinematic rigid body.

Here are the upcoming features that have already been implemented (and will be published on Github at the end of January):

  • Compatibility with ECS-based designs. The physics world will be Send+Sync so it can be used safely on ECS systems. (Previous versions of nphysics used Rc<_> internally, breaking those properties.) However, nphysics itself is not implemented as an ECS (because I think it does not fit very well).
  • Compatibility with ECS means that the objects on the physics world are identified by handles. Those handles have then to be passed to the physics world in order to retrieve temporary references to a rigid body, a collider, a multibody, etc.
  • Separations of the concepts of Collider and RigidBody. Therefore, you will be able to add rigid bodies without any collider attached to them (if you don't need any contact computation).
  • Kinematic rigid bodies (bodies that have a velocity controlled by the user, e.g., for game platforms).
  • Ability to mark temporarily an object as static (it won't move), or disabled (it will be ignored by the physics engine).
  • Multibodies (in reduced-coordinates) with computation of the mass and Coriolis matrices. This especially useful for robotics. Basically this means that: 1) multibody joints cannot be violated since the constraints are directly encoded into the equations of motion (this is what "reduced coordinate approach" means). And 2) multibodies in nphysics are more accurate and stable than those on, e.g., Bullet which is based on Featherstone's algorithms (more on this on the next section).
  • Lots of joint covering all the useful combinations of limitations of degrees of freedoms: Prismatic (1 translation), Revolute (1 rotation), Helical (1 translation coupled with a rotation), Universal (2 rotations), Ball (3 rotations), Cylindrical (1 rotation, 1 translation along the same axis), Pin-slot (1 rotation, 1 translation with different axes), Rectangular (2 translation), Cartesian (3 translations), Planar (1 rotation, 2 translations), Fixed (0 degrees of freedom), and Free (3 translations, 3 rotations).
  • Joint limits and joint motors.
  • Stable gyroscopic forces: allows the simulation of e.g., the Dzhanibekov effect.

Here are the upcoming features that have not been implemented yet (and will be published on Github a the end of February):

  • Joints implemented as constraints (in full coordinates) with limits and motors. Right now, I've only implemented the Revolute, Ball, and Fixed joint. Adding others will be quite simple but will take some time.
  • Ability to remove a joint or a link from a multibody.
  • Right now sensors are broken, I'll have to re-implement them with the new design.
  • Right now continuous collision detection is also broken so I still have to re-implement it with the new design.


Major distinctions between nphysics and existing open-source C++ physics library

Here, I will only compare to Box2D and Bullet Physics v2.87:

  • nphysics2d has multibodies (based reduced coordinates) while Box2D only supports constraint-based joints.
  • nphysis3d has an implicit integration of the linear part of Coriolis/centrifugal forces for multibodies based on reduced coordinates. This means that multibody simulation will be more accurate and stable than the implementation of Bullet. Indeed, bullet implements multibodies using Featherstone's algorithm which is only able to compute Coriolis/centrifugal forces explicitly. In practice computing them explicitly will induce significant numerical errors that will usually result in the simulation exploding (unless very small timesteps are a massive amount of damping are used).
  • nphysics3d has an implicit integration of the linear part of the gyroscopic forces. Even if Bullet claims to have fully implicit integration of gyroscopic forces, this is not true stritly speaking. First, its implicit resolution only performs one step of the Newton-Raphson method meaning only the linear part is actually considered implicit. Moreover, this will work only for unconstrained bodies since there is no computation of the Coriolis matrix (which contributes to the mass matrix on the equations of motion): velocity changes due to contacts or constraints are not taken into account for the gyroscopic force computations.

Performance-wise, nphysics is still slightly behind Box2D and Bullet since at the moment my focus is on implementing the features.


Changes on ncollide and nalgebra

As a result of those works, I have a few upcoming updates on ncollide and on nalgebra:

  • The collision world on ncollide will be ECS-compatible as well.
  • Penetration depths are now computed with efficient 2D and 3D implementations of the popular EPA algorithm.
  • nalgebra will allow the construction of vector and matrix slices from a user-provided buffer (a `&[Scalar]` or `&mut[Scalar]`). This is extensively used for the efficient implementation of multibodies on nphysics since we store mathematical vectors of varying dimensions (because each multibody link may have a different number of degrees of freedoms) on a single Vec<N> for good cache-coherence.


Roadmap

Currently, the works shown in this video and described here are not published on GitHub yet nor released on crates.io. I still have some cleanup to do but if all goes well, the roadmap will be as follows:

  • About the end of January: release the changes made on ncollide and nalgebra + publish on Github the new code for nphysics.
  • About the end of February: finish the implementation of all the aforementioned features + push everything on Github.
  • About the end of March: release the new nphysics2d and nphysics3d, and publish a new website including a users-guide.

Thank you all for your support!