Chipmunk is a great physics engine for use with openFrameworks because it isn’t weighed down with any graphics support. The documentation is pretty sparse, but I am starting on a little wrapper working and incorporated the ofxDelaunay addon by plong0. There are still a lot of things missing, like springs and joints and stuff. But I wanted to post this in case anyone else is interested in the code. Here is what the wrapper class, ofxCPBody looks like.
#ifndef _OFX_CP_BODY
#define _OFX_CP_BODY
#include "chipmunk.h"
#include "ofxDelaunay.h"
#include "ofxVectorMath.h"
class ofxCpBody {
public:
cpBody *body;
vector<cpShape*> shapes;
cpSpace *space; // Holds our Space object
ofxCpBody(cpSpace* _space, bool inSpace=true, double mass=INFINITY, double inertia=INFINITY);
~ofxCpBody();
void removeFromSpace();
int addCircle(int radius, int xoffset, int yoffset, int collision_type=1, bool isStatic=false, double friction=0.5, double elacticity=0.5);
int addPoly(int nverts, ofPoint* points, int xoffset, int yoffset, int collision_type=1, bool isStatic=false, double friction=0.5, double elacticity=0.5);
int* addTriangulatedPoly(vector<ofPoint> points, int xoffset, int yoffset, int collision_type=1, bool isStatic=false, double friction=0.5, double elacticity=0.5);
double flipy(double y);
int addShape(cpShape* shape);
void setPosition(double x, double y);
ofPoint getPosition();
int getx();
int gety();
float getRotation();
//void cpBodyApplyImpulse(cpBody *body, cpVect j, cpVect r)
void applyImpulse(ofxVec2f j, ofxVec2f r);
//void cpBodyApplyForce(cpBody *body, cpVect f, cpVect r)
void applyForce(ofxVec2f f, ofxVec2f r);
virtual void draw();
};
#endif
One Comment
Hey there. This looks like a nice beginning to a chipmunk set of wrapper classes for oF. I was just starting one of my own, and was curious if you have the implementation of the above somewhere to take a look at. I’d love to build off what you already have, if possible, rather than recreate the wheel.
Either way, looks like you’re well on your way to a nice library!
One Trackback
[...] « Week 145 Chipmunk and openFrameworks » [...]