My favorites | Sign in
Project Logo
                
Search
for
Updated Mar 01, 2009 by memosan
Labels: Featured
ofxMSAPhysics  

ofxMSAPhysics v2.0a requires the latest version of openFrameworks as of writing (rev240 on the OF SVN) and is aimed at OF 006 when it is released. It also requires my ofxObjCPointer v1.1+ addon which makes memory management easier. It does not require ofxVectorMath anymore as the required functionality is now in the new OF core.

Using the library is quite simple, and a lot of the method names are the same (or similar) to the Traer physics library for Processing.org. So if you are familiar with the traer library using ofxMSAPhysics should be very straightforward (though the behaviour may - and probably will be - a bit different as the underlying code is completely different - in fact you definitely will need to tweak the numbers).

More docs coming soon, in the meantime check the testApp.cpp in the downloads.

class ofxMSAPhysics : public ofxMSAParticleUpdatable {
	
public:	
	friend class ofxMSAParticle;
	
	bool				verbose;
	
	ofxMSAPhysics();
	~ofxMSAPhysics();
	
	ofxMSAParticle*		makeParticle(float x, float y, float z, float m = 1.0f, float d = 1.0f);
	ofxMSASpring*		makeSpring(ofxMSAParticle *a, ofxMSAParticle *b, float _strength, float _restLength);
	ofxMSAAttraction*	makeAttraction(ofxMSAParticle *a, ofxMSAParticle *b, float _strength, float _minimumDistance = 0);
	ofxMSACollision*	makeCollision(ofxMSAParticle *a, ofxMSAParticle *b);
	
	// this method retains the particle, so you should release() it after adding (obj-c style)
	ofxMSAParticle*		addParticle(ofxMSAParticle *p);
	
	// this method retains the constraint, so you should release it after adding (obj-c style)
	ofxMSAConstraint*	addConstraint(ofxMSAConstraint *c);
	
	ofxMSAParticle*		getParticle(uint i);		// get i'th particle
	ofxMSAConstraint*	getConstraint(uint i);		// get i'th custom constraint
	ofxMSASpring*		getSpring(uint i);		// get i'th spring
	ofxMSAAttraction*	getAttraction(uint i);		// get i'th attraction
	ofxMSACollision*	getCollision(uint i);		// get i'th collision
	
	uint				numberOfParticles();
	uint				numberOfConstraints();		// custom constraints
	uint				numberOfSprings();		// only springs
	uint				numberOfAttractions();		// only attractions
	uint				numberOfCollisions();		// only collisions
	
	ofxMSAPhysics*		enableCollision();
	ofxMSAPhysics*		disableCollision();
	bool				isCollisionEnabled();
	
	ofxMSAPhysics*		addToCollision(ofxMSAParticle* p);
	ofxMSAPhysics*		removeFromCollision(ofxMSAParticle* p);
	
	ofxMSAPhysics*		setDrag(float drag = 0.99);					// set the drag. 1: no drag at all, 0.9: quite a lot of drag, 0: particles can't even move
	ofxMSAPhysics*		setGravity(float gy);							// set gravity 
	ofxMSAPhysics*		setGravity(float gx = 0, float gy = 0, float gz = 0);		// default values
	ofxMSAPhysics*		setGravity(ofPoint &g);
	ofPoint&			getGravity();
	ofxMSAPhysics*		setTimeStep(float timeStep);
	ofxMSAPhysics*		setNumIterations(float numIterations = 20);	// default value
	
	ofxMSAPhysics*		setWorldMin(ofPoint worldMin);
	ofxMSAPhysics*		setWorldMax(ofPoint worldMax);
	ofxMSAPhysics*		setWorldSize(ofPoint worldMin, ofPoint worldMax);
	ofxMSAPhysics*		clearWorldSize();
	
	// preallocate buffers if you know how big they need to be (they grow automatically if need be)
	ofxMSAPhysics*		setParticleCount(uint i);
	ofxMSAPhysics*		setConstraintCount(uint i);
	ofxMSAPhysics*		setSpringCount(uint i);
	ofxMSAPhysics*		setAttractionCount(uint i);
	ofxMSAPhysics*		setCollisionCount(uint i);
}

Sign in to add a comment
Hosted by Google Code