Created
October 1, 2017 17:07
-
-
Save AnishN/860776e75f58dc8595f7955198af42a8 to your computer and use it in GitHub Desktop.
Partial cython wrapper for Chipmunk 2D physics library (alternative to cymunk)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from libc.stdint cimport uintptr_t, uint32_t | |
#Basic/Core Chipmunk Types | |
cdef extern from "chipmunk/chipmunk.h": | |
ctypedef double cpFloat | |
ctypedef struct cpVect: | |
cpFloat x,y | |
cpVect cpv(cpFloat x, cpFloat y) | |
#Body | |
cdef extern from "chipmunk/chipmunk.h": | |
ctypedef enum cpBodyType: | |
CP_BODY_TYPE_DYNAMIC | |
CP_BODY_TYPE_KINEMATIC | |
CP_BODY_TYPE_STATIC | |
ctypedef struct cpBody: | |
pass | |
cpBody * cpBodyNew(cpFloat mass, cpFloat moment) | |
cpBody * cpBodyNewKinematic() | |
cpBody * cpBodyNewStatic() | |
void cpBodyFree(cpBody *body) | |
cpFloat cpBodyGetMass(cpBody *body) | |
void cpBodySetMass(cpBody *body, cpFloat m) | |
cpFloat cpBodyGetMoment(cpBody *body) | |
void cpBodySetMoment(cpBody *body, cpFloat m) | |
cpVect cpBodyGetPosition(cpBody *body) | |
void cpBodySetPosition(cpBody *body, cpVect pos) | |
cpVect cpBodyGetCenterOfGravity(cpBody *body) | |
void cpBodySetCenterOfGravity(cpBody *body, cpVect cog) | |
cpVect cpBodyGetVelocity(cpBody *body) | |
void cpBodySetVelocity(cpBody *body, cpVect velocity) | |
cpVect cpBodyGetForce(cpBody *body) | |
void cpBodySetForce(cpBody *body, cpVect force) | |
cpFloat cpBodyGetAngle(cpBody *body) | |
void cpBodySetAngle(cpBody *body, cpFloat a) | |
cpFloat cpBodyGetAngularVelocity(cpBody *body) | |
void cpBodySetAngularVelocity(cpBody *body, cpFloat angularVelocity) | |
cpFloat cpBodyGetTorque(cpBody *body) | |
void cpBodySetTorque(cpBody *body, cpFloat torque) | |
cpVect cpBodyGetRotation(cpBody *body) | |
#Space | |
cdef extern from "chipmunk/chipmunk.h": | |
ctypedef struct cpSpace: | |
pass | |
cpSpace * cpSpaceNew() | |
void cpSpaceFree(cpSpace *space) | |
cpVect cpSpaceGetGravity(cpSpace *space) | |
void cpSpaceSetGravity(cpSpace *space, cpVect value) | |
cpShape * cpSpaceAddShape(cpSpace *space, cpShape *shape) | |
cpBody * cpSpaceAddBody(cpSpace *space, cpBody *body) | |
void cpSpaceRemoveShape(cpSpace *space, cpShape *shape) | |
void cpSpaceRemoveBody(cpSpace *space, cpBody *body) | |
void cpSpaceStep(cpSpace *space, cpFloat dt) | |
#Shape | |
cdef extern from "chipmunk/chipmunk.h": | |
ctypedef struct cpShape: | |
pass | |
#Helper functions | |
cpFloat cpMomentForCircle(cpFloat m, cpFloat r1, cpFloat r2, cpVect offset) | |
cpFloat cpMomentForSegment(cpFloat m, cpVect a, cpVect b) | |
cpFloat cpMomentForPoly(cpFloat m, int numVerts, cpVect *verts, cpVect offset) | |
cpFloat cpMomentForBox(cpFloat m, cpFloat width, cpFloat height) | |
cpShape * cpSegmentShapeNew(cpBody *body, cpVect a, cpVect b, cpFloat radius) | |
cpShape * cpCircleShapeNew (cpBody *body, cpFloat radius, cpVect offset) | |
void cpShapeFree(cpShape *shape) | |
cpFloat cpShapeGetFriction(cpShape *shape) | |
void cpShapeSetFriction(cpShape *shape, cpFloat friction) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment