diff --git a/src/shapes/ofxBulletSoftBody.cpp b/src/shapes/ofxBulletSoftBody.cpp index 54c4b51..c38d17a 100644 --- a/src/shapes/ofxBulletSoftBody.cpp +++ b/src/shapes/ofxBulletSoftBody.cpp @@ -72,6 +72,16 @@ float ofxBulletSoftBody::getMass() const { return _softBody->getTotalMass(); } +//-------------------------------------------------------------- +ofVec3f ofxBulletSoftBody::getPosition() const { + ofVec3f avgpos; + for ( int i = 0; i < getNumNodes(); i++ ) { + avgpos += getNodePos(i); + } + avgpos /= (float)getNumNodes(); + return avgpos; +} + //-------------------------------------------------------------- size_t ofxBulletSoftBody::getNumNodes() const { return _softBody->m_nodes.size(); diff --git a/src/shapes/ofxBulletSoftBody.h b/src/shapes/ofxBulletSoftBody.h index 4764a48..b5651d5 100644 --- a/src/shapes/ofxBulletSoftBody.h +++ b/src/shapes/ofxBulletSoftBody.h @@ -29,6 +29,8 @@ class ofxBulletSoftBody : public ofxBulletBaseShape { int getType(); float getMass() const; + // returns an average position of all of the nodes // + virtual ofVec3f getPosition() const; size_t getNumNodes() const; ofVec3f getNodePos(int idx) const; diff --git a/src/shapes/ofxBulletSoftTriMesh.cpp b/src/shapes/ofxBulletSoftTriMesh.cpp index 2247de8..5058ea9 100644 --- a/src/shapes/ofxBulletSoftTriMesh.cpp +++ b/src/shapes/ofxBulletSoftTriMesh.cpp @@ -88,15 +88,6 @@ void ofxBulletSoftTriMesh::draw() { getMesh().draw(); } -//-------------------------------------------------------------- -ofVec3f ofxBulletSoftTriMesh::getPosition() const { - // approximation // - btVector3& bounds = _softBody->m_bounds[0]; - btVector3& bounds2 = _softBody->m_bounds[1]; - ofVec3f tpos( (bounds.x()+bounds2.x())/2, (bounds.y()+bounds2.y())/2, (bounds.z()+bounds2.z())/2 ); - return tpos; -} - //-------------------------------------------------------------- void ofxBulletSoftTriMesh::updateMesh( ofMesh& aMesh ) { diff --git a/src/shapes/ofxBulletSoftTriMesh.h b/src/shapes/ofxBulletSoftTriMesh.h index 2d782db..d7dc6a1 100644 --- a/src/shapes/ofxBulletSoftTriMesh.h +++ b/src/shapes/ofxBulletSoftTriMesh.h @@ -19,7 +19,6 @@ class ofxBulletSoftTriMesh : public ofxBulletSoftBody { void draw(); - ofVec3f getPosition() const; void updateMesh( ofMesh& aMesh ); protected: