This project is an implementation of the Game Physics in a Weekend book using the Rust programming language and the Bevy game engine.
This has been a learning excercise for me to get a better understanding of implementing a physics engine, using Bevy and also making use of my math library glam.
Note that the code from the book and this code is for learning purposes, it's not very optimized and not intended for use in production. For real world use check out Rapier or physx-rs.
I'm using a fork of Bevy 0.5.0 that is using the latest version of glam from github.
- T - toggles pausing the simulation
- Y - step the simulation while paused
- R - reset the simulation
The Bevy Flycam plugin is used for camera movement.
- WASD - move backwards, forwards, left and right
- Space - move up
- Left shift - move down
- Escape - toggle mouse cursor lock
The book uses Z up and Bevy uses Y up. I've used the Bevy Y up convention here.
The book uses row-major matrices whereas glam
uses column vectors and column
major matrices.
I've mostly tried to follow the code structure in the book, however some things don't translate so well to Rust so some organisation of code has changed.
BodyHandle
is used instead ofBody*
pointers. The handle is currently just wrapping an array index.Body
andConstraint
structs are owned byBodyArena
andConstraintArena
instead of being owned byPhysicsScene
. This makes working with the borrow checker easier.