BGE real-time soft bodies, step 2 / 3: create a btSoftBody. Next step is hooking...
[blender-staging.git] / source / gameengine / Physics / Bullet / CcdPhysicsEnvironment.cpp
index 68b3df1695c13e3c530c392f37641959a01d1725..96aa9ad164e9b103e914469bfe61b9c05e853d71 100644 (file)
@@ -24,6 +24,7 @@ subject to the following restrictions:
 #include "LinearMath/btIDebugDraw.h"
 #include "BulletCollision/CollisionDispatch/btSimulationIslandManager.h"
 #include "BulletSoftBody/btSoftRigidDynamicsWorld.h"
+#include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h"
 
 //profiling/timings
 #include "LinearMath/btQuickprof.h"
@@ -331,7 +332,9 @@ m_filterCallback(NULL)
        {
                m_triggerCallbacks[i] = 0;
        }
-       m_collisionConfiguration = new btDefaultCollisionConfiguration();
+
+//     m_collisionConfiguration = new btDefaultCollisionConfiguration();
+       m_collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();
 
        if (!dispatcher)
        {
@@ -339,6 +342,8 @@ m_filterCallback(NULL)
                m_ownDispatcher = dispatcher;
        }
 
+       //m_broadphase = new btAxisSweep3(btVector3(-1000,-1000,-1000),btVector3(1000,1000,1000));
+       //m_broadphase = new btSimpleBroadphase();
        m_broadphase = new btDbvtBroadphase();
 
        m_filterCallback = new CcdOverlapFilterCallBack(this);
@@ -375,9 +380,8 @@ void        CcdPhysicsEnvironment::addCcdPhysicsController(CcdPhysicsController* ctrl)
        {
                if (ctrl->GetSoftBody())
                {
-                       //not yet
-                       btAssert(0);
-                       //m_dynamicsWorld->addSo
+                       btSoftBody* softBody = ctrl->GetSoftBody();
+                       m_dynamicsWorld->addSoftBody(softBody);
                } else
                {
                        if (obj->getCollisionShape())
@@ -460,8 +464,7 @@ void        CcdPhysicsEnvironment::removeCcdPhysicsController(CcdPhysicsController* ctr
                //if a softbody
                if (ctrl->GetSoftBody())
                {
-                       //not yet
-                       btAssert(0);
+                       m_dynamicsWorld->removeSoftBody(ctrl->GetSoftBody());
                } else
                {
                        m_dynamicsWorld->removeCollisionObject(ctrl->GetCollisionObject());
@@ -553,7 +556,8 @@ bool        CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep)
        float subStep = timeStep / float(m_numTimeSubSteps);
        for (i=0;i<m_numTimeSubSteps;i++)
        {
-               m_dynamicsWorld->stepSimulation(subStep,0);//perform always a full simulation step
+//                     m_dynamicsWorld->stepSimulation(subStep,20,1./240.);//perform always a full simulation step
+                       m_dynamicsWorld->stepSimulation(subStep,0);//perform always a full simulation step
        }
 
        for (it=m_controllers.begin(); it!=m_controllers.end(); it++)
@@ -670,7 +674,13 @@ void               CcdPhysicsEnvironment::setSolverType(int solverType)
 
 
 
-
+void           CcdPhysicsEnvironment::getGravity(PHY__Vector3& grav)
+{
+               const btVector3& gravity = m_dynamicsWorld->getGravity();
+               grav[0] = gravity.getX();
+               grav[1] = gravity.getY();
+               grav[2] = gravity.getZ();
+}
 
 
 void           CcdPhysicsEnvironment::setGravity(float x,float y,float z)
@@ -955,6 +965,13 @@ btBroadphaseInterface*     CcdPhysicsEnvironment::getBroadphase()
        return m_dynamicsWorld->getBroadphase(); 
 }
 
+btDispatcher*  CcdPhysicsEnvironment::getDispatcher()
+{ 
+       return m_dynamicsWorld->getDispatcher();
+}
+
+
+