A fast and lightweight 2D game physics library.

Overview

NEW IN CHIPMUNK 7

Chipmunk 7 is complete and now includes the ARM NEON optimizations, the autogeometry code, and the mulithreaded solver.

The latest programming guide is available.

ABOUT:

Chipmunk2D is a simple, lightweight, fast and portable 2D rigid body physics library written in C. It’s licensed under the unrestrictive, OSI approved MIT license. My aim is to give 2D developers access to the same quality of physics you find in newer 3D games. I hope you enjoy using Chipmunk2D!

FEATURES:

  • Designed specifically for 2D video games.
  • Circle, convex polygon, and beveled line segment collision primitives.
  • Multiple collision primitives can be attached to a single rigid body.
  • Fast broad phase collision detection by using a bounding box tree with great temporal coherence or a spatial hash.
  • Extremely fast impulse solving by utilizing Erin Catto’s contact persistence algorithm.
  • Supports sleeping objects that have come to rest to reduce the CPU load.
  • Support for collision event callbacks based on user definable object types types.
  • Flexible collision filtering system with layers, exclusion groups and callbacks.
    • Can be used to create all sorts of effects like one way platforms or buoyancy areas. (Examples included)
  • Supports nearest point, segment (raycasting), shape and bounding box queries to the collision detection system.
  • Collision impulses amounts can be retrieved for gameplay effects, sound effects, etc.
  • Large variety of joints – easily make vehicles, ragdolls, and more.
  • Joint callbacks.
    • Can be used to easily implement breakable or animated joints. (Examples included)
  • Maintains a contact graph of all colliding objects.
  • Lightweight C99 implementation with no external dependencies outside of the Std. C library.
  • Many language bindings available.
  • Simple, read the documentation and see!
  • Unrestrictive MIT license

CONTRACTING:

Howling Moon Software (my company) is available for contracting if you want to make the physics in your game really stand out. Given our unique experience with the library, we can help you use Chipmunk to its fullest potential. Feel free to contact us through our webpage: http://howlingmoonsoftware.com/

BUILDING:

Mac OS X: There is an included Xcode project file for building the static library and demo application. Alternatively you could use the CMake files or the macstatic.command script inside the xcode/ directory to build a static lib and package up the headers for you.

iPhone: A native Objective-C API is included. The Xcode project can build a static library with all the proper compiler settings. Alternatively, you can just run iphonestatic.command in the xcode/ directory. It will build you a fat library compiled as release for the device and debug for the simulator. After running it, you can simply drop the Chipmunk-iOS directory into your iPhone project!

UNIXes: A forum user was kind enough to make a set of CMake files for Chipmunk. This will require you to have CMake installed. To build run ‘cmake .’ then ‘make’. This should build a dynamic library, a static library, and the demo application. A number of people have had build errors on Ubuntu due to not having GLUT or libxmu installed.

Windows: Visual Studio projects are included in the msvc/ directory. While I try to make sure the MSVC 10 project is up to date, I don’t have MSVC 9 to keep that project updated regularly. It may not work. I’d appreciate a hand fixing it if that’s the case.

GET UP TO DATE:

If you got the source from a point release download, you might want to consider getting the latest source from GitHub. Bugs are fixed and new features are added regularly. Big changes are done in branches and tested before merging them in it’s rare for the point release downloads to be better or more bug free than the latest code.

Head on over to GitHub and experience the future TODAY! (Okay, so maybe it’s not that exciting.)

GETTING STARTED:

First of all, you can find the C API documentation in the doc/ directory.

A good starting point is to take a look at the included Demo application. The demos all just set up a Chipmunk simulation space and the demo app draws the graphics directly out of that. This makes it easy to see how the Chipmunk API works without worrying about the graphics code. You are free to use the demo drawing routines in your own projects, though it is certainly not the recommended way of drawing Chipmunk objects as it pokes around at the undocumented/private APIs of Chipmunk.

SUPPORT:

The best way to get support is to visit the Chipmunk Forums. There are plenty of people around using Chipmunk on the just about every platform I’ve ever heard of. If you are working on a commercial project and want some more direct help, Howling Moon Software is also available for contracting.

Issues
  • Fix compilation with MSVC14 and C++14 compilers, and gets rid of pthread-win32

    Fix compilation with MSVC14 and C++14 compilers, and gets rid of pthread-win32

    Hey.

    I'm looking at using Chipmunk as a 2D physics engine for my game engine and I had some troubles compiling it under Windows because of MSVC now supporting users litterals and because of the pthread.h include, so I did fix that.

    I also reimplemented a very small pthread implementation based on Win32 API, this way we don't have to use pthread-win32 on Windows, which is a problem because it's LGPL-licenced.

    opened by SirLynix 18
  • Build failure in Windows (MinGW-W64) due to missing `<sys/sysctl.h>`

    Build failure in Windows (MinGW-W64) due to missing ``

    Chipmunk 7.0.0 fails to build in Windows.

    The compiler used was MinGW-W64, and the reason appears to be a missing <sys/sysctl.h> include in src/cpHastySpace.c:

    [ 20%] Building C object src/CMakeFiles/chipmunk.dir/cpHastySpace.c.obj
    C:\Devel\build\Chipmunk-7.0.0\src\cpHastySpace.c:9:24: fatal error: sys/sysctl.h: No such file or directory
     #include <sys/sysctl.h>
                            ^
    compilation terminated.
    src\CMakeFiles\chipmunk.dir\build.make:342: recipe for target 'src/CMakeFiles/chipmunk.dir/cpHastySpace.c.obj' failed
    mingw32-make[2]: *** [src/CMakeFiles/chipmunk.dir/cpHastySpace.c.obj] Error 1
    CMakeFiles\Makefile2:76: recipe for target 'src/CMakeFiles/chipmunk.dir/all' failed
    mingw32-make[1]: *** [src/CMakeFiles/chipmunk.dir/all] Error 2
    makefile:116: recipe for target 'all' failed
    mingw32-make: *** [all] Error 2
    
    Bug Windows 
    opened by darkuranium 10
  • Xcode scheme for tvos

    Xcode scheme for tvos

    Hi,

    I'm working on making cocos2d 3.5 work inside SpriteBuiler 1.5 I would need a twos scheme for chipmunk so that I can point directly to your repository Do you think this is possible ?

    Thank you

    Olivier

    opened by oxeron 8
  • Build problems with Visual Studio.

    Build problems with Visual Studio.

    Received via email:

    After having all the paths and directories right: -i had to edit "chipmunk.c" at line 46 and put instead " const char *cpVersionString = ""; " -i compiled the lib, and i installed the C++ wrapper from jhasse, chipmunkpp -i got an error from cpCollision.obj, and i didn't understand for a while and then i discovered that cpRobust.h and cpRobust.c weren't put in the Visual Studio solution, i re-compiled and then got a weird error and it cames from the "cpRobust.c" at line 1 it was written " #import " instead of " #include "

    so just a few tricks to get it compiled but, i wanted to share you these so you will maybe fix them

    INFOS: -downloaded by github https://github.com/slembcke/Chipmunk2D/tree/07d74973eaa285cc7eee80e79ef9b9d545d2a9d1

    -used the vs13 folder/solution

    -used Visual Studio 2015

    opened by slembcke 7
  • Sreich add header guards

    Sreich add header guards

    add some include guards on nearly all public headers. it's very dangerous to not do this, and it will wreak havoc on most projects when they try to use it.

    in fact, i don't know how no users caught this earlier, my project's uses witnesses the breakages quite unavoidably.

    opened by sreich 6
  • Dust off VC10 project

    Dust off VC10 project

    Hi Scott. I'm learning Github; hope you don't mind my poking at Chipmunk in the process.

    This pull request incorporates some changes to get the Visual C++ 2010 project building again.

    The .gitignore was over-aggressive in culling out everything within the msvc project directory, which meant changes to project files (*.vcxproj and *.vcxproj.filters, to name a couple) weren't getting committed. (That's my guess as to what happened, at any rate.) I've attempted to slice out things more judiciously.

    I left the vc9 project alone; it has a more fundamental problem in that stdint.h is not included with that version of Visual C++.

    Thanks, James

    opened by mcneja 6
  • fix headers to utilize include guards, else all hell breaks lose easily

    fix headers to utilize include guards, else all hell breaks lose easily

    when someone tries to use them.

    cherry picked because github merge is a fucking retard (cherry picked from commit 76e0b93999b38de024631d5c60b2c1b65f33a81f)

    opened by sreich 5
  • Racket FFI

    Racket FFI

    Hi,

    I'm trying to create an updated FFI for Chipmunk 7 for the Racket language. It's kind of working. Something about callbacks seems broken.

    Here's the basic "Hello World" example from the Chipmunk docs. I converted it to Racket, verified that it worked, then added some collision handler callbacks. The begin callback seems to be broken, though.

    #lang racket
    
    (require racket-chipmunk/lang/chipmunk-ffi)
    
    (define gravity (cpv 0 -100))
    (define space (cpSpaceNew))
    
    (define handler (cpSpaceAddDefaultCollisionHandler space))
    
    (set-cpCollisionHandler-cpCollisionBeginFunc!
      handler
      (lambda (a s d)
        (displayln "Begin")
        1))
    
    (set-cpCollisionHandler-cpCollisionPreSolveFunc!
      handler
      (lambda (a s d)
        (displayln "PreSolve")
        1))
    
    (set-cpCollisionHandler-cpCollisionPostSolveFunc!
      handler
      (lambda (a s d)
        (displayln "PostSolve")
        1))
    
    (set-cpCollisionHandler-cpCollisionSeparateFunc!
      handler
      (lambda (a s d)
        (displayln "Separate")
        1))
    
    
    (cpSpaceSetGravity space gravity)
    
    (define ground 
      (cpSegmentShapeNew 
        (cpSpaceGetStaticBody space)
        (cpv -20 5)
        (cpv 20 -5)
        0.0))
    
    (cpShapeSetFriction ground 1.0)
    (cpSpaceAddShape space ground)
    
    (define radius 5.0)
    (define mass 1.0)
    
    (define moment (cpMomentForCircle mass 0.0 radius (cpv 0 0)))
    
    (define ballBody (cpSpaceAddBody space (cpBodyNew mass moment)))
    
    (define ballShape (cpSpaceAddShape space (cpCircleShapeNew ballBody radius (cpv 0 0))))
    
    (cpShapeSetFriction ballShape 0.7)
    
    (define timeStep (/ 1 60))
    
    (define time 0)
    (let loop ()
      (set! time (+ time timeStep)) 
    
      (define pos (cpBodyGetPosition ballBody))
      (define vel (cpBodyGetVelocity ballBody))
      
      (cpSpaceStep space (real->double-flonum time))
    
      (when (< time 2) 
        (loop)))
    
    
    (cpShapeFree ballShape)
    (cpBodyFree ballBody)
    (cpShapeFree ground)
    (cpSpaceFree space)
    

    The output is puzzling me:

    PreSolve
    PostSolve
    Separate
    PostSolve
    Separate
    PostSolve
    Separate
    PostSolve
    Separate
    PostSolve
    Separate
    PostSolve
    Separate
    PostSolve
    Separate
    PostSolve
    Separate
    PostSolve
    Separate
    PostSolve
    Separate
    PostSolve
    Separate
    PostSolve
    Separate
    PostSolve
    Separate
    

    A few odd things:

    1. Why does "Begin" never print?
    2. Why do "PostSolve" and "Separate" print so much more than "PreSolve"?

    If it helps, here are my FFI declarations for these callbacks:

    (define _cpCollisionBeginFunc
      (_fun _cpArbiter-pointer
            _cpSpace-pointer
            _pointer
            -> _cpBool))
    
    (define _cpCollisionPreSolveFunc
      (_fun _cpArbiter-pointer
            _cpSpace-pointer
            _pointer
            -> _cpBool))
    
    (define _cpCollisionPostSolveFunc
      (_fun _cpArbiter-pointer
            _cpSpace-pointer
            _pointer
            -> _cpBool
            ;The Chipmunk docs say it should be _void, but that was causing weird behavior too.
            ;I've tried it both ways
    ))
    
    (define _cpCollisionSeparateFunc
      (_fun _cpArbiter-pointer
            _cpSpace-pointer
            _pointer
            -> _cpBool
            ;Made this non-void too, but only to be consistent
     ))
    
    (define-cstruct _cpCollisionHandler
      ([typeA _cpCollisionType]
       [typeB _cpCollisionType]
       [cpCollisionBeginFunc     _cpCollisionBeginFunc]
       [cpCollisionPreSolveFunc  _cpCollisionPreSolveFunc]
       [cpCollisionPostSolveFunc _cpCollisionPostSolveFunc]
       [cpCollisionSeparateFunc  _cpCollisionSeparateFunc]
       [cpDataPointer            _cpDataPointer]))
    

    Any ideas what I'm doing wrong?

    opened by srfoster 4
  • Chipmunk demos can't be compiled in Ubuntu 16.10

    Chipmunk demos can't be compiled in Ubuntu 16.10

    I have glfw3 installed that newer than version needed for Chimpmunk demos and a bit differ. So, I can't configure and build it:

    CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: GLFW_INCLUDE_DIR used as include directory in directory /home/robotex/sources/Chipmunk2D/demo

    There is no older versions of GLFW in repository.

    opened by NicholasShatokhin 4
  • Hello Chipmunk example not compiling

    Hello Chipmunk example not compiling

    Hi,

    The first example displayed here has two issues when compiling it as a C++ program (haven't tried as a C program).

    The first issue is just a few typos:

    • cpBodySetPos should be cpBodySetPosition
    • cpBodyGetPos should be cpBodyGetPosition
    • cpBodyGetVel should be cpBodyGetVelocity

    But the other issue is more tricky and got only a workaround ATM: when compiling it as is, I get the following error

    main.cpp:30:46: error: member access into incomplete type 'cpSpace'
        cpShape *ground = cpSegmentShapeNew(space->staticBody, cpv(-20, 5), cpv(20, -5), 0);
                                                 ^
    

    If I change the include to #include <chipmunk_private.h> it works but that's probably not how it should be solved...

    High Priority Documentation 
    opened by mantognini 4
  • Unified the FFI by eliminating public static inline functions

    Unified the FFI by eliminating public static inline functions

    The FFI no longer consists of function pointers, which makes it much easier to import them in other programs/languages. Public functions that were declared static inline are now just inline and exported in a seperate translation unit, as recommended by section 6.7.4 of the ISO C standard

    Something similar was already noted in include/chipmunk/chipmunk_ffi.h:

    // TODO: get rid of the reliance on static inlines.
    // They make a mess for FFIs.
    

    Legacy function pointers are still supported, though the use of -DCHIPMUNK_LEGACY_FFI. An additional option in cmake makes it easy to enable or disable this feature. Eventually, it can be removed completely.

    There were also a few inlude-directives in src/ that were inconsistent with some other files; I have changed them to what I thought they should be.

    Tested on Ubuntu 14.04 with GCC 4.8.2.

    opened by ghost 4
  • Add cpShapeIsPoly, cpShapeIsSegment, cpShapeIsCircle functions

    Add cpShapeIsPoly, cpShapeIsSegment, cpShapeIsCircle functions

    Addresses #219.

    Imagine you are writing a cpShapeEach callback to draw a scene which contains both circle and poly shapes. At the moment, there is no way to determine whether any one shape addressed by the callback is a circle, a poly, or something else. However telling circles and polys apart is necessary because functions like cpPolyShapeGetCount() assert-crash when called on the wrong kind of shape.

    This patch adds three new functions cpShapeIsPoly, cpShapeIsSegment, cpShapeIsCircle that do the expected thing. I am indifferent to whether this is the best naming for these functions.

    I tested this by doing a successful build and calling cpShapeIsPoly in live code (although my tests were in a feature branch based on older Chipmunk.) I did not attempt to modify any documentation.

    opened by mcclure 0
  • cpSpaceSegmentQueryFirst returns wrong normal If a segment query starts within a shape

    cpSpaceSegmentQueryFirst returns wrong normal If a segment query starts within a shape

    From manual: "If a segment query starts within a shape it will have t = 0 and n = cpvzero." Instead it has t = 0 (correct) and n equal some garbage value (incorrect). See "Segment Query Demo" from Chipmunk source to reproduce this bug.

    opened by mosmetro 0
  • Licensing confusion

    Licensing confusion

    According to VERSION.txt and the chipmunk-physics.net website, all Chipmunk Pro features are now open source. Indeed, they do seem to be included in this repo, however they still list the following copyright disclaimer:

    // Copyright 2013 Howling Moon Software. All rights reserved.
    // See http://chipmunk2d.net/legal.php for more information.
    

    The legal page that the mentioned URL redirects to states that licenses are still required in order to use the Pro features, but there does not appear to be anywhere to purchase one.

    I expect this is just leftover stuff that hasn't been cleaned up since the features were open sourced, but it'd be great to get the legal page changed and the source code header changed to the MIT one, just to avoid confusion and make any potential lawyers happy.

    opened by silversquirl 1
  • [Documentation] cpPolyShapeGetCount typo in docs

    [Documentation] cpPolyShapeGetCount typo in docs

    The docs list a function

    int cpPolyShapeGetNumVerts(cpShape *shape) ...

    Getters for poly shape properties. Passing a non-poly shape or an index that does not exist will throw an assertion.

    However, the function in cpPolyShape.h:

    /// Get the number of verts in a polygon shape.
    CP_EXPORT int cpPolyShapeGetCount(const cpShape *shape);
    

    The name is wrong in the docs.

    opened by mcclure 0
High-performance C++ multibody dynamics/physics library for simulating articulated biomechanical and mechanical systems like vehicles, robots, and the human skeleton.

Simbody Simbody is a high-performance, open-source toolkit for science- and engineering-quality simulation of articulated mechanisms, including biomec

Simbody Project 1.9k May 15, 2022
C++ library for multi-physics simulation

Project CHRONO Project Chrono represents a community effort aimed at producing a physics-based modelling and simulation infrastructure based on a plat

null 1.4k May 13, 2022
Box2D is a 2D physics engine for games

Build Status Box2D Box2D is a 2D physics engine for games. Contributing Please do not submit pull requests with new features or core library changes.

Erin Catto 5.7k May 17, 2022
2D physics engine for games

LiquidFun Version 1.1.0 Welcome to LiquidFun! LiquidFun is a 2D physics engine for games. Go to our landing page to browse our documentation and see s

Google 4.4k May 7, 2022
Real-time multi-physics simulation with an emphasis on medical simulation.

Introduction SOFA is an open source framework primarily targeted at real-time simulation, with an emphasis on medical simulation. It is mainly intende

SOFA Framework 605 May 10, 2022
Natively multithreaded physics for threejs with PhysX.

Three-Physx Natively multithreaded physics for threejs with PhysX and an easy interface. Credit to Milkshake inc, physx-js, three-ammo, three-to-canno

XR Foundation 12 Feb 17, 2022
A modern C++11 quantum computing library

Quantum++ Version 2.6 - 9 January 2021 Build status: Chat (questions/issues) About Quantum++ is a modern C++11 general purpose quantum computing libra

softwareQ Inc. 361 May 3, 2022
Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

Bullet Physics SDK This is the official C++ source code repository of the Bullet Physics SDK: real-time collision detection and multi-physics simulati

Bullet Physics SDK 9.3k May 10, 2022
Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

Bullet Physics SDK 9.3k May 11, 2022
SKR_Physics is a lightweight and easy to use 2D physics engine which is written in C++.

SKR_Physics SKR_Physics is a lightweight and easy to use 2D physics engine which is written in C++. Features Rectangle based collision system Very sim

Şükrü 0 Mar 8, 2022
A game with basic physics and platforming.

Physgun A simple game with basic physics and platforming. Planned features Work in progress: Physics engine. Swept AABB collision algorithm. Elastic a

Bad Games Studio 24 Dec 17, 2021
A Tiny 2D OpenGL based C++ Game Engine that is fast, lightweight and comes with a level editor.

A Tiny 2D OpenGL based C++ Game Engine that is fast, lightweight and comes with a level editor.

Samuel Rasquinha 47 Apr 12, 2022
Source code for Game Physics Cookbook

Game Physics Cookbook Website Facebook Twitter This book is a comprehensive guide to the linear algebra and collision detection games commonly use, bu

Gabor Szauer 597 May 11, 2022
2D physics header-only library for videogames developed in C using raylib library.

Physac Physac is a small 2D physics engine written in pure C. The engine uses a fixed time-step thread loop to simluate physics. A physics step contai

Víctor Fisac 202 May 7, 2022
High-performance C++ multibody dynamics/physics library for simulating articulated biomechanical and mechanical systems like vehicles, robots, and the human skeleton.

Simbody Simbody is a high-performance, open-source toolkit for science- and engineering-quality simulation of articulated mechanisms, including biomec

Simbody Project 1.9k May 15, 2022
A multi core friendly rigid body physics and collision detection library suitable for games and VR applications.

Jolt Physics Library A multi core friendly rigid body physics and collision detection library suitable for games and VR applications. A YouTube video

null 1.6k May 14, 2022
A multi core friendly rigid body physics and collision detection library suitable for games and VR applications.

A multi core friendly rigid body physics and collision detection library suitable for games and VR applications.

null 1.6k May 11, 2022
A 2D collision detection and physics library written in C.

A 2D collision detection and physics library written in C. WARNING: This library is in an early alpha stage, use it at your own risk. Documentation —

c-krit 67 May 9, 2022
A coupling library for partitioned multi-physics simulations, including, but not restricted to fluid-structure interaction and conjugate heat transfer simulations.

A coupling library for partitioned multi-physics simulations, including, but not restricted to fluid-structure interaction and conjugate heat transfer simulations.

preCICE 410 May 4, 2022
A small data-oriented and SIMD-optimized 3D rigid body physics library.

nudge Nudge is a small data-oriented and SIMD-optimized 3D rigid body physics library. For more information, see: http://rasmusbarr.github.io/blog/dod

null 228 May 13, 2022
Real-time oriented physics engine and library that's currently best suited for 2D games.

PlayRho A way to play with physical behaviors like the conservation of momentum. PlayRho is a real-time oriented physics engine and library that's cur

Louis Langholtz 82 Apr 22, 2022
A C++ fast and lightweight 3D vector library

Vector3D A C++ fast and lightweight 3D vector library. Usage On your C++ code include the file. #include <vector.h> Then, declare your vector and ini

Carlos del Valle 6 Jan 18, 2022
C++ library for multi-physics simulation

Project CHRONO Project Chrono represents a community effort aimed at producing a physics-based modelling and simulation infrastructure based on a plat

null 1.4k May 13, 2022
C++ library for multi-physics simulation

Project Chrono represents a community effort aimed at producing a physics-based modelling and simulation infrastructure based on a platform-independent, open-source design.

null 1.4k May 11, 2022
Open source C++ physics engine library in 3D

ReactPhysics3D ReactPhysics3D is an open source C++ physics engine library that can be used in 3D simulations and games. www.reactphysics3d.com ?? Fea

Daniel Chappuis 991 May 9, 2022
PendulumSynth is an on-going and open-source project, running on Arduino platform with the goal of mixing real-world physics into music composition and musical performance.

PendulumSynth PendulumSynth is an on-going and open-source project, running on Arduino platform with the goal of mixing real-world physics into music

Mohammadreza Anvari 3 Mar 27, 2022
CGIF, A fast and lightweight GIF encoder that can create GIF animations and images

CGIF, a GIF encoder written in C A fast and lightweight GIF encoder that can create GIF animations and images. Summary of the main features: user-defi

Daniel Löbl 57 May 17, 2022
This the contains the test examples and validator tool for the ISPD2021 Wafer-Scale Physics Modeling contest.

This readme documents information regarding the validator/scorer which will be used for the 2021 ISPD Contest problem: Wafer-Scale Physics Modelling

Cerebras 15 Jan 6, 2022
graphics and computational physics framework

atto Graphics and computational physics research framework: aligned memory allocation, string manipulation, file IO, etc. 2-, 3- and 4-dimensional vec

Carlos Correia 1 Oct 25, 2021