error when a soft body collide with a rigid body !!!

OSasuke
Posts: 47
Joined: Tue Dec 09, 2008 10:12 am

error when a soft body collide with a rigid body !!!

Post by OSasuke »

Hi every one.

I have a segfault when a soft body collide with a rigid one.

This is the code i wrote :

Code: Select all

#include <iostream>
#include <cstdlib>
#include <btBulletDynamicsCommon.h>
#include <Bullet-C-Api.h>
#include <btBulletCollisionCommon.h>
#include <BulletSoftBody/btSoftBody.h>
#include <BulletSoftBody/btSoftRigidDynamicsWorld.h>
#include <BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h>
#include <BulletSoftBody/btSoftBodyHelpers.h>

using namespace std;

int main(int argc, char** argv)
{

    btSoftBodyWorldInfo	softBodyWI;

    btVector3 worldAabbMin(-1000,-1000,-1000);
    btVector3 worldAabbMax(1000,1000,1000);
    int maxProxies = 1024;
    btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
    softBodyWI.m_broadphase = broadphase;

    btDefaultCollisionConfiguration* collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();
    btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
    softBodyWI.m_dispatcher = dispatcher;

    btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;

    btSoftRigidDynamicsWorld* world = new btSoftRigidDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
    world->setGravity(btVector3(0,-10,0));
    softBodyWI.m_gravity.setValue(0,-10,0);

    btSoftBody*	psb=btSoftBodyHelpers::CreateEllipsoid(softBodyWI,btVector3(0,0,0),
                                                        btVector3(3,3,3),512);
	psb->m_materials[0]->m_kLST	=	0.1;
	psb->m_cfg.kDF				=	1;
	psb->m_cfg.kDP				=	0.001;
	psb->m_cfg.kPR				=	2500;
	psb->setTotalMass(20,true);

	world->addSoftBody(psb);
	psb->translate(btVector3(0,100,0));

    btCollisionShape* Shape = new btBoxShape(btVector3(50,5,50));
    btMotionState* motionState = new btDefaultMotionState(btTransform::getIdentity());

    btRigidBody::btRigidBodyConstructionInfo BodyCI(0,motionState,Shape,btVector3(0,0,0));
    btRigidBody* rBody = new btRigidBody(BodyCI);
    world->addRigidBody(rBody);

    btClock iclock;
    iclock.reset();
    unsigned int l_time = 0;
    unsigned int c_time = 0;

    while(iclock.getTimeMilliseconds()<1000*10)
    {
        world->stepSimulation(1.0f/60.f,10);

        c_time = iclock.getTimeMilliseconds();
        if(c_time - l_time > 100)
        {
            l_time = iclock.getTimeMilliseconds();
            cout << psb->m_nodes[0].m_x[1] << endl;
        }
    }

    delete Shape;
    delete motionState;
    delete rBody;

    delete world;
    delete solver;
    delete dispatcher;
    delete collisionConfiguration;
    delete broadphase;

    return 0;
}
Is there any thing wrong :?: :?: :?:
foolegg
Posts: 5
Joined: Tue Dec 22, 2009 3:32 pm

Re: error when a soft body collide with a rigid body !!!

Post by foolegg »

Code: Select all

    softBodyWI->m_sparsesdf.Initialize();
try add this line. after

Code: Select all

    softBodyWI.m_gravity.setValue(0,-10,0);
OSasuke
Posts: 47
Joined: Tue Dec 09, 2008 10:12 am

Re: error when a soft body collide with a rigid body !!!

Post by OSasuke »

Thanks very much. :D

I haven't seen this line in the SoftDemo example :!:
Is this line essential for the creation of the soft bodies :?: