2D Rigidbody physics engine
- Continuous collision detection (Bilateral advancement by Erin Catto of Box2D)
- Shapes: circle, capsule, and convex polygon
- Support for rounded polygons
- Multiple colliders attached to a single body
- Dynamic, static, and kinematic bodies
- Collision filtering
- Dynamic AABB tree broadphase
- Accelerated raycast, shapecast, and area queries
- Easy-to-use collision detection and distance functions
- Continuous physics simulation (time of impact solver and sub-stepping)
- PGS solver with a separate position solver
- Stable stacking with a 2-contact LCP solver (Block solver)
- Efficient and persistent contact management from Box2D
- Constraint islanding and sleeping
- Contact callbacks: begin, touching, end, pre-solve, post-solve, and destroy
- Physics material: friction, restitution, and surface speed
- Various joints: angle, distance, grab, line, motor, prismatic, pulley, revolute, and weld
- Cross platform library (C++20)
- Intuitive and straightforward API design
- 50+ interactive demos
- OpenGL based cross platform demo framework
- WebAssembly powered web demo
#include "muli/muli.h"
using namespace muli;
int main()
{
WorldSettings settings;
World world(settings);
RigidBody* box = world.CreateBox(1.0f);
box->SetPosition(0.0f, 5.0f);
// Run simulation for one second
float dt = 1.0f / 60.0f;
for(int i = 0; i < 60; ++i)
{
world.Step(dt);
}
return 0;
}- Install CMake.
- Ensure CMake is in the system
PATH. - Clone the repository:
git clone https://github.com/Sopiro/Muli - Run CMake build script for your system:
- Visual Studio: Run
build.bat. - Other systems: Run
build.sh.
- Visual Studio: Run
- You can find the demo executable in
build/bin.
You can easily include the library using CMake's FetchContent module.
include(FetchContent)
FetchContent_Declare(
muli
GIT_REPOSITORY https://github.com/Sopiro/Muli
)
set(MULI_BUILD_DEMO OFF)
FetchContent_MakeAvailable(muli)You can install the library using these commands:
mkdir build
cd build
cmake -DMULI_BUILD_DEMO=OFF ..
cmake --build . --config Release
cmake --install . --prefix "installation-path"Assuming you've added "installation-path" to your system PATH, you can now integrate the library into your project.
find_package(muli REQUIRED)
target_link_libraries(your-project PRIVATE muli::muli)Here are some great resources for learning how to build a physics engine:
