Chipmunk and openFrameworks

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
Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • MySpace
  • Netvibes
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
This entry was posted in Howtus. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Jeff
    Posted March 29, 2010 at 5:16 pm | Permalink

    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

  1. By Week 147 on February 19, 2010 at 7:45 pm

    [...] « Week 145 Chipmunk and openFrameworks » [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>