Skip to content

Sopiro/Muli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

626 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo

Muli

Build library

2D Rigidbody physics engine

Features

Collision

  • 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

Physics Simulation

  • 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

Others

  • Cross platform library (C++20)
  • Intuitive and straightforward API design

Demo

  • 50+ interactive demos
  • OpenGL based cross platform demo framework
  • WebAssembly powered web demo

Example

#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;
}

Building and running the demo

  • 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.
  • You can find the demo executable in build/bin.

Including the library

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)

Installing the library

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)

References

Here are some great resources for learning how to build a physics engine:

About

2D Physics Engine

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages