Esempio n. 1
0
void BulletTestApp::initTest()
{

	// Clean up last test
	if ( mWorld ) {
		mWorld->clear();
		mWorld->getInfo().m_sparsesdf.Reset();
	}
	
	// Used when generating terrain
	Channel32f heightField;

	// Create and add the wobbly box
	btSoftBody* body				= 0;
	btSoftBody::Material* material	= 0;
	mGroundTransform.setIdentity();
	switch ( mTest ) {
	case 0:
		mGround = bullet::createRigidBox( mWorld, Vec3f( 200.0f, 35.0f, 200.0f ), 0.0f );
		bullet::createRigidSphere( mWorld, 50.0f, 0.0f, Vec3f( 0.0f, -50.0f, 0.0f ) );
		break;
	case 1:
		mGround = bullet::createRigidHull( mWorld, mConvex, Vec3f::one() * 50.0f, 0.0f );
		break;
	case 2:
		mGround = bullet::createRigidMesh( mWorld, mConcave, Vec3f( 10.0f, 1.0f, 10.0f ), 0.0f, 0.0f );
		break;
	case 5:
		heightField = Channel32f( loadImage( loadResource( RES_IMAGE_HEIGHTFIELD_SM ) ) );
		mGround = bullet::createRigidTerrain( mWorld, heightField, -1.0f, 1.0f, Vec3f( 6.0f, 80.0f, 6.0f ), 0.0f );
		break;
	case 6:
		// ADVANCED: To add a custom class, create a standard pointer to it and 
		// pushBack it into your world. Be sure to delete this pointer when you no longer need it.
		heightField = Channel32f( loadImage( loadResource( RES_IMAGE_HEIGHTFIELD ) ) );
		mTerrain = new DynamicTerrain( heightField, -1.0f, 1.0f, Vec3f( 2.0f, 50.0f, 2.0f ), 0.0f );
		mWorld->pushBack( mTerrain );
		break;
	case 7:

		// Start capture
		if ( !mCapture ) {
			mCapture = Capture( 320, 240 );
			mCapture.start();
		}

		break;
	case 8:
		mWorld->getInfo().m_gravity = toBulletVector3( Vec3f( 0.0f, -0.5f, 0.0f ) );

		mGround = bullet::createSoftCloth( mWorld, Vec2f::one() * 180.0f, Vec2i( 18, 20 ), SoftCloth::CLOTH_ATTACH_CORNER_ALL, Vec3f( 0.0f, 0.0f, 40.0f ), Quatf( 0.0f, 0.0f, 0.0f, 0.1f ) );
		
		body = toBulletSoftBody( mGround );
		
		body->m_materials[ 0 ]->m_kAST	= 0.2f;
		body->m_materials[ 0 ]->m_kLST	= 0.2f;
		body->m_materials[ 0 ]->m_kVST	= 0.2f;
		
		body->m_cfg.kDF					= 0.9f; 
		body->m_cfg.kSRHR_CL			= 1.0f;
		body->m_cfg.kSR_SPLT_CL			= 0.0f;
		body->m_cfg.collisions			= btSoftBody::fCollision::CL_SS + btSoftBody::fCollision::CL_RS;
		
		body->getCollisionShape()->setMargin( 0.0001f );
		body->setTotalMass( 500.0f );
		body->generateClusters( 0 );

		material						= body->appendMaterial();
		material->m_kAST				= 0.5f;
		material->m_kLST				= 0.5f;
		material->m_kVST				= 1.0f;
		body->generateBendingConstraints( 1, material );

		break;
	case 9:
		heightField = Channel32f( loadImage( loadResource( RES_IMAGE_HEIGHTFIELD_SM ) ) );
		mGround = bullet::createRigidTerrain( mWorld, heightField, -1.0f, 1.0f, Vec3f( 6.0f, 80.0f, 6.0f ), 0.0f );
		break;
	default:
		mGround = bullet::createRigidBox( mWorld, Vec3f( 200.0f, 35.0f, 200.0f ), 0.0f );
		break;
	}

	// Set friction for box
	if ( mTest < 5 ) {
		btRigidBody* boxBody = bullet::toBulletRigidBody( mGround );
		boxBody->setFriction( 0.95f );
	}

}
Esempio n. 2
0
void BulletTestApp::initTest()
{

	// Clean up last test
	if ( mWorld ) {
		mWorld->clear();
	}
	
	// Used when generating terrain
	Channel32f heightField;

	// Create and add the wobbly box
	mGroundTransform.setIdentity();
	switch ( mTest ) {
	case 0:
		mGround = bullet::createRigidBox( mWorld, Vec3f( 200.0f, 35.0f, 200.0f ), 0.0f );
		bullet::createRigidSphere( mWorld, 50.0f, 64, 0.0f, Vec3f( 0.0f, -50.0f, 0.0f ) );
		break;
	case 1:
		mGround = bullet::createRigidHull( mWorld, mConvex, Vec3f::one() * 50.0f, 0.0f );
		break;
	case 2:
		mGround = bullet::createRigidMesh( mWorld, mConcave, Vec3f( 10.0f, 1.0f, 10.0f ), 0.0f, 0.0f );
		break;
	case 3:
		mGround = bullet::createRigidBox( mWorld, Vec3f( 200.0f, 35.0f, 200.0f ), 0.0f );
		break;
	case 4:
		mGround = bullet::createRigidBox( mWorld, Vec3f( 200.0f, 35.0f, 200.0f ), 0.0f );
		break;
	case 5:
		heightField = Channel32f( loadImage( loadResource( RES_IMAGE_HEIGHTFIELD_SM ) ) );
		mGround = bullet::createRigidTerrain( mWorld, heightField, -1.0f, 1.0f, Vec3f( 6.0f, 80.0f, 6.0f ), 0.0f );
		break;
	case 6:

		// ADVANCED: To add a custom class, create a standard pointer to it and 
		// pushBack it into your world. Be sure to delete this pointer when you no loinger need it
		heightField = Channel32f( loadImage( loadResource( RES_IMAGE_HEIGHTFIELD ) ) );
		mTerrain = new DynamicTerrain( heightField, -1.0f, 1.0f, Vec3f( 2.0f, 50.0f, 2.0f ), 0.0f );
		mWorld->pushBack( mTerrain );
		break;

	case 7:

		// Start capture
		if ( !mCapture ) {
			mCapture = Capture( 320, 240 );
			mCapture.start();
		}

		break;

	}

	// Set friction for box
	if ( mTest < 5 ) {
		btRigidBody* boxBody = bullet::toBulletRigidBody( mGround );
		boxBody->setFriction( 0.95f );
	}

}
Esempio n. 3
0
void BulletTestApp::initTest()
{
    // Clean up last test
    if ( mWorld )
    {
        mWorld->clear();
    }

    mGroundTransform.setIdentity();

    // Create the ground
    {
        mGround = bullet::createRigidBox( mWorld, Vec3f( 357.0f, 1.0f, 600.0f ), 0.0f );
        btRigidBody* boxBody = bullet::toBulletRigidBody( mGround );
        boxBody->setFriction( 0.95f );
        boxBody->setRestitution( .65f );
    }

    // Create the backboard
    {
        mBackBaord = bullet::createRigidBox( mWorld, Vec3f( 110.0f, 70.0f, 1.0f ), 0.0f, Vec3f( 0.0f, 100.f, 250.f ));
        btRigidBody* boxBody = bullet::toBulletRigidBody( mBackBaord );
        boxBody->setFriction( 0.95f );
        boxBody->setRestitution( .65f );
    }

// 	{
// 		mTest = bullet::createRigidCylinder( mWorld, Vec3f( 10.0f, 50.0f, 10.0f ), 16, 0.0f, Vec3f( 0.0f, 50.0f, 0.0f ));
// 		btRigidBody* boxBody = bullet::toBulletRigidBody( mBackBaord );
// 		boxBody->setFriction( 0.95f );
// 		boxBody->setRestitution( .65f );
// 	}

    // Create the ring box
    {
        mBox = bullet::createRigidBox( mWorld, Vec3f( 5.f, 1.0f, 5.0f ), 0.0f, Vec3f( 0.0f, 75.0f, 247.5f ));
        btRigidBody* boxBody = bullet::toBulletRigidBody( mBox );
        boxBody->setFriction( 0.95f );
        boxBody->setRestitution( .65f );
    }

    // Create the ring
    {
        mRing = bullet::createRigidTorus( mWorld, 0.5f, 10.f, 200, 0.0f, Vec3f( 0.0f, 75.0f, 234.0f ), Quatf( Vec3f::xAxis(), M_PI / 2. ) );
        btRigidBody* boxBody = bullet::toBulletRigidBody( mRing );
        boxBody->setFriction( 0.95f );
        boxBody->setRestitution( .65f );

// 		mRing = bullet::createRigidMesh( mWorld, mTorus, Vec3f( 1.0f, 2.0f, 1.0f ), 0.0f, 0.0f, Vec3f( 0.0f, 50.0f, 0.0f ));
// 		btRigidBody* boxBody = bullet::toBulletRigidBody( mRing );
// 		boxBody->setFriction( 0.95f );
// 		boxBody->setRestitution( .65f );

// 		float radiusIn     =  0.5f;
// 		float radiusOut    =  8.0f;
// 		float subdivisions = 36.f;
// 		Vec3f forward( 0.0      , 0.0, 1.0 );
// 		Vec3f side   ( radiusOut, 0.0, 0.0 );
//
// 		float gap = sqrt( 2.0f * radiusOut * radiusOut - 2.0f * radiusIn * radiusIn * cos(( 2.0f * SIMD_PI ) / subdivisions ));
//
// 		btTransform t;
// 		for( int x = 0; x < (int)subdivisions; x++ )
// 		{
// 			float angle = ( x * 2.0f * SIMD_PI ) / subdivisions;
// 			Vec3f position = side;
// 			position.rotate( forward, angle );
// 			Quatf q( forward, angle );
//
// 			mRing = bullet::createRigidCylinder( mWorld, Vec3f( radiusIn, 3* ( SIMD_PI / subdivisions ) + 0.5f * gap, radiusIn ), subdivisions, 0.0f, position, q );
// 			btRigidBody* boxBody = bullet::toBulletRigidBody( mRing );
// 			boxBody->setFriction( 0.95f );
// 			boxBody->setRestitution( .65f );
// 		}

//		mRing = bullet::createRigidCylinder( mWorld, Vec3f( 1, 1, 1 ), 16, 0.0f, Vec3f( 0, 10, 0 ), Quatf( Vec3f::xAxis(), M_PI / 2 ));

    }
}