Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/bullet/BulletSoftBody/btSoftRigidDynamicsWorld.cpp @ 2305

Last change on this file since 2305 was 2192, checked in by rgrieder, 16 years ago

Reverted all changes of attempt to update physics branch.

  • Property svn:eol-style set to native
File size: 3.7 KB
Line 
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16
17#include "btSoftRigidDynamicsWorld.h"
18#include "LinearMath/btQuickprof.h"
19
20//softbody & helpers
21#include "btSoftBody.h"
22#include "btSoftBodyHelpers.h"
23
24
25
26
27
28btSoftRigidDynamicsWorld::btSoftRigidDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration)
29:btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration)
30{
31m_drawFlags                     =       fDrawFlags::Std;
32m_drawNodeTree          =       true;
33m_drawFaceTree          =       false;
34m_drawClusterTree       =       false;
35m_sbi.m_broadphase = pairCache;
36m_sbi.m_dispatcher = dispatcher;
37m_sbi.m_sparsesdf.Initialize();
38m_sbi.m_sparsesdf.Reset();
39
40}
41               
42btSoftRigidDynamicsWorld::~btSoftRigidDynamicsWorld()
43{
44
45}
46
47void    btSoftRigidDynamicsWorld::predictUnconstraintMotion(btScalar timeStep)
48{
49        btDiscreteDynamicsWorld::predictUnconstraintMotion( timeStep);
50
51        for ( int i=0;i<m_softBodies.size();++i)
52        {
53                btSoftBody*     psb= m_softBodies[i];
54
55                psb->predictMotion(timeStep);           
56        }
57}
58               
59void    btSoftRigidDynamicsWorld::internalSingleStepSimulation( btScalar timeStep)
60{
61        btDiscreteDynamicsWorld::internalSingleStepSimulation( timeStep );
62
63        ///solve soft bodies constraints
64        solveSoftBodiesConstraints();
65
66        ///update soft bodies
67        updateSoftBodies();
68
69}
70
71void    btSoftRigidDynamicsWorld::updateSoftBodies()
72{
73        BT_PROFILE("updateSoftBodies");
74       
75        for ( int i=0;i<m_softBodies.size();i++)
76        {
77                btSoftBody*     psb=(btSoftBody*)m_softBodies[i];
78                psb->integrateMotion(); 
79        }
80}
81
82void    btSoftRigidDynamicsWorld::solveSoftBodiesConstraints()
83{
84        BT_PROFILE("solveSoftConstraints");
85       
86        if(m_softBodies.size())
87                {
88                btSoftBody::solveClusters(m_softBodies);
89                }
90       
91        for(int i=0;i<m_softBodies.size();++i)
92        {
93                btSoftBody*     psb=(btSoftBody*)m_softBodies[i];
94                psb->solveConstraints();
95        }       
96}
97
98void    btSoftRigidDynamicsWorld::addSoftBody(btSoftBody* body)
99{
100        m_softBodies.push_back(body);
101
102        btCollisionWorld::addCollisionObject(body,
103                                        btBroadphaseProxy::DefaultFilter,
104                                        btBroadphaseProxy::AllFilter);
105
106}
107
108void    btSoftRigidDynamicsWorld::removeSoftBody(btSoftBody* body)
109{
110        m_softBodies.remove(body);
111
112        btCollisionWorld::removeCollisionObject(body);
113}
114
115void    btSoftRigidDynamicsWorld::debugDrawWorld()
116{
117        btDiscreteDynamicsWorld::debugDrawWorld();
118
119        if (getDebugDrawer())
120        {
121                int i;
122                for (  i=0;i<this->m_softBodies.size();i++)
123                {
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))
128                        {
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);
132                        }
133                }               
134        }       
135}
Note: See TracBrowser for help on using the repository browser.