Getting started§

nphysics relies on the official Rust package manager Cargo for dependency resolution and compilation. Therefore, making nphysics ready to be used by your project is simply a matter of adding a new dependency to your Cargo.toml file. You can either use the nphysics2d crate for 2D physics simulation or the nphysics3d crate for 3D physics simulation. You can even use both if you need both 2D and 3D in your application. Note that you will probably need nalgebra as well because it defines algebraic entities (vectors, points, transformation matrices) used by most types of nphysics. Similarly, you will probably need ncollide2d or ncollide3d which defines all the geometric entities for collision shapes (spheres, cubes, triangle meshes, etc.)

[dependencies]
nalgebra = "0.20"
# Choose the one you need, or both.
ncollide2d = "0.22"
ncollide3d = "0.22"
# Choose the one you need, or both.
nphysics2d = "0.14"
nphysics3d = "0.14"

Until nphysics reaches 1.0, it is strongly recommended to always use its latest version, though you might encounter breaking changes from time to time.

Cargo example§

Here is an example Cargo file for compiling an executable depending on nphysics:

[package]
name    = "example-using-nphysics"
version = "0.0.0"
authors = [ "You" ]

[dependencies]
nalgebra = "0.20"
ncollide2d = "0.22"
nphysics2d = "0.14"

[[bin]]
name = "example"
path = "./example.rs"

[package]
name    = "example-using-nphysics"
version = "0.0.0"
authors = [ "You" ]

[dependencies]
nalgebra = "0.20"
ncollide3d = "0.22"
nphysics3d = "0.14"

[[bin]]
name = "example"
path = "./example.rs"

Rigid body simulation