Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Mar 16, 2017 4:18 am 
Offline

Joined: Thu Mar 14, 2013 9:56 pm
Posts: 6
Hi all,

The physics works very well. I'm just getting this error on valgrind when the rigidbody comes closer to the softbody.
The same error occours using CreatePatch instead CreatePatchUV :'(

Here is my code:

Initializing physics:

Code:
collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();

dispatcher = 0;

dispatcher = new btCollisionDispatcher(collisionConfiguration);

btVector3 worldAabbMin(-100,-100,-100);
btVector3 worldAabbMax(100,100,100);

broadPhase = new btAxisSweep3(worldAabbMin,worldAabbMax,16384); //32766);

softBodyWorldInfo.m_dispatcher = dispatcher;
softBodyWorldInfo.m_broadphase = broadPhase;
softBodyWorldInfo.m_gravity.setValue(0,-10,0);

solver = new btSequentialImpulseConstraintSolver();

dynamicsWorld = new btSoftRigidDynamicsWorld(dispatcher,broadPhase,solver,collisionConfiguration);
dynamicsWorld->getDispatchInfo().m_enableSPU = true;

softBodyWorldInfo.m_sparsesdf.Initialize();


Creating the SoftBody:

Code:
const btScalar   x=8.f;
const btScalar   y1=3.8f;
const btScalar   y2=2.f;
const btScalar z=0.f;

netBody = btSoftBodyHelpers::CreatePatchUV(Physics::getInstance()->getSoftBodyWorldInfo(),
btVector3(-x,y1,z),
btVector3(x,y1,z),
btVector3(-x,y2,z),
btVector3(x,y2,z),
                 resx,
                 resy,
                 1+2+4+8+16,
                 false,
                 texCoords);

netBody->getCollisionShape()->setMargin(0.3f);

btSoftBody::Material* pm=netBody->appendMaterial();
pm->m_kLST = 1.f;
pm->m_kAST = 1.f;
pm->m_kVST = 1.f;
pm->m_flags      -=   btSoftBody::fMaterial::DebugDraw;

netBody->generateBendingConstraints(2,pm);

netBody->m_cfg.piterations = 10;
netBody->m_cfg.kCHR = 1;
netBody->m_cfg.kSRHR_CL = 1;

netBody->setTotalMass(1.0f);

Physics::getInstance()->addSoftBody(netBody, collisionCfg, collisionSelfNet);


Stepping:


Code:
            dynamicsWorld->stepSimulation(timeDiff);
            softBodyWorldInfo.m_sparsesdf.GarbageCollect();


Valgrind Error:

Code:
==5681== Use of uninitialised value of size 8
==5681==    at 0x49984B: btSparseSdf<3>::Evaluate(btVector3 const&, btCollisionShape const*, btVector3&, float) [clone .constprop.473]
==5681==    by 0x49FC43: btSoftColliders::CollideSDF_RS::DoNode(btSoftBody::Node&) const
==5681==    by 0x49D033: btDbvt::collideTV(btDbvtNode const*, btDbvtAabbMm const&, btDbvt::ICollide&) const
==5681==    by 0x48B832: btSoftBody::defaultCollisionHandler(btCollisionObjectWrapper const*)
==5681==    by 0x4EBE98: btCollisionDispatcher::defaultNearCallback(btBroadphasePair&, btCollisionDispatcher&, btDispatcherInfo const&)
==5681==    by 0x4EC277: btCollisionPairCallback::processOverlap(btBroadphasePair&)
==5681==    by 0x4E9402: btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback*, btDispatcher*)
==5681==    by 0x4EB88B: btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache*, btDispatcherInfo const&, btDispatcher*)
==5681==    by 0x4ED10F: btCollisionWorld::performDiscreteCollisionDetection()
==5681==    by 0x4BD129: btDiscreteDynamicsWorld::internalSingleStepSimulation(float)
==5681==    by 0x4A8B84: btSoftRigidDynamicsWorld::internalSingleStepSimulation(float)
==5681==    by 0x4BA351: btDiscreteDynamicsWorld::stepSimulation(float, int, float)
==5681==  Uninitialised value was created by a stack allocation
==5681==    at 0x499520: btSparseSdf<3>::Evaluate(btVector3 const&, btCollisionShape const*, btVector3&, float) [clone .constprop.473]
==5681==
==5681== Conditional jump or move depends on uninitialised value(s)
==5681==    at 0x4997B0: btSparseSdf<3>::Evaluate(btVector3 const&, btCollisionShape const*, btVector3&, float) [clone .constprop.473]
==5681==    by 0x49FC43: btSoftColliders::CollideSDF_RS::DoNode(btSoftBody::Node&) const
==5681==    by 0x49D033: btDbvt::collideTV(btDbvtNode const*, btDbvtAabbMm const&, btDbvt::ICollide&) const
==5681==    by 0x48B832: btSoftBody::defaultCollisionHandler(btCollisionObjectWrapper const*)
==5681==    by 0x4EBE98: btCollisionDispatcher::defaultNearCallback(btBroadphasePair&, btCollisionDispatcher&, btDispatcherInfo const&)
==5681==    by 0x4EC277: btCollisionPairCallback::processOverlap(btBroadphasePair&)
==5681==    by 0x4E9402: btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback*, btDispatcher*)
==5681==    by 0x4EB88B: btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache*, btDispatcherInfo const&, btDispatcher*)
==5681==    by 0x4ED10F: btCollisionWorld::performDiscreteCollisionDetection()
==5681==    by 0x4BD129: btDiscreteDynamicsWorld::internalSingleStepSimulation(float)
==5681==    by 0x4A8B84: btSoftRigidDynamicsWorld::internalSingleStepSimulation(float)
==5681==    by 0x4BA351: btDiscreteDynamicsWorld::stepSimulation(float, int, float)
==5681==  Uninitialised value was created by a stack allocation
==5681==    at 0x499520: btSparseSdf<3>::Evaluate(btVector3 const&, btCollisionShape const*, btVector3&, float) [clone .constprop.473]


I'm still working on it. Based on "Cloth" Sample.
Am I forgetting something? I'm using bullet-2.81-rev2613
Thanks!


Top
 Profile  
 
PostPosted: Fri Mar 17, 2017 8:08 am 
Offline

Joined: Thu Mar 14, 2013 9:56 pm
Posts: 6
I'm sorry, here is the error with debug version of bullet:

Code:
==22262== Conditional jump or move depends on uninitialised value(s)
==22262==    at 0x4524C5: btAlignedObjectArray<btSparseSdf<3>::Cell*>::operator[](int) (btAlignedObjectArray.h:177)
==22262==    by 0x49EE74: btSparseSdf<3>::Evaluate(btVector3 const&, btCollisionShape const*, btVector3&, float) (btSparseSDF.h:165)
==22262==    by 0x48AC3F: btSoftBody::checkContact(btCollisionObjectWrapper const*, btVector3 const&, float, btSoftBody::sCti&) const (btSoftBody.cpp:2243)
==22262==    by 0x499F5B: btSoftColliders::CollideSDF_RS::DoNode(btSoftBody::Node&) const (btSoftBodyInternals.h:822)
==22262==    by 0x499E2C: btSoftColliders::CollideSDF_RS::Process(btDbvtNode const*) (btSoftBodyInternals.h:814)
==22262==    by 0x496AD3: btDbvt::collideTV(btDbvtNode const*, btDbvtAabbMm const&, btDbvt::ICollide&) const (btDbvt.h:946)
==22262==    by 0x490CEB: btSoftBody::defaultCollisionHandler(btCollisionObjectWrapper const*) (btSoftBody.cpp:3163)
==22262==    by 0x4AF834: btDefaultSoftBodySolver::processCollision(btSoftBody*, btCollisionObjectWrapper const*) (btDefaultSoftBodySolver.cpp:135)
==22262==    by 0x4AD183: btSoftRigidCollisionAlgorithm::processCollision(btCollisionObjectWrapper const*, btCollisionObjectWrapper const*, btDispatcherInfo const&, btManifoldResult*) (btSoftRigidCollisionAlgorithm.cpp:68)
==22262==    by 0x4E5C17: btCollisionDispatcher::defaultNearCallback(btBroadphasePair&, btCollisionDispatcher&, btDispatcherInfo const&) (btCollisionDispatcher.cpp:279)
==22262==    by 0x4E6467: btCollisionPairCallback::processOverlap(btBroadphasePair&) (btCollisionDispatcher.cpp:230)
==22262==    by 0x4E3CB5: btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback*, btDispatcher*) (btOverlappingPairCache.cpp:387)
==22262==  Uninitialised value was created by a stack allocation
==22262==    at 0x4A1FEB: btSparseSdf<3>::Hash(int, int, int, btCollisionShape const*) (btSparseSDF.h:285)
==22262==
==22262== Conditional jump or move depends on uninitialised value(s)
==22262==    at 0x4524EF: btAlignedObjectArray<btSparseSdf<3>::Cell*>::operator[](int) (btAlignedObjectArray.h:178)
==22262==    by 0x49EE74: btSparseSdf<3>::Evaluate(btVector3 const&, btCollisionShape const*, btVector3&, float) (btSparseSDF.h:165)
==22262==    by 0x48AC3F: btSoftBody::checkContact(btCollisionObjectWrapper const*, btVector3 const&, float, btSoftBody::sCti&) const (btSoftBody.cpp:2243)
==22262==    by 0x499F5B: btSoftColliders::CollideSDF_RS::DoNode(btSoftBody::Node&) const (btSoftBodyInternals.h:822)
==22262==    by 0x499E2C: btSoftColliders::CollideSDF_RS::Process(btDbvtNode const*) (btSoftBodyInternals.h:814)
==22262==    by 0x496AD3: btDbvt::collideTV(btDbvtNode const*, btDbvtAabbMm const&, btDbvt::ICollide&) const (btDbvt.h:946)
==22262==    by 0x490CEB: btSoftBody::defaultCollisionHandler(btCollisionObjectWrapper const*) (btSoftBody.cpp:3163)
==22262==    by 0x4AF834: btDefaultSoftBodySolver::processCollision(btSoftBody*, btCollisionObjectWrapper const*) (btDefaultSoftBodySolver.cpp:135)
==22262==    by 0x4AD183: btSoftRigidCollisionAlgorithm::processCollision(btCollisionObjectWrapper const*, btCollisionObjectWrapper const*, btDispatcherInfo const&, btManifoldResult*) (btSoftRigidCollisionAlgorithm.cpp:68)
==22262==    by 0x4E5C17: btCollisionDispatcher::defaultNearCallback(btBroadphasePair&, btCollisionDispatcher&, btDispatcherInfo const&) (btCollisionDispatcher.cpp:279)
==22262==    by 0x4E6467: btCollisionPairCallback::processOverlap(btBroadphasePair&) (btCollisionDispatcher.cpp:230)
==22262==    by 0x4E3CB5: btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback*, btDispatcher*) (btOverlappingPairCache.cpp:387)
==22262==  Uninitialised value was created by a stack allocation
==22262==    at 0x4A1FEB: btSparseSdf<3>::Hash(int, int, int, btCollisionShape const*) (btSparseSDF.h:285)
==22262==
==22262== Use of uninitialised value of size 8
==22262==    at 0x49EE83: btSparseSdf<3>::Evaluate(btVector3 const&, btCollisionShape const*, btVector3&, float) (btSparseSDF.h:166)
==22262==    by 0x48AC3F: btSoftBody::checkContact(btCollisionObjectWrapper const*, btVector3 const&, float, btSoftBody::sCti&) const (btSoftBody.cpp:2243)
==22262==    by 0x499F5B: btSoftColliders::CollideSDF_RS::DoNode(btSoftBody::Node&) const (btSoftBodyInternals.h:822)
==22262==    by 0x499E2C: btSoftColliders::CollideSDF_RS::Process(btDbvtNode const*) (btSoftBodyInternals.h:814)
==22262==    by 0x496AD3: btDbvt::collideTV(btDbvtNode const*, btDbvtAabbMm const&, btDbvt::ICollide&) const (btDbvt.h:946)
==22262==    by 0x490CEB: btSoftBody::defaultCollisionHandler(btCollisionObjectWrapper const*) (btSoftBody.cpp:3163)
==22262==    by 0x4AF834: btDefaultSoftBodySolver::processCollision(btSoftBody*, btCollisionObjectWrapper const*) (btDefaultSoftBodySolver.cpp:135)
==22262==    by 0x4AD183: btSoftRigidCollisionAlgorithm::processCollision(btCollisionObjectWrapper const*, btCollisionObjectWrapper const*, btDispatcherInfo const&, btManifoldResult*) (btSoftRigidCollisionAlgorithm.cpp:68)
==22262==    by 0x4E5C17: btCollisionDispatcher::defaultNearCallback(btBroadphasePair&, btCollisionDispatcher&, btDispatcherInfo const&) (btCollisionDispatcher.cpp:279)
==22262==    by 0x4E6467: btCollisionPairCallback::processOverlap(btBroadphasePair&) (btCollisionDispatcher.cpp:230)
==22262==    by 0x4E3CB5: btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback*, btDispatcher*) (btOverlappingPairCache.cpp:387)
==22262==    by 0x4E59FD: btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache*, btDispatcherInfo const&, btDispatcher*) (btCollisionDispatcher.cpp:244)
==22262==  Uninitialised value was created by a stack allocation
==22262==    at 0x4A1FEB: btSparseSdf<3>::Hash(int, int, int, btCollisionShape const*) (btSparseSDF.h:285)
==22262==
==22262== Use of uninitialised value of size 8
==22262==    at 0x49EFC1: btSparseSdf<3>::Evaluate(btVector3 const&, btCollisionShape const*, btVector3&, float) (btSparseSDF.h:185)
==22262==    by 0x48AC3F: btSoftBody::checkContact(btCollisionObjectWrapper const*, btVector3 const&, float, btSoftBody::sCti&) const (btSoftBody.cpp:2243)
==22262==    by 0x499F5B: btSoftColliders::CollideSDF_RS::DoNode(btSoftBody::Node&) const (btSoftBodyInternals.h:822)
==22262==    by 0x499E2C: btSoftColliders::CollideSDF_RS::Process(btDbvtNode const*) (btSoftBodyInternals.h:814)
==22262==    by 0x496AD3: btDbvt::collideTV(btDbvtNode const*, btDbvtAabbMm const&, btDbvt::ICollide&) const (btDbvt.h:946)
==22262==    by 0x490CEB: btSoftBody::defaultCollisionHandler(btCollisionObjectWrapper const*) (btSoftBody.cpp:3163)
==22262==    by 0x4AF834: btDefaultSoftBodySolver::processCollision(btSoftBody*, btCollisionObjectWrapper const*) (btDefaultSoftBodySolver.cpp:135)
==22262==    by 0x4AD183: btSoftRigidCollisionAlgorithm::processCollision(btCollisionObjectWrapper const*, btCollisionObjectWrapper const*, btDispatcherInfo const&, btManifoldResult*) (btSoftRigidCollisionAlgorithm.cpp:68)
==22262==    by 0x4E5C17: btCollisionDispatcher::defaultNearCallback(btBroadphasePair&, btCollisionDispatcher&, btDispatcherInfo const&) (btCollisionDispatcher.cpp:279)
==22262==    by 0x4E6467: btCollisionPairCallback::processOverlap(btBroadphasePair&) (btCollisionDispatcher.cpp:230)
==22262==    by 0x4E3CB5: btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback*, btDispatcher*) (btOverlappingPairCache.cpp:387)
==22262==    by 0x4E59FD: btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache*, btDispatcherInfo const&, btDispatcher*) (btCollisionDispatcher.cpp:244)
==22262==  Uninitialised value was created by a stack allocation
==22262==    at 0x4A1FEB: btSparseSdf<3>::Hash(int, int, int, btCollisionShape const*) (btSparseSDF.h:285)
==22262==
==22262== Use of uninitialised value of size 8
==22262==    at 0x49EFE0: btSparseSdf<3>::Evaluate(btVector3 const&, btCollisionShape const*, btVector3&, float) (btSparseSDF.h:185)
==22262==    by 0x48AC3F: btSoftBody::checkContact(btCollisionObjectWrapper const*, btVector3 const&, float, btSoftBody::sCti&) const (btSoftBody.cpp:2243)
==22262==    by 0x499F5B: btSoftColliders::CollideSDF_RS::DoNode(btSoftBody::Node&) const (btSoftBodyInternals.h:822)
==22262==    by 0x499E2C: btSoftColliders::CollideSDF_RS::Process(btDbvtNode const*) (btSoftBodyInternals.h:814)
==22262==    by 0x496AD3: btDbvt::collideTV(btDbvtNode const*, btDbvtAabbMm const&, btDbvt::ICollide&) const (btDbvt.h:946)
==22262==    by 0x490CEB: btSoftBody::defaultCollisionHandler(btCollisionObjectWrapper const*) (btSoftBody.cpp:3163)
==22262==    by 0x4AF834: btDefaultSoftBodySolver::processCollision(btSoftBody*, btCollisionObjectWrapper const*) (btDefaultSoftBodySolver.cpp:135)
==22262==    by 0x4AD183: btSoftRigidCollisionAlgorithm::processCollision(btCollisionObjectWrapper const*, btCollisionObjectWrapper const*, btDispatcherInfo const&, btManifoldResult*) (btSoftRigidCollisionAlgorithm.cpp:68)
==22262==    by 0x4E5C17: btCollisionDispatcher::defaultNearCallback(btBroadphasePair&, btCollisionDispatcher&, btDispatcherInfo const&) (btCollisionDispatcher.cpp:279)
==22262==    by 0x4E6467: btCollisionPairCallback::processOverlap(btBroadphasePair&) (btCollisionDispatcher.cpp:230)
==22262==    by 0x4E3CB5: btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback*, btDispatcher*) (btOverlappingPairCache.cpp:387)
==22262==    by 0x4E59FD: btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache*, btDispatcherInfo const&, btDispatcher*) (btCollisionDispatcher.cpp:244)
==22262==  Uninitialised value was created by a stack allocation
==22262==    at 0x4A1FEB: btSparseSdf<3>::Hash(int, int, int, btCollisionShape const*) (btSparseSDF.h:285)
==22262==
==22262== Conditional jump or move depends on uninitialised value(s)
==22262==    at 0x49EEDC: btSparseSdf<3>::Evaluate(btVector3 const&, btCollisionShape const*, btVector3&, float) (btSparseSDF.h:171)
==22262==    by 0x48AC3F: btSoftBody::checkContact(btCollisionObjectWrapper const*, btVector3 const&, float, btSoftBody::sCti&) const (btSoftBody.cpp:2243)
==22262==    by 0x499F5B: btSoftColliders::CollideSDF_RS::DoNode(btSoftBody::Node&) const (btSoftBodyInternals.h:822)
==22262==    by 0x499E2C: btSoftColliders::CollideSDF_RS::Process(btDbvtNode const*) (btSoftBodyInternals.h:814)
==22262==    by 0x496AD3: btDbvt::collideTV(btDbvtNode const*, btDbvtAabbMm const&, btDbvt::ICollide&) const (btDbvt.h:946)
==22262==    by 0x490CEB: btSoftBody::defaultCollisionHandler(btCollisionObjectWrapper const*) (btSoftBody.cpp:3163)
==22262==    by 0x4AF834: btDefaultSoftBodySolver::processCollision(btSoftBody*, btCollisionObjectWrapper const*) (btDefaultSoftBodySolver.cpp:135)
==22262==    by 0x4AD183: btSoftRigidCollisionAlgorithm::processCollision(btCollisionObjectWrapper const*, btCollisionObjectWrapper const*, btDispatcherInfo const&, btManifoldResult*) (btSoftRigidCollisionAlgorithm.cpp:68)
==22262==    by 0x4E5C17: btCollisionDispatcher::defaultNearCallback(btBroadphasePair&, btCollisionDispatcher&, btDispatcherInfo const&) (btCollisionDispatcher.cpp:279)
==22262==    by 0x4E6467: btCollisionPairCallback::processOverlap(btBroadphasePair&) (btCollisionDispatcher.cpp:230)
==22262==    by 0x4E3CB5: btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback*, btDispatcher*) (btOverlappingPairCache.cpp:387)
==22262==    by 0x4E59FD: btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache*, btDispatcherInfo const&, btDispatcher*) (btCollisionDispatcher.cpp:244)
==22262==  Uninitialised value was created by a stack allocation
==22262==    at 0x4A1FEB: btSparseSdf<3>::Hash(int, int, int, btCollisionShape const*) (btSparseSDF.h:285)



The error starts here:

Code:
      Cell*&         root=cells[static_cast<int>(h%cells.size())];       //<--------------- Line 165 of btSparseSDF.h

Code:
      SIMD_FORCE_INLINE T& operator[](int n)
      {
         btAssert(n>=0);                    //<--------------- Line 177 of btAlignedObjectArray.h
         btAssert(n<size());
         return m_data[n];
      }


Seems that cells[n] couldn't be null. But cells.size() = 2383.
The Initializes is OK
It happens in the first approach with the softbody.

Any Idea? :?
Thanks again!


Top
 Profile  
 
PostPosted: Fri Mar 17, 2017 11:56 pm 
Offline

Joined: Sun Aug 07, 2011 5:27 am
Posts: 42
Hi

I would have a look at bullet softbody demo that came with the sdk, the sofbodies in the demo a configured diffrent from yours.


Top
 Profile  
 
PostPosted: Sat Mar 18, 2017 5:37 am 
Offline

Joined: Thu Mar 14, 2013 9:56 pm
Posts: 6
Thank you Xcoder79,

That's exactly what I'm trying to do. It is very different now. I've started by the Soft Cloth demo (but with CreatePatchUV by @mi076 instead Cloth's CreatePatch - BTW this generates error too :( ). But as I'm making a c++ game, with a few managers and entities, maybe I got lost.

But I think the solution is going to arise in a few days, and I'll post here with a big smile hehe. Until there, any suggests will be welcome.

Could you point these differences?

Thanks!


Top
 Profile  
 
PostPosted: Mon Mar 27, 2017 7:21 am 
Offline

Joined: Thu Mar 14, 2013 9:56 pm
Posts: 6
Hello,

After a lot of tries and investigation, I can't find the reason of this error. I also tried with the today's git version of bullet but nothing, the error remains just like I said previously.
Here is the final code simplified. I unified the SoftDemo.cpp to post it here. Maybe I forgot something. Any tip is very welcome.

Code:
#include "BulletSoftBody/btSoftRigidDynamicsWorld.h"

#include <btBulletDynamicsCommon.h>

#include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h"
#include "BulletSoftBody/btSoftBodyHelpers.h"

btDefaultCollisionConfiguration* collisionConfiguration;
btSoftBodyWorldInfo    softBodyWorldInfo;
btDynamicsWorld* dynamicsWorld;
btCollisionDispatcher* dispatcher;
btBroadphaseInterface* broadPhase;
btConstraintSolver* solver;
btAlignedObjectArray<btCollisionShape*> collisionShapes;

void reset()
{

    if (dynamicsWorld)
    {

        int numObjects = 0;
        int i;
        int numConstraints = dynamicsWorld->getNumConstraints();
        for (i=0;i<numConstraints;i++)
        {
            dynamicsWorld->getConstraint(0)->setEnabled(true);
        }
        numObjects = dynamicsWorld->getNumCollisionObjects();

        ///create a copy of the array, not a reference!
        btCollisionObjectArray copyArray = dynamicsWorld->getCollisionObjectArray();

        for (i=0;i<numObjects;i++)
        {
            btCollisionObject* colObj = copyArray[i];
            btRigidBody* body = btRigidBody::upcast(colObj);
            if (body)
            {
                if (body->getMotionState())
                {
                    btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState();
                    myMotionState->m_graphicsWorldTrans = myMotionState->m_startWorldTrans;
                    body->setCenterOfMassTransform( myMotionState->m_graphicsWorldTrans );
                    colObj->setInterpolationWorldTransform( myMotionState->m_startWorldTrans );
                    colObj->forceActivationState(ACTIVE_TAG);
                    colObj->activate();
                    colObj->setDeactivationTime(0);
                }

                if (dynamicsWorld->getBroadphase()->getOverlappingPairCache())
                    dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(colObj->getBroadphaseHandle(),((btDynamicsWorld*)dynamicsWorld)->getDispatcher());

                btRigidBody* body = btRigidBody::upcast(colObj);
                if (body && !body->isStaticObject())
                {
                    btRigidBody::upcast(colObj)->setLinearVelocity(btVector3(0,0,0));
                    btRigidBody::upcast(colObj)->setAngularVelocity(btVector3(0,0,0));
                }
            }

        }

        ///reset some internal cached data in the broadphase
        dynamicsWorld->getBroadphase()->resetPool(((btDynamicsWorld*)dynamicsWorld)->getDispatcher());
        dynamicsWorld->getConstraintSolver()->reset();


        ///remove the rigidbodies from the dynamics world and delete them
        for(int i=dynamicsWorld->getNumCollisionObjects()-1;i>=0;i--)
        {
            btCollisionObject*   obj=dynamicsWorld->getCollisionObjectArray()[i];
            btRigidBody*      body=btRigidBody::upcast(obj);
            if(body&&body->getMotionState())
            {
                delete body->getMotionState();
            }
            while(dynamicsWorld->getNumConstraints())
            {
                btTypedConstraint*   pc=dynamicsWorld->getConstraint(0);
                dynamicsWorld->removeConstraint(pc);
                delete pc;
            }
            btSoftBody* softBody = btSoftBody::upcast(obj);
            if (softBody)
            {
                ((btSoftRigidDynamicsWorld*)dynamicsWorld)->removeSoftBody(softBody);
            } else
            {
                btRigidBody* body = btRigidBody::upcast(obj);
                if (body)
                    dynamicsWorld->removeRigidBody(body);
                else
                    dynamicsWorld->removeCollisionObject(obj);
            }
            delete obj;
        }

    }
}

int main()
{

    collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();

    dispatcher = 0;

    dispatcher = new btCollisionDispatcher(collisionConfiguration);
    softBodyWorldInfo.m_dispatcher = dispatcher;


   btVector3 worldAabbMin(-1000,-1000,-1000);
   btVector3 worldAabbMax(1000,1000,1000);

   broadPhase = new btAxisSweep3(worldAabbMin,worldAabbMax,32766);

    softBodyWorldInfo.m_broadphase = broadPhase;

    solver = new btSequentialImpulseConstraintSolver();

   btSoftBodySolver* softBodySolver = 0;

    btDiscreteDynamicsWorld* world = new btSoftRigidDynamicsWorld(dispatcher,broadPhase,solver,collisionConfiguration,softBodySolver);
    dynamicsWorld = world;

   dynamicsWorld->getDispatchInfo().m_enableSPU = true;
   dynamicsWorld->setGravity(btVector3(0,-10,0));
   softBodyWorldInfo.m_gravity.setValue(0,-10,0);
    softBodyWorldInfo.m_sparsesdf.Initialize();

    reset();

   softBodyWorldInfo.m_sparsesdf.Reset();

   softBodyWorldInfo.air_density      =   (btScalar)1.2;
   softBodyWorldInfo.water_density   =   0;
   softBodyWorldInfo.water_offset      =   0;
   softBodyWorldInfo.water_normal      =   btVector3(0,0,0);
   softBodyWorldInfo.m_gravity.setValue(0,-10,0);

   const btScalar   s=8;
    btSoftBody*      softBody=btSoftBodyHelpers::CreatePatch(   softBodyWorldInfo,btVector3(-s,0,-s),
      btVector3(+s,0,-s),
      btVector3(-s,0,+s),
      btVector3(+s,0,+s),
      31,31,
      //      31,31,
      1+2+4+8,true);

   softBody->getCollisionShape()->setMargin(0.5);
   btSoftBody::Material* pm=softBody->appendMaterial();
   pm->m_kLST      =   0.4;
   pm->m_flags      -=   btSoftBody::fMaterial::DebugDraw;
   softBody->generateBendingConstraints(2,pm);
   softBody->setTotalMass(150);

    ((btSoftRigidDynamicsWorld*)dynamicsWorld)->addSoftBody(softBody);

    btCollisionShape* ballShape = new btSphereShape(btScalar(1.25));

    btTransform startTransform;
    startTransform.setIdentity();

    btScalar mass(0.01f);

    bool isDynamic = (mass != 0.f);

    btVector3 localInertia(0,0,0);
    if (isDynamic)
            ballShape->calculateLocalInertia(mass,localInertia);

    btVector3 initialPosition = btVector3(0,2,0);
    startTransform.setOrigin(initialPosition);

    collisionShapes.push_back(ballShape);

    //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
    btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
    btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,ballShape,localInertia);
    rbInfo.m_restitution = 1.1f;
    rbInfo.m_friction = 0.8f;
    rbInfo.m_angularDamping = 0;
    btRigidBody* body = new btRigidBody(rbInfo);
    body->setActivationState(DISABLE_DEACTIVATION);

    dynamicsWorld->addRigidBody(body);

    int i=0;
    while(i++ < 100)
    {

        dynamicsWorld->stepSimulation(1.0f/60.f,0);
        softBodyWorldInfo.m_sparsesdf.GarbageCollect();

    }

    reset();
    softBodyWorldInfo.m_sparsesdf.Reset();

   //delete collision shapes
   for (int j=0;j<collisionShapes.size();j++)
   {
      btCollisionShape* shape = collisionShapes[j];
      collisionShapes[j] = 0;
      delete shape;
   }

   delete dynamicsWorld;

   delete solver;

   delete broadPhase;

   delete dispatcher;

   delete collisionConfiguration;

    return 0;
}


Thanks again!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Exabot [Bot], Google [Bot] and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group