{"id":24285147,"url":"https://github.com/yoyoengine/p2d","last_synced_at":"2025-08-26T12:07:14.858Z","repository":{"id":271936783,"uuid":"909449899","full_name":"yoyoengine/p2d","owner":"yoyoengine","description":"A 2D rigidbody physics system written for yoyoengine","archived":false,"fork":false,"pushed_at":"2025-02-02T23:45:15.000Z","size":153,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-02-03T00:26:00.897Z","etag":null,"topics":["2d","physics-engine","yoyoengine"],"latest_commit_sha":null,"homepage":"","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/yoyoengine.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-12-28T18:31:50.000Z","updated_at":"2025-02-02T23:45:18.000Z","dependencies_parsed_at":"2025-01-10T21:39:17.824Z","dependency_job_id":"258325d4-cd8d-449b-8476-58788eccf29e","html_url":"https://github.com/yoyoengine/p2d","commit_stats":null,"previous_names":["yoyoengine/p2d"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoyoengine%2Fp2d","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoyoengine%2Fp2d/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoyoengine%2Fp2d/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoyoengine%2Fp2d/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoyoengine","download_url":"https://codeload.github.com/yoyoengine/p2d/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242087919,"owners_count":20069722,"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":["2d","physics-engine","yoyoengine"],"created_at":"2025-01-16T06:29:46.443Z","updated_at":"2025-03-05T19:06:40.191Z","avatar_url":"https://github.com/yoyoengine.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003cpicture style=\"width: 100%; height: auto;\"\u003e\n        \u003csource srcset=\".github/media/p2dlogo.png\"  media=\"(prefers-color-scheme: dark)\"\u003e\n        \u003cimg src=\".github/media/p2dlogo.png\"\u003e\n    \u003c/picture\u003e\n\u003c/div\u003e\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n![GitHub repo size](https://img.shields.io/github/repo-size/yoyoengine/p2d)\n\n---\n\nA 2D rigidbody physics system written for yoyoengine.\n\n## Features\n\n- Broad phase collision detection, using a hashed spatial grid\n- OOB and Circle collision detection and resolution\n- Collision and trigger callbacks\n- Easy synchronization with existing ECS\n- Frustum-culled sleeping objects\n- Spring and Hinge Joints\n- Collision layers\n\n\u003e [!WARNING]  \n\u003e Internal rotations are stored in degrees (not radians!) so make sure you convert properly.\n\n## Usage\n\n```c\n#include \u003cp2d/p2d.h\u003e\n\n// example collision callback\nvoid collision_callback(struct p2d_cb_data* data) {\n  // ...\n}\n\n// example trigger callback\nvoid trigger_callback(struct p2d_cb_data* data) {\n  // ...\n}\n\n// at some point during init\np2d_init(..., trigger_callback);\n\n// create and register objects\n// ...\nstruct p2d_object obj = {0};\nobj.type = P2D_OBJECT_RECTANGLE,\nobj.x = 100;\nobj.y = 200;\nobj.vx = 100;\nobj.out_x = \u0026YOUR_ECS_X;\nobj.out_y = \u0026YOUR_ECS_Y;\nobj.out_rotation = \u0026YOUR_ECS_ROTATION;\nobj.mask = P2D_LAYER_1 \u0026 P2D_LAYER_2;\np2d_register_object(\u0026obj);\n// ...\n\n// in your engine update loop: (run this at the hz you want your physics to run at)\np2d_step(physics_delta_time);\n\n// before quitting, shutdown\np2d_shutdown();\n```\n\n## Future work\n\n| Item                | Description                                 | Priority | Progress        |\n|---------------------|---------------------------------------------|----------|-----------------|\n| Debug Resolution    | The current basic resolution has edge cases | High     | Done            |\n| Rotation Resolution | Implement rotation and torque               | High     | Done            |\n| Friction Resolution | Implement friction                          | High     | Done            |\n| Joints              | Constraints between objects                 | High     | Mostly Done     |\n| Collision Layers    | Specify what can collide with what          | Medium   | Mostly Done     |\n| Advanced Gravity    | Allow seperate spatial fields of gravity    | Low      | Maybe Later     |\n| New Shapes          | Implement planes for more complex shapes    | Low      | Maybe Later     |\n| Optimization        | Micro-optimize for performance              | Low      | Maybe Later     |\n| Add \"True\" Sleeping | Standstill objects get optimized out        | Low      | Maybe Later     |\n\n## Testing\n\n`cmake -DBUILD_P2D_TESTS=ON ..`\n\n## Resources\n\nHere are some resources that helped me along the way, which can hopefully be useful to you too!\n\n- [(Book) Game Physics Engine Development](https://www.amazon.com/Game-Physics-Engine-Development-Commercial-Grade/dp/0123819768)\n- [(Book) Real Time Collision Detection (Book)](https://a.co/d/g9Rpjsk)\n- [(Youtube) Two-Bit Coding Physics Engine Playlist](https://www.youtube.com/playlist?list=PLSlpr6o9vURwq3oxVZSimY8iC-cdd3kIs)\n- [(Articles) Rigid Body Dyanmics - Chris Hecker](https://www.chrishecker.com/Rigid_Body_Dynamics)\n- [(Reference Example) Box2D](https://github.com/erincatto/box2d-lite/tree/master/Box2D)\n\n## Advice\n\nIf I were to write this again from scratch, I would:\n\n- Avoid writing a physics engine at all, unless I was doing it for fun or learning (it's really really hard)\n- define rectangles by half extents, because their x,y position should be the center, not the top left (mixing with circles that have x,y as center is a huge pain)\n- use radians instead of degrees internally (the conversion is a big failure point)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoyoengine%2Fp2d","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoyoengine%2Fp2d","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoyoengine%2Fp2d/lists"}