Skip to content

Commit

Permalink
helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
NickHardeman committed Sep 2, 2015
1 parent 17a7dc0 commit 0836171
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/shapes/ofxBulletSoftBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/shapes/ofxBulletSoftBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions src/shapes/ofxBulletSoftTriMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {

Expand Down
1 change: 0 additions & 1 deletion src/shapes/ofxBulletSoftTriMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class ofxBulletSoftTriMesh : public ofxBulletSoftBody {

void draw();

ofVec3f getPosition() const;
void updateMesh( ofMesh& aMesh );

protected:
Expand Down

0 comments on commit 0836171

Please sign in to comment.