#physics #2d #box2d

box2d-rs

Port of Box2d to Rust

4 releases

0.0.4 May 12, 2023
0.0.3 Jan 13, 2022
0.0.2 Dec 31, 2021
0.0.1 Nov 20, 2020

#1457 in Game dev

Download history 4/week @ 2024-02-10 16/week @ 2024-02-17 36/week @ 2024-02-24

56 downloads per month

MIT license

740KB
18K SLoC

box2d-rs

A native port of Box2D to Rust.

Minimum Rust version: 1.56.0 (1.61 for dev-dependecies)

Ported Box2D version: 2.4.1 commits

Latest release on crates.io Documentation on docs.rs Build status dependency status codecov

When porting, I pursued the following goals

  • Keep file system structure as is for simpler further updates
  • Keep all identifiers names(except case convertion) and code order(except some specific cases)
  • Store all new not original code in separate files
  • No unsafe code

TODO

  • convert comments from doxygen to rustdoc
  • fix some comments

Known differences

  • dump() function replaced by serde library (optional dependency)
  • comments converted from doxygen to rustdoc
  • two additional buttons in the testbed's UI for serialize/deserialize (available only with serde_support feature). Serialized data available in serialize_test directory
  • query/raycast callback class replaced by closure

Usage

Add this to your Cargo.toml:

[dependencies]
box2d-rs = "0.0.4"

If you want serialize/deserialize world with serde:

[dependencies]
box2d-rs = { version = "0.0.4", features = ["serde_support"] }

Compiling and running the testbed from source

Build and run testbed in debug mode:

# At the reposity root
cargo build --examples --tests
cargo run --example testbed

In debug mode with serde_support:

cargo build --examples --tests --features serde_support
cargo run --example testbed --features serde_support

Release version with serde_support:

cargo build --examples --tests --release --features serde_support
cargo run --example testbed --release --features serde_support

Run tests

cargo test --features serde_support

Crate features

Optionally, the following dependencies can be enabled:

  • serde_support enables serialize/deserialize of world via the serde crate

Documentation

Dependencies

~97–390KB