Soft Body Bonanza

User avatar
sio2interactive
Posts: 31
Joined: Tue Jul 29, 2008 10:26 am

Soft Body Bonanza

Post by sio2interactive »

Ok Im a bit confuse this is the code that Im using

Code: Select all


// Initialization
	_btSoftBodyWorldInfo = ( btSoftBodyWorldInfo * )calloc( 1, sizeof( btSoftBodyWorldInfo ) ); 

	_btSoftBodyRigidBodyCollisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();
	_btCollisionDispatcher = new btCollisionDispatcher( _btSoftBodyRigidBodyCollisionConfiguration );
	_btBroadphaseInterface = new btDbvtBroadphase();
	_btConstraintSolver= new btSequentialImpulseConstraintSolver();
	
	_btSoftBodyWorldInfo->m_dispatcher = _btCollisionDispatcher;
	_btSoftBodyWorldInfo->m_broadphase = _btBroadphaseInterface;
	
	_btSoftRigidDynamicsWorld = new btSoftRigidDynamicsWorld( _btCollisionDispatcher, _btBroadphaseInterface, _btConstraintSolver, _btSoftBodyRigidBodyCollisionConfiguration );


// Add soft body

	btTransform _btTransform;
	...
	...

	switch( bounds )
	{
		case SIO2_PHYSIC_TRIANGLEMESH:
		case SIO2_PHYSIC_CONVEXHULL:
		{
			btVector3 *buf = ( btVector3 * )malloc( GetNumVert( tmp ) * sizeof( btVector3 ) );
			
			...
			...

			_btSoftBody = new btSoftBody( physic->_btSoftBodyWorldInfo,
													   sio2ObjectGetNumVert( tmp ),
													   buf,
													   NULL );
			
			i = 0;
			while( i != tmp->n_vgroup )
			{
				j = 0;
				while( j != tmp->vertexgroup[ i ]->n_ind )
				{
					_btSoftBody->appendLink( tmp->vertexgroup[ i ]->ind[ j     ], tmp->vertexgroup[ i ]->ind[ j + 1 ] );

					_btSoftBody->appendLink( tmp->vertexgroup[ i ]->ind[ j + 1 ], tmp->vertexgroup[ i ]->ind[ j + 2 ] );

					_btSoftBody->appendLink( tmp->vertexgroup[ i ]->ind[ j + 2 ], tmp->vertexgroup[ i ]->ind[ j     ] );
														  
					_btSoftBody->appendFace( tmp->vertexgroup[ i ]->ind[ j     ], tmp->vertexgroup[ i ]->ind[ j + 1 ], tmp->vertexgroup[ i ]->ind[ j + 2 ] );
					
					j += 3;
				}
			
				++i;
			}
			
			break;
		}
	}
	
    _btSoftBody->m_cfg.kDP = 0.0f;
    _btSoftBody->m_cfg.kDF = 0.2f;
    _btSoftBody->m_cfg.kMT = 0.02f;
    _btSoftBody->m_cfg.kCHR = 1.0f;
    _btSoftBody->m_cfg.kKHR = 0.8f;
    _btSoftBody->m_cfg.kSHR = 1.0f;
    _btSoftBody->m_cfg.piterations = 2;
    _btSoftBody->m_materials[0]->m_kLST = 0.8f;
    _btSoftBody->m_materials[0]->m_kAST = 0.8f;
    _btSoftBody->m_materials[0]->m_kVST = 0.8f;
	
    _btSoftBody->setPose( true, true );
    
    _btSoftBody->generateBendingConstraints( 2 );
	
    _btSoftBody->randomizeConstraints();	

    ...
    ...
	
    _btTransform.setFromOpenGLMatrix( ( btScalar * )m );
	
    _btSoftBody->setWorldTransform( _btTransform );
	
    _btSoftRigidDynamicsWorld->addSoftBody( _btSoftBody );
    
    ...
    ...

Everything works fine and I can see the softbody object along with other rigid body object, now the thing that puzzle me is why the softbody does not interact with the other rigid bodies...

Take a look at the following video to see what I mean, the monkey is a softbody, the cubes are cube rigid bodies and the floor is a static triangle mesh:

http://www.youtube.com/watch?v=X4D4mCzXdhA&fmt=18


Another thing that puzzle me is how can I get the position of the object in the world, the _btSoftBody->getWorldTransform().getOpenGLMatrix( mat ); function always stay the same even if the soft body is falling down due to the gravity...

I review the soft body tutorials many times, and I can't figure out what Im doing wrong... am I missing something or?

Tks in advance,
User avatar
sio2interactive
Posts: 31
Joined: Tue Jul 29, 2008 10:26 am

Re: Soft Body Bonanza

Post by sio2interactive »

I read something on the forum about the rigid body / soft body creation order as well as for their transformation (like setFromOpenGLMatrix)... The post is a bit outdated but is there a specific order in the object creation in 2.73??

Cheers,
User avatar
sio2interactive
Posts: 31
Joined: Tue Jul 29, 2008 10:26 am

Re: Soft Body Bonanza

Post by sio2interactive »

Ok... I figure it out...

Code: Select all


	_btTransform.setFromOpenGLMatrix( ( btScalar * )m );
	object->_btSoftBody->transform( _btTransform );

This is the right way to setup the matrix...