{"id":23069731,"url":"https://github.com/sohne/dura2d","last_synced_at":"2025-08-15T13:32:23.567Z","repository":{"id":216194298,"uuid":"738715656","full_name":"SOHNE/Dura2D","owner":"SOHNE","description":"A learning-focused 2D physics engine project.","archived":false,"fork":false,"pushed_at":"2024-10-27T16:29:48.000Z","size":7250,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-27T19:31:35.592Z","etag":null,"topics":["cpp","learning","physics-2d","physics-engine","raylib"],"latest_commit_sha":null,"homepage":"https://dura2d.glitch.me/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SOHNE.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-03T21:58:52.000Z","updated_at":"2024-10-27T16:29:51.000Z","dependencies_parsed_at":"2024-01-08T23:24:14.252Z","dependency_job_id":"432721cc-d855-41f1-96e3-34e932cad16d","html_url":"https://github.com/SOHNE/Dura2D","commit_stats":null,"previous_names":["sohne/dura2d"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SOHNE%2FDura2D","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SOHNE%2FDura2D/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SOHNE%2FDura2D/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SOHNE%2FDura2D/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SOHNE","download_url":"https://codeload.github.com/SOHNE/Dura2D/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229915676,"owners_count":18144014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","learning","physics-2d","physics-engine","raylib"],"created_at":"2024-12-16T06:16:51.031Z","updated_at":"2024-12-16T06:16:51.435Z","avatar_url":"https://github.com/SOHNE.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dura2D\n\n\u003cdiv align=\"center\"\u003e\n\n![Dura2D](docs/assets/logo.svg)\n\n_An educational 2D Game Physics Engine_\n\n\u003cbr /\u003e\n\n[![MacOS Status](https://github.com/SOHNE/Dura2D/workflows/MacOS/badge.svg)](https://github.com/SOHNE/Dura2D/actions)\n[![Windows Status](https://github.com/SOHNE/Dura2D/workflows/Windows/badge.svg)](https://github.com/SOHNE/Dura2D/actions)\n[![Ubuntu Status](https://github.com/SOHNE/Dura2D/workflows/Ubuntu/badge.svg)](https://github.com/SOHNE/Dura2D/actions)\n[![Install Status](https://github.com/SOHNE/Dura2D/workflows/Install/badge.svg)](https://github.com/SOHNE/Dura2D/actions)\n\n[![GitHub release (latest by date)](https://img.shields.io/github/v/release/SOHNE/Dura2D?style=flat)](https://github.com/SOHNE/Dura2D/releases/latest)\n[![License](https://img.shields.io/github/license/SOHNE/Dura2D?style=flat)](https://github.com/SOHNE/Dura2D/blob/main/LICENSE)\n[![GitHub stars](https://img.shields.io/github/stars/SOHNE/Dura2D?style=social)](https://github.com/SOHNE/Dura2D/stargazers)\n\n[Live Demo](https://dura2d.glitch.me/) | [Documentation](https://sohne.github.io/Dura2D) | [Report Bug](https://github.com/SOHNE/Dura2D/issues)\n\n\u003cdiv class=\"title_screenshot\"\u003e\n\n  ![GIF of Dura2D Test Bed](res/dura2d.gif)\n\n\u003c/div\u003e\n\n\u003c/div\u003e\n\n## 🚀 Introduction\n\nThis 2D physics engine is an educational tool for exploring the principles behind game physics simulation. The project provides a hands-on approach to understanding fundamental 2D physics concepts, drawing inspiration from sources such as:\n\n- [Pikuma's Game Physics Engine Programming course](https://pikuma.com/courses/game-physics-engine-programming)\n- [Ming-Lun \"Allen\" Chou's Game Physics Series](https://allenchou.net/game-physics-series/)\n- [Erin Catto's Box2D](https://box2d.org/)\n- [Jason Gregory's Game Engine Architecture](https://www.gameenginebook.com/)\n\n## 🌟 Features\n\n- **Robust Constraint System**: Experience realistic physical interactions through constraint solver.\n- **Warm Starting**: Enjoy faster simulations with our implementation of warm starting techniques.\n- **Dynamic AABB Tree**: Enhances performance by efficiently updating bounding volume hierarchies in real-time during simulations.\n\n## 📦 Installation\n\n### CPM.cmake (Recommended)\n\nThis method is recommended for its simplicity and ease of version management.\n\n1. First, set up [CPM.cmake] in your project:\n\n   ```bash\n   mkdir -p cmake\n   wget -O cmake/CPM.cmake https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/get_cpm.cmake\n   ```\n\n2. In your `CMakeLists.txt`, add the following lines after `project(...)`:\n\n   ```cmake\n   include(cmake/CPM.cmake)\n\n   CPMAddPackage(\"gh:SOHNE/Dura2D@0.1.0\")\n\n   add_executable(your_target main.cpp)\n   target_link_libraries(your_target PRIVATE Dura2D::Dura2D)\n   ```\n\n### Vendored\n\nChoose one of the following vendored approaches based on your preference:\n\n#### Git Submodule\n\n1. Add Dura2D as a submodule to your project:\n   ```bash\n   git submodule add https://github.com/SOHNE/Dura2D.git vendor/Dura2D\n   git submodule update --init --recursive\n   ```\n\n2. In your project's `CMakeLists.txt`, add the submodule directory:\n   ```cmake\n   add_subdirectory(vendor/Dura2D)\n   ```\n\n#### Git Subtree\n\nIf you prefer to have more control over updates and want to include Dura2D directly in your repository:\n\n1. Add Dura2D as a subtree to your project:\n   ```bash\n   git subtree add --prefix vendor/Dura2D https://github.com/SOHNE/Dura2D.git main --squash\n   ```\n\n2. To update Dura2D in the future:\n   ```bash\n   git subtree pull --prefix vendor/Dura2D https://github.com/SOHNE/Dura2D.git main --squash\n   ```\n\n3. In your project's `CMakeLists.txt`, add the subtree directory:\n   ```cmake\n   add_subdirectory(vendor/Dura2D)\n   ```\n\nFor both vendored approaches, link your target with Dura2D:\n```cmake\ntarget_link_libraries(your_target PRIVATE Dura2D)\n```\n## 🎮 Usage\n\nHere's a quick example:\n\n```cpp\n#include \u003ccstdio\u003e\n#include \"dura2d/dura2d.h\"\n\nint\nmain()\n{\n    // Set up the world with gravity\n    d2Vec2 gravity(0.F, -9.8F);\n    d2World world(gravity);\n\n    // Create a circular body (Shape, Position, Mass)\n    d2Body * pBody = world.CreateBody(d2CircleShape(45), {0, 0}, 10.F);\n    pBody-\u003eSetAngularVelocity(10.F);\n\n    // Time step for the simulation\n    constexpr float timeStep = 1.F / 60.F;\n\n    // Simulate the physics for 5 seconds\n    for (int i = 0; i \u003c 60 * 5; ++i)\n    {\n        // Update the world for the next time step\n        world.Step(timeStep);\n\n        // Print the position and angle of the body every second\n        if (i % 60 == 0)\n        {\n            d2Vec2 position = pBody-\u003eGetPosition();\n            float  angle    = pBody-\u003eGetRotation();\n\n            printf(\"Position: (%.2f, %.2f) | Angle: %.2f\\n\", position.x, position.y, angle);\n        }\n    }\n\n    return 0;\n}\n```\n\n## ⚒️ Building\n\n### Prerequisites\n- [CMake] 3.26+\n- For [test bed web](#web-builds-for-testbed) builds: [Emscripten]/EMSDK properly set up in your environment\n\n### Cloning the Repository\n```bash\ngit clone https://github.com/SOHNE/Dura2D.git\ncd Dura2D\n```\n\n### Dura2D Library\n\n1. Configure the lib project:\n\n  ```bash\n  cmake -S. --preset \u003cdebug  |  release\u003e\n  ```\n\n2. Build the project:\n   ```bash\n\tcmake --build build/lib/\u003cdebug | release\u003e\n   ```\n\n#### CMake Options\n\n- `BUILD_SHARED_LIBS`: Build Dura2D as a shared library (default: OFF)\n- `USE_CCACHE`: Enable compiler cache to improve build times (default: ON for top-level builds)\n\n  Example configuration:\n  ```bash\n  cmake .. -DBUILD_SHARED_LIBS=ON -DUSE_CCACHE=ON\n  ```\n\n### Testbed\n\n1. Configure the testbed project:\n   ```bash\n   cmake -S testbed --preset \u003cdebug | release\u003e\n   ```\n\n2. Build the testbed:\n   ```bash\n   cmake --build build/testbed/\u003cdebug | release\u003e\n   ```\n\n#### Web Builds for Testbed\n\nFor [Emscripten]/HTML5 builds:\n\n1. Configure:\n   ```bash\n   cmake -S testbed --preset \u003cweb-debug | web-release\u003e\n   ```\n\n2. Build:\n   ```bash\n   cmake --build build/testbed/\u003cweb-debug | web-release\u003e\n   ```\n\n\n### Running Unit Tests\n\n1. Configure the unit tests:\n\t  ```bash\n\t   cmake -S unit-test --preset \u003cdefault  |  with-coverage  |  installed-version\u003e\n\t ```\n\n2. Build the tests:\n   ```bash\n   cmake --build build/unit-test/\u003cdefault | with-coverage | installed-version\u003e\n   ```\n\n3. Run the tests:\n   ```bash\n   ctest --test-dir build/unit-test/\u003cdefault | with-coverage | installed-version\u003e\n   ```\n\n### Generating Documentation\n\n1. Configure the documentation build:\n   ```bash\n   cmake -S docs --preset gendocs\n   ```\n\n2. Generate the documentation:\n   ```bash\n   cmake --build build/doc\n   ```\n\n3. The generated documentation will be available at:\n   ```\n   build/doc/doxygen/html/index.html\n   ```\n\n### Additional Notes\n\n- All build artifacts are organized in the `build` directory, with subdirectories for each component (*main library*, *testbed*, *unit tests*, and *documentation*).\n- Use the `--preset` option with `cmake` commands to easily switch between different configurations.\n- For any build issues, ensure all [prerequisites] are correctly installed and environment variables (like EMSDK for web/HTML5 builds) are properly set.\n\n## 🛣️ Roadmap\n\n- [ ] Introduce contact caching for optimization\n- [ ] Develop an island state system for bodies\n- [ ] Add an awake state for bodies\n- [ ] Create a robust manifold implementation\n\n## 🤝 Contributing\n\nWe welcome contributions! Whether it's bug fixes, feature additions, or documentation improvements, your input is valuable.\n\n## 🙏 Acknowledgements\n\nA huge thank you to the open-source community and the authors of the resources that inspired this project. Your work continues to educate and inspire.\n\n[//]: (Externals)\n[CPM.cmake]: https://github.com/cpm-cmake/CPM.cmake/\n[CMake]: https://cmake.org/\n[Emscripten]: https://emscripten.org/\n\n[prerequisites]: #prerequisites\n\n[//]: (EOF)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsohne%2Fdura2d","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsohne%2Fdura2d","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsohne%2Fdura2d/lists"}