2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
17 #include "btSoftRigidDynamicsWorld.h"
18 #include "LinearMath/btQuickprof.h"
21 #include "btSoftBody.h"
22 #include "btSoftBodyHelpers.h"
28 btSoftRigidDynamicsWorld::btSoftRigidDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration)
29 :btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration)
31 m_drawFlags = fDrawFlags::Std;
32 m_drawNodeTree = true;
33 m_drawFaceTree = false;
34 m_drawClusterTree = false;
35 m_sbi.m_broadphase = pairCache;
36 m_sbi.m_dispatcher = dispatcher;
37 m_sbi.m_sparsesdf.Initialize();
38 m_sbi.m_sparsesdf.Reset();
42 btSoftRigidDynamicsWorld::~btSoftRigidDynamicsWorld()
47 void btSoftRigidDynamicsWorld::predictUnconstraintMotion(btScalar timeStep)
49 btDiscreteDynamicsWorld::predictUnconstraintMotion( timeStep);
51 for ( int i=0;i<m_softBodies.size();++i)
53 btSoftBody* psb= m_softBodies[i];
55 psb->predictMotion(timeStep);
59 void btSoftRigidDynamicsWorld::internalSingleStepSimulation( btScalar timeStep)
61 btDiscreteDynamicsWorld::internalSingleStepSimulation( timeStep );
63 ///solve soft bodies constraints
64 solveSoftBodiesConstraints();
71 void btSoftRigidDynamicsWorld::updateSoftBodies()
73 BT_PROFILE("updateSoftBodies");
75 for ( int i=0;i<m_softBodies.size();i++)
77 btSoftBody* psb=(btSoftBody*)m_softBodies[i];
78 psb->integrateMotion();
82 void btSoftRigidDynamicsWorld::solveSoftBodiesConstraints()
84 BT_PROFILE("solveSoftConstraints");
86 if(m_softBodies.size())
88 btSoftBody::solveClusters(m_softBodies);
91 for(int i=0;i<m_softBodies.size();++i)
93 btSoftBody* psb=(btSoftBody*)m_softBodies[i];
94 psb->solveConstraints();
98 void btSoftRigidDynamicsWorld::addSoftBody(btSoftBody* body)
100 m_softBodies.push_back(body);
102 btCollisionWorld::addCollisionObject(body,
103 btBroadphaseProxy::DefaultFilter,
104 btBroadphaseProxy::AllFilter);
108 void btSoftRigidDynamicsWorld::removeSoftBody(btSoftBody* body)
110 m_softBodies.remove(body);
112 btCollisionWorld::removeCollisionObject(body);
115 void btSoftRigidDynamicsWorld::debugDrawWorld()
117 btDiscreteDynamicsWorld::debugDrawWorld();
119 if (getDebugDrawer())
122 for ( i=0;i<this->m_softBodies.size();i++)
124 btSoftBody* psb=(btSoftBody*)this->m_softBodies[i];
125 btSoftBodyHelpers::DrawFrame(psb,m_debugDrawer);
126 btSoftBodyHelpers::Draw(psb,m_debugDrawer,m_drawFlags);
127 if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
129 if(m_drawNodeTree) btSoftBodyHelpers::DrawNodeTree(psb,m_debugDrawer);
130 if(m_drawFaceTree) btSoftBodyHelpers::DrawFaceTree(psb,m_debugDrawer);
131 if(m_drawClusterTree) btSoftBodyHelpers::DrawClusterTree(psb,m_debugDrawer);