Example #1
0
void Physics::Init()
{
	broadphase = new btDbvtBroadphase();
	btVector3 worldAabbMin(-1000, -1000, -1000);
	btVector3 worldAabbMax(1000, 1000, 1000);
	broadphase = new btAxisSweep3(worldAabbMin, worldAabbMax, MAX_PROXIES);

	collisionConfiguration =
		new btSoftBodyRigidBodyCollisionConfiguration();
	dispatcher = new btCollisionDispatcher(collisionConfiguration);
	solver = new btSequentialImpulseConstraintSolver();

	//new btConstraintSolver()

	softBodySolver = new btDefaultSoftBodySolver();
	dynamicsWorld = new btSoftRigidDynamicsWorld(dispatcher,
		broadphase, solver, collisionConfiguration, softBodySolver);

	dynamicsWorld->setGravity(btVector3(0, -10, 0));

	softBodyWorldInfo.m_broadphase = broadphase;
	softBodyWorldInfo.m_dispatcher = dispatcher;
	softBodyWorldInfo.m_gravity.setValue(0, -10, 0);
	softBodyWorldInfo.air_density = (btScalar)0.2;
	softBodyWorldInfo.water_density = 0;
	softBodyWorldInfo.water_offset = 0;
	softBodyWorldInfo.water_normal = btVector3(0, 0, 0);
	softBodyWorldInfo.m_sparsesdf.Initialize();

	blob = nullptr;
}
Example #2
0
			void startup(gemini::Allocator& allocator)
			{
				physics_allocator = &allocator;
				// TODO@apetrone: set up custom allocation with btAlignedAllocSetCustom.

				collision_config = new btDefaultCollisionConfiguration();
				dispatcher = new btCollisionDispatcher( collision_config );

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

				constraint_solver = new btSequentialImpulseConstraintSolver();

				broadphase = new btDbvtBroadphase();
//				broadphase = new btAxisSweep3(worldAabbMin, worldAabbMax);

				pair_cache = broadphase->getOverlappingPairCache();
				// setup ghost pair callback instance
				pair_cache->setInternalGhostPairCallback( new CustomGhostPairCallback() );

				dynamics_world = new btDiscreteDynamicsWorld(dispatcher, (btBroadphaseInterface*)broadphase, constraint_solver, collision_config);
				dynamics_world->setGravity( btVector3( 0, -9.8f, 0 ) );
//				dynamics_world->getDispatchInfo().m_useConvexConservativeDistanceUtil = true;
//				dynamics_world->getDispatchInfo().m_convexConservativeDistanceThreshold = 0.01;
				dynamics_world->getDispatchInfo().m_allowedCcdPenetration = 0.0001f;

				// instance and set the debug renderer
				debug_renderer = MEMORY2_NEW(*physics_allocator, bullet::DebugPhysicsRenderer);
				dynamics_world->setDebugDrawer(debug_renderer);
			}
Example #3
0
    void PhysicalSystem::initPhysicalSystem()
    {

        ///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration.
        collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();

        //dispatcher =0;

        ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
        dispatcher = new btCollisionDispatcher(collisionConfiguration);

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

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

        softBodyWorldInfo.m_dispatcher = dispatcher;
        softBodyWorldInfo.m_broadphase = broadPhase;
        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);

        softBodyWorldInfo.m_sparsesdf.Initialize();

        ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
        solver = new btSequentialImpulseConstraintSolver;

        dynamicsWorld = new btSoftRigidDynamicsWorld(dispatcher,broadPhase,solver,collisionConfiguration);

        //softBodyWorldInfo.m_gravity.setValue(0,-10,0);

    }
Example #4
0
void	DoublePrecisionDemo::initPhysics()
{
  m_debugMode |= btIDebugDraw::DBG_DrawWireframe;
	
	btMatrix3x3 basisA;
	basisA.setIdentity();

	btMatrix3x3 basisB;
	basisB.setIdentity();

	objects[0].getWorldTransform().setBasis(basisA);
	objects[1].getWorldTransform().setBasis(basisB);
	

	btBoxShape* boxA = new btBoxShape(btVector3(0.5,0.5,0.5));
	btBoxShape* boxB = new btBoxShape(btVector3(0.5,0.5,0.5));

	objects[0].setCollisionShape(boxA);//&hullA;
	objects[1].setCollisionShape(boxB);//&hullB;

	btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
	btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
	btVector3	worldAabbMin(80000,80000,80000);
	btVector3	worldAabbMax(120000,120000,120000);

	btAxisSweep3*	broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);
	
	collisionWorld = new btCollisionWorld(dispatcher,broadphase,collisionConfiguration);
		
	collisionWorld->addCollisionObject(&objects[0]);
	collisionWorld->addCollisionObject(&objects[1]);

}
Example #5
0
void	ColladaDemo::initPhysics(const char* filename)
{
	m_cameraUp = SimdVector3(0,0,1);
	m_forwardAxis = 1;

	///Setup a Physics Simulation Environment
	CollisionDispatcher* dispatcher = new	CollisionDispatcher();
	SimdVector3 worldAabbMin(-10000,-10000,-10000);
	SimdVector3 worldAabbMax(10000,10000,10000);
	OverlappingPairCache* broadphase = new AxisSweep3(worldAabbMin,worldAabbMax);
	//BroadphaseInterface* broadphase = new SimpleBroadphase();
	m_physicsEnvironmentPtr = new CcdPhysicsEnvironment(dispatcher,broadphase);
	m_physicsEnvironmentPtr->setDeactivationTime(2.f);
	m_physicsEnvironmentPtr->setGravity(0,0,-10);
	m_physicsEnvironmentPtr->setDebugDrawer(&debugDrawer);

	MyColladaConverter* converter = new MyColladaConverter(this);

	bool result = converter->load(filename);

	if (result)
	{
		result = converter->convert();
	}
	if (result)
	{
		gColladaConverter = converter;
	} else
	{
		gColladaConverter = 0;
	}
}
Example #6
0
void PendulumApplication::initPhysics()
{
	setCameraDistance(8.);
	m_debugMode |= btIDebugDraw::DBG_NoHelpText;

	///register some softbody collision algorithms on top of the default btDefaultCollisionConfiguration
	m_collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();


	m_dispatcher = new	btCollisionDispatcher(m_collisionConfiguration);
	m_softBodyWorldInfo.m_dispatcher = m_dispatcher;

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

	m_broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);

	m_softBodyWorldInfo.m_broadphase = m_broadphase;

	btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver();

	m_solver = solver;

	btSoftBodySolver* softBodySolver = 0;

	btDiscreteDynamicsWorld* world = new btSoftRigidDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration,softBodySolver);
	m_dynamicsWorld = world;
	m_dynamicsWorld->setDebugDrawer(&gDebugDrawer);

	m_dynamicsWorld->getDispatchInfo().m_enableSPU = true;
	m_dynamicsWorld->setGravity(btVector3(0,-10,0));
	m_softBodyWorldInfo.m_gravity.setValue(0,-10,0);

	m_softBodyWorldInfo.m_sparsesdf.Initialize();

	//create a few basic rigid bodies
	btBoxShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));
	m_collisionShapes.push_back(groundShape);

	btTransform groundTransform;
	groundTransform.setIdentity();
	groundTransform.setOrigin(btVector3(0,-50,0));
	localCreateRigidBody(0,groundTransform,groundShape);

	//buildDoublePendulumRigid();
	//buildDoublePendulumSoft();
	buildFlyingTrapeze();

	m_softBodyWorldInfo.m_sparsesdf.Reset();

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

}
Example #7
0
World::World() : m_root(new osg::Group) {
	btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
    btCollisionDispatcher *dispatcher = new btCollisionDispatcher(collisionConfiguration);
    btConstraintSolver *solver = new btSequentialImpulseConstraintSolver();
    btVector3 worldAabbMin(-10000, -10000, -10000);
    btVector3 worldAabbMax(10000, 10000, 10000);
    btBroadphaseInterface *inter = new btDbvtBroadphase();
    m_dynamics = new btDiscreteDynamicsWorld(dispatcher, inter, solver, collisionConfiguration);
    m_dynamics->setGravity(btVector3(0, 0, -10));
}
Example #8
0
void RagdollDemo::initPhysics()
{
	// Setup the basic world

	setTexturing(true);
	setShadows(true);

	setCameraDistance(btScalar(5.));

	m_collisionConfiguration = new btDefaultCollisionConfiguration();

	m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);

	btVector3 worldAabbMin(-10000,-10000,-10000);
	btVector3 worldAabbMax(10000,10000,10000);
	m_broadphase = new btAxisSweep3 (worldAabbMin, worldAabbMax);

	m_solver = new btSequentialImpulseConstraintSolver;

	m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
	//m_dynamicsWorld->getDispatchInfo().m_useConvexConservativeDistanceUtil = true;
	//m_dynamicsWorld->getDispatchInfo().m_convexConservativeDistanceThreshold = 0.01f;



	// Setup a big ground box
	{
		btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(200.),btScalar(10.),btScalar(200.)));
		m_collisionShapes.push_back(groundShape);
		btTransform groundTransform;
		groundTransform.setIdentity();
		groundTransform.setOrigin(btVector3(0,-10,0));

#define CREATE_GROUND_COLLISION_OBJECT 1
#ifdef CREATE_GROUND_COLLISION_OBJECT
		btCollisionObject* fixedGround = new btCollisionObject();
		fixedGround->setCollisionShape(groundShape);
		fixedGround->setWorldTransform(groundTransform);
		m_dynamicsWorld->addCollisionObject(fixedGround);
#else
		localCreateRigidBody(btScalar(0.),groundTransform,groundShape);
#endif //CREATE_GROUND_COLLISION_OBJECT

	}

	// Spawn one ragdoll
	btVector3 startOffset(1,0.5,0);
	spawnRagdoll(startOffset);
	startOffset.setValue(-1,0.5,0);
	spawnRagdoll(startOffset);

	clientResetScene();		
}
Example #9
0
btCollisionWorld* initCollision()
{
    btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
    btCollisionDispatcher* dispatcher = new btCollisionDispatcher( collisionConfiguration );

    btVector3 worldAabbMin( -10000, -10000, -10000 );
    btVector3 worldAabbMax( 10000, 10000, 10000 );
    btBroadphaseInterface* inter = new btAxisSweep3( worldAabbMin, worldAabbMax, 1000 );

    btCollisionWorld* collisionWorld = new btCollisionWorld( dispatcher, inter, collisionConfiguration );

    return( collisionWorld );
}
void ArtificialBirdsDemoApp::initPhysics()
{
	// Setup the basic world
	setTexturing(true);
	setShadows(true);

	setCameraDistance(btScalar(5.));

	m_collisionConfiguration = new btDefaultCollisionConfiguration();

	m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);

	btVector3 worldAabbMin(-10000,-10000,-10000);
	btVector3 worldAabbMax(10000,10000,10000);
	m_broadphase = new btAxisSweep3 (worldAabbMin, worldAabbMax);

	m_solver = new btSequentialImpulseConstraintSolver;
	m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
	//m_dynamicsWorld->getDispatchInfo().m_useConvexConservativeDistanceUtil = true;
	//m_dynamicsWorld->getDispatchInfo().m_convexConservativeDistanceThreshold = 0.01f;
	m_dynamicsWorld->setInternalTickCallback(pickingPreTickCallback, this, true);
	m_dynamicsWorld->getSolverInfo().m_numIterations = kSolverNumIterations;
	m_dynamicsWorld->setGravity(btVector3(0,kGravity,0));

	// Setup a big ground box
	{
		btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(200.),btScalar(10.),btScalar(200.)));
		m_collisionShapes.push_back(groundShape);
		btTransform groundTransform;
		groundTransform.setIdentity();
		groundTransform.setOrigin(btVector3(0,-10,0));

#define CREATE_GROUND_COLLISION_OBJECT 1
#ifdef CREATE_GROUND_COLLISION_OBJECT
		btCollisionObject* fixedGround = new btCollisionObject();
		fixedGround->setCollisionShape(groundShape);
		fixedGround->setWorldTransform(groundTransform);
		m_dynamicsWorld->addCollisionObject(fixedGround);
#else
		localCreateRigidBody(btScalar(0.),groundTransform,groundShape);
#endif //CREATE_GROUND_COLLISION_OBJECT

	}

	m_birdOpt = 0;
	m_birdDemo = 0;
	//m_birdOpt = new BirdOptimizer(m_dynamicsWorld);
	m_birdDemo = new BirdDemo(m_dynamicsWorld);

	clientResetScene();		
}
Example #11
0
void RagdollApp::initPhysics()
{
	// Setup the basic world
	m_time = 0;
	m_CycPerKnee = 2000.f;	// in milliseconds
	m_CycPerHip = 3000.f;	// in milliseconds
	m_fMuscleStrength = 0.5f;

	setTexturing(true);
	setShadows(true);

	setCameraDistance(btScalar(5.));

	m_collisionConfiguration = new btDefaultCollisionConfiguration();

	m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);

	btVector3 worldAabbMin(-10000,-10000,-10000);
	btVector3 worldAabbMax(10000,10000,10000);
	m_broadphase = new btAxisSweep3 (worldAabbMin, worldAabbMax);

	m_solver = new btSequentialImpulseConstraintSolver;

	m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
	//m_dynamicsWorld->getDispatchInfo().m_useConvexConservativeDistanceUtil = true;
	//m_dynamicsWorld->getDispatchInfo().m_convexConservativeDistanceThreshold = 0.01f;
	m_dynamicsWorld->setInternalTickCallback( forcePreTickCB, this, true );
	m_dynamicsWorld->setGravity( btVector3(0,-0,0) );
	// create surface
	//createSurface();

	//// Setup a big ground box
	btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(200.),btScalar(10.),btScalar(200.)));
	m_collisionShapes.push_back(groundShape);
	btTransform groundTransform;
	groundTransform.setIdentity();
	groundTransform.setOrigin(btVector3(0,-10,0));

	btCollisionObject* fixedGround = new btCollisionObject();
	fixedGround->setCollisionShape(groundShape);
	fixedGround->setWorldTransform(groundTransform);
	m_dynamicsWorld->addCollisionObject(fixedGround);

	// Spawn one ragdoll
	btVector3 startOffset(1,0.5,0);
	spawnRagdoll(startOffset);
	startOffset.setValue(-1,0.1,0);
	spawnRagdoll(startOffset);

	clientResetScene();		
}
void MotorDemo::initPhysics()
{
	setTexturing(true);
	setShadows(true);

	// Setup the basic world

	m_Time = 0;
	m_fCyclePeriod = 2000.f; // in milliseconds

//	m_fMuscleStrength = 0.05f;
	// new SIMD solver for joints clips accumulated impulse, so the new limits for the motor
	// should be (numberOfsolverIterations * oldLimits)
	// currently solver uses 10 iterations, so:
	m_fMuscleStrength = 0.5f;

	setCameraDistance(btScalar(5.));

	m_collisionConfiguration = new btDefaultCollisionConfiguration();

	m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);

	btVector3 worldAabbMin(-10000,-10000,-10000);
	btVector3 worldAabbMax(10000,10000,10000);
	m_broadphase = new btAxisSweep3 (worldAabbMin, worldAabbMax);

	m_solver = new btSequentialImpulseConstraintSolver;

	m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);

	m_dynamicsWorld->setInternalTickCallback(motorPreTickCallback,this,true);


	// Setup a big ground box
	{
		btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(200.),btScalar(10.),btScalar(200.)));
		m_collisionShapes.push_back(groundShape);
		btTransform groundTransform;
		groundTransform.setIdentity();
		groundTransform.setOrigin(btVector3(0,-10,0));
		localCreateRigidBody(btScalar(0.),groundTransform,groundShape);
	}

	// Spawn one ragdoll
	btVector3 startOffset(1,0.5,0);
	spawnTestRig(startOffset, false);
	startOffset.setValue(-2,0.5,0);
	spawnTestRig(startOffset, true);

	clientResetScene();		
}
Example #13
0
void PhysicsEngine::Init() {
    srand(GetTickCount());

    btVector3 worldAabbMin(-1000,-1000,-1000);
    btVector3 worldAabbMax(1000,1000,1000);
    const int maxProxies = 32766;

    m_collisionConfiguration = new btDefaultCollisionConfiguration();
    m_solver = new btSequentialImpulseConstraintSolver();
    m_broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
    btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver();
    m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);

    Reset();
}
Example #14
0
PhysicsEngine::PhysicsEngine() {
	m_CollisionConfig = new btDefaultCollisionConfiguration();
	m_Dispatcher = new btCollisionDispatcher(m_CollisionConfig);

	double scene_size = 1000.0;
	btScalar sscene_size = (btScalar)scene_size;
	btVector3 worldAabbMin(-sscene_size, -sscene_size, -sscene_size);
	btVector3 worldAabbMax(sscene_size, sscene_size, sscene_size);
	//This is one type of broadphase, bullet has others that might be faster depending on the application
	m_Broadphase = new bt32BitAxisSweep3(worldAabbMin, worldAabbMax, 16000, 0, true);  // true for disabling raycast accelerator

	m_Solver = new btSequentialImpulseConstraintSolver();
	m_World = new btDiscreteDynamicsWorld(m_Dispatcher, m_Broadphase, m_Solver, m_CollisionConfig);
	m_World->setGravity(btVector3(0.0f, -9.18f, 0.0f));
}
//--------------------------------------------------------------
void ofxBulletWorldSoft::setup() {
	if(broadphase == NULL) {
		btVector3 worldAabbMin(-1000,-1000,-1000);
		btVector3 worldAabbMax(1000,1000,1000);
		broadphase = new btAxisSweep3 (worldAabbMin, worldAabbMax);
	}
	

	
	if(collisionConfig == NULL)			collisionConfig = new btSoftBodyRigidBodyCollisionConfiguration();
	if(dispatcher == NULL)				dispatcher = new btCollisionDispatcher( collisionConfig );
	if(solver == NULL)					solver = new btSequentialImpulseConstraintSolver;
	if(world == NULL)					world = new btSoftRigidDynamicsWorld(dispatcher, broadphase, solver, collisionConfig);
	
	
	
	
	// default gravity //
	setGravity(ofVec3f(0.f, 9.8f, 0.f));
	
	

	
	world->getDispatchInfo().m_enableSPU = true;
	world->getWorldInfo().m_sparsesdf.Initialize();
	world->getWorldInfo().air_density		=	(btScalar)1.2;
	world->getWorldInfo().m_sparsesdf.Reset();
	
	/*
	Nodes		=	0x0001,
	Links		=	0x0002,
	Faces		=	0x0004,
	Tetras		=	0x0008,
	Normals		=	0x0010,
	Contacts	=	0x0020,
	Anchors		=	0x0040,
	Notes		=	0x0080,
	Clusters	=	0x0100,
	NodeTree	=	0x0200,
	FaceTree	=	0x0400,
	ClusterTree	=	0x0800,
	Joints		=	0x1000,
	Std			=	Links+Faces+Tetras+Anchors+Notes+Joints,
	StdTetra	=	Std-Faces+Tetras*/
	world->setDrawFlags(fDrawFlags::Links | fDrawFlags::Normals | fDrawFlags::Joints | fDrawFlags::Anchors | fDrawFlags::Contacts | fDrawFlags::Faces );


}
Example #16
0
//-----------------------------------
void CollisionManager::init()
{
       
	m_pCollisionConfig = new btDefaultCollisionConfiguration();
	
	///the maximum size of the collision world. Make sure objects stay within these boundaries
	///Don't make the world AABB size too large, it will harm simulation quality and performance
	btVector3 worldAabbMin(-10000,-10000,-10000);
	btVector3 worldAabbMax(10000,10000,10000);
	m_pBroadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,MAX_PROXIES);
	m_pCollisionDispatcher = new btCollisionDispatcher(m_pCollisionConfig);
	m_pConstraintSolver = new btSequentialImpulseConstraintSolver;
	m_pDynamicsWorld = new btDiscreteDynamicsWorld(m_pCollisionDispatcher,m_pBroadphase,m_pConstraintSolver,m_pCollisionConfig);
	m_pDynamicsWorld->setGravity(btVector3(0,0,0));

}
Example #17
0
btDynamicsWorld * initPhysics()
{
    btDefaultCollisionConfiguration * collisionConfiguration = new btDefaultCollisionConfiguration();
    btCollisionDispatcher * dispatcher = new btCollisionDispatcher( collisionConfiguration );
    btConstraintSolver * solver = new btSequentialImpulseConstraintSolver;

    btVector3 worldAabbMin( -10000, -10000, -10000 );// 进行aabb算法的范围?
    btVector3 worldAabbMax( 10000, 10000, 10000 );
    btBroadphaseInterface * inter = new btAxisSweep3( worldAabbMin, worldAabbMax, 1000 );//采用的碰撞检测算法

    btDynamicsWorld * dynamicsWorld = new btDiscreteDynamicsWorld( dispatcher, inter, solver, collisionConfiguration );

    dynamicsWorld->setGravity( btVector3( 0, 0, -10 ) );

    return( dynamicsWorld );
}
void ChainBtDynamics::initPhysics()
{
	// Setup the basic world
	m_collisionConfiguration = new btDefaultCollisionConfiguration();
    
	m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
    
	btVector3 worldAabbMin(-10000,-10000,-10000);
	btVector3 worldAabbMax(10000,10000,10000);
	m_broadphase = new btAxisSweep3 (worldAabbMin, worldAabbMax);
    
	m_solver = new btSequentialImpulseConstraintSolver;
    
	m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
    //m_dynamicsWorld->setGravity(btVector3(0.0f, -9.8f*GRAVITY_SCALE, 0.0f));
    //m_dynamicsWorld->setGravity(btVector3(0.0f, 0.1f*GRAVITY_SCALE, 0.0f));
    //m_dynamicsWorld->setGravity(btVector3(0.0f, -3.0f*GRAVITY_SCALE, 0.0f));
    m_dynamicsWorld->setGravity(btVector3(0.0f, 0.00f*GRAVITY_SCALE, 0.0f));
	//m_dynamicsWorld->getDispatchInfo().m_useConvexConservativeDistanceUtil = true;
	//m_dynamicsWorld->getDispatchInfo().m_convexConservativeDistanceThreshold = 0.01f;
    

	// Setup a big ground box
    //{
    //    //btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(1.5),btScalar(0.1),btScalar(1.5)));
    //    
    //    btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(3000.0f),
    //                                                             btScalar(600.0f),
    //                                                             btScalar(3000.0f)));
    //    m_collisionShapes.push_back(groundShape);
    //    btTransform groundTransform;
    //    groundTransform.setIdentity();
    //    //groundTransform.setOrigin(btVector3(0,-10,0));
    //    groundTransform.setOrigin(btVector3(0,-600.0f,0));
    //    
    //    btCollisionObject* fixedGround = new btCollisionObject();
    //    fixedGround->setCollisionShape(groundShape);
    //    fixedGround->setWorldTransform(groundTransform);
    //    m_groundInfo.isGround = true;
    //    fixedGround->setUserPointer(&m_groundInfo);
    //    
    //    m_dynamicsWorld->addCollisionObject(fixedGround);
    //}
    btVector3 startOffset(0,100,0);

	clientResetScene();
}
BulletPhysics::BulletPhysics(double configGravity[3],osgOcean::OceanTechnique* oceanSurf,PhysicsWater physicsWater) {
    collisionConfiguration = new btHfFluidRigidCollisionConfiguration();
    dispatcher = new btCollisionDispatcher( collisionConfiguration );
    solver = new btSequentialImpulseConstraintSolver();

    btVector3 worldAabbMin( -10000, -10000, -10000 );
    btVector3 worldAabbMax( 10000, 10000, 10000 );
    inter = new btAxisSweep3( worldAabbMin, worldAabbMax, 1000 );

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

    btVector3 gravity(configGravity[0],configGravity[1],configGravity[2]);
    if(configGravity[0]==0 && configGravity[1]==0 && configGravity[2]==0){
      gravity=UWSIM_DEFAULT_GRAVITY;
    }

    dynamicsWorld->setGravity( gravity);
    oceanSurface=oceanSurf;

    if(physicsWater.enable){

    	fluid = new btHfFluid (physicsWater.resolution, physicsWater.size[0], physicsWater.size[1],physicsWater.size[2], physicsWater.size[3],physicsWater.size[4] , physicsWater.size[5]);
    	//fluid = new btHfFluid (btScalar(0.25), 100,100);
    	btTransform xform;
    	xform.setIdentity ();
    	xform.getOrigin() = btVector3(physicsWater.position[0], physicsWater.position[1], physicsWater.position[2]);
    	//xform.setRotation(btQuaternion(0,1.57,0));
    	fluid->setWorldTransform (xform);
    	fluid->setHorizontalVelocityScale (btScalar(0.0f));
    	fluid->setVolumeDisplacementScale (btScalar(0.0f));
    	dynamicsWorld->addHfFluid (fluid);

	for (int i = 0; i < fluid->getNumNodesLength()*fluid->getNumNodesWidth(); i++){
		fluid->setFluidHeight(i, btScalar(0.0f));
     	}

     	fluid->prep ();
    }
    else
	fluid=NULL;
    /*debugDrawer.setDebugMode(btIDebugDraw::DBG_DrawContactPoints|| btIDebugDraw::DBG_DrawWireframe || btIDebugDraw::DBG_DrawText);
    dynamicsWorld->setDebugDrawer(&debugDrawer);
    debugDrawer.BeginDraw();
    debugDrawer.setEnabled(true);*/
}
Example #20
0
// init
void MBulletContext::init(const MVector3 & worldMin, const MVector3 & worldMax)
{
	clear();

	m_collisionConfiguration = new btDefaultCollisionConfiguration();
	m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);

	int	maxProxies = 1024;
	btVector3 worldAabbMin(worldMin.x, worldMin.y, worldMin.z);
	btVector3 worldAabbMax(worldMax.x, worldMax.y, worldMax.z);
	//m_overlappingPairCache = new btAxisSweep3(worldAabbMin, worldAabbMax, maxProxies);
	m_overlappingPairCache = new btDbvtBroadphase();
	
	m_solver = new btSequentialImpulseConstraintSolver();
	m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher, m_overlappingPairCache, m_solver, m_collisionConfiguration);
	m_dynamicsWorld->setGravity(btVector3(0,0,-10));
}
void	CollisionInterfaceDemo::initPhysics()
{
			
	m_debugMode |= btIDebugDraw::DBG_DrawWireframe;
	
	btMatrix3x3 basisA;
	basisA.setIdentity();

	btMatrix3x3 basisB;
	basisB.setIdentity();

	objects[0].getWorldTransform().setBasis(basisA);
	objects[1].getWorldTransform().setBasis(basisB);

	btBoxShape* boxA = new btBoxShape(btVector3(1,1,1));
	boxA->setMargin(0.f);

	btBoxShape* boxB = new btBoxShape(btVector3(0.5,0.5,0.5));
	boxB->setMargin(0.f);
	//ConvexHullShape	hullA(points0,3);
	//hullA.setLocalScaling(btVector3(3,3,3));
	//ConvexHullShape	hullB(points1,4);
	//hullB.setLocalScaling(btVector3(4,4,4));

	objects[0].setCollisionShape(boxA);//&hullA;
	objects[1].setCollisionShape(boxB);//&hullB;

	btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
	btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
	btVector3	worldAabbMin(-1000,-1000,-1000);
	btVector3	worldAabbMax(1000,1000,1000);

	btAxisSweep3*	broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);
	
	//SimpleBroadphase is a brute force alternative, performing N^2 aabb overlap tests
	//SimpleBroadphase*	broadphase = new btSimpleBroadphase;

	collisionWorld = new btCollisionWorld(dispatcher,broadphase,collisionConfiguration);
	collisionWorld->setDebugDrawer(&debugDrawer);
		
#ifdef TEST_NOT_ADDING_OBJECTS_TO_WORLD
//	collisionWorld->addCollisionObject(&objects[0]);
	collisionWorld->addCollisionObject(&objects[1]);
#endif //TEST_NOT_ADDING_OBJECTS_TO_WORLD

}
Example #22
0
void ConvexDecompositionDemo::setupEmptyDynamicsWorld()
{
m_collisionConfiguration = new btDefaultCollisionConfiguration();


#ifdef USE_PARALLEL_DISPATCHER
#ifdef USE_WIN32_THREADING

	int maxNumOutstandingTasks = 4;//number of maximum outstanding tasks
	Win32ThreadSupport* threadSupport = new Win32ThreadSupport(Win32ThreadSupport::Win32ThreadConstructionInfo(
								"collision",
								processCollisionTask,
								createCollisionLocalStoreMemory,
								maxNumOutstandingTasks));
#else
///@todo other platform threading
///Playstation 3 SPU (SPURS)  version is available through PS3 Devnet
///Libspe2 SPU support will be available soon
///pthreads version
///you can hook it up to your custom task scheduler by deriving from btThreadSupportInterface
#endif

	m_dispatcher = new	SpuGatheringCollisionDispatcher(threadSupport,maxNumOutstandingTasks,m_collisionConfiguration);
#else
	m_dispatcher = new	btCollisionDispatcher(m_collisionConfiguration);
#endif//USE_PARALLEL_DISPATCHER

	gCompoundChildShapePairCallback = MyCompoundChildShapeCallback;

	convexDecompositionObjectOffset.setValue(10,0,0);

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

	m_broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);
	//m_broadphase = new btSimpleBroadphase();

	m_solver = new btSequentialImpulseConstraintSolver();
	m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);

#ifdef USE_PARALLEL_DISPATCHER
	m_dynamicsWorld->getDispatchInfo().m_enableSPU = true;
#endif //USE_PARALLEL_DISPATCHER

}
Example #23
0
Physics::Physics() {
	body_max_ = 16384; /* Maximum number of rigid bodies */

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

	broadphase_ = new btAxisSweep3(worldAabbMin,worldAabbMax,body_max_);
	collisionConfiguration_ = new btDefaultCollisionConfiguration();
	dispatcher_ = new btCollisionDispatcher(collisionConfiguration_);
	solver_ = new btSequentialImpulseConstraintSolver;

	dynamicsWorld_ = new btDiscreteDynamicsWorld(dispatcher_,
					broadphase_, solver_, collisionConfiguration_);
	setGravity(GRAVITY_EARTH);

	//gDebugDrawer_.setDebugMode(1);
	//dynamicsWorld_->setDebugDrawer(&gDebugDrawer_);
	body_count_ = 0;
}
Example #24
0
void BulletSoftObject::init() {
    btDefaultCollisionConfiguration* m_collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();
    btCollisionDispatcher* m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
    getEnvironment()->bullet->dispatcher = m_dispatcher;
	btVector3 worldAabbMin(-1000,-1000,-1000);
	btVector3 worldAabbMax(1000,1000,1000);

	btBroadphaseInterface* m_broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,32766);

	getEnvironment()->bullet->broadphase = m_broadphase;

	btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver();

	getEnvironment()->bullet->solver = solver;

	//btSoftRigidDynamicsWorld* world = new btSoftRigidDynamicsWorld(m_dispatcher,m_broadphase,solver,m_collisionConfiguration);
	//getEnvironment()->bullet->dynamicsWorld = world;
	//m_dynamicsWorld->setInternalTickCallback(pickingPreTickCallback,this,true);


	//getEnvironment()->bullet->dynamicsWorld->getDispatchInfo().m_enableSPU = true;
	//getEnvironment()->bullet->dynamicsWorld->setGravity(btVector3(0,0,-10));
	//m_softBodyWorldInfo.m_gravity.setValue(0,-10,0);

    getEnvironment()->bullet->dynamicsWorld->addSoftBody(softBody.get());

    vertices = new osg::Vec3Array;
    normals = new osg::Vec3Array;
    geom = new osg::Geometry;
    geom->setDataVariance(osg::Object::DYNAMIC);
    geom->setUseDisplayList(false);
    geom->setUseVertexBufferObjects(true);
    geom->setVertexArray(vertices.get());
    geom->setNormalArray(normals.get());
    geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);

    osg::ref_ptr<osg::Geode> geode = new osg::Geode;
    geode->addDrawable(geom);
    transform = new osg::MatrixTransform;
    transform->addChild(geode);
    getEnvironment()->osg->root->addChild(transform);
}
Example #25
0
void Simulation::initPhysics()
{
  // setup the ANN
  ANN* neuralNet = new ANN();
  neuralNet->loadXML();
  
  // Setup the basic world
  m_collisionConfiguration = new btDefaultCollisionConfiguration();

  m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);

  btVector3 worldAabbMin(-10000,-10000,-10000);
  btVector3 worldAabbMax(10000,10000,10000);
  m_broadphase = new btAxisSweep3 (worldAabbMin, worldAabbMax);

  m_solver = new btSequentialImpulseConstraintSolver;

  m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase,
                                                m_solver,m_collisionConfiguration);
  
  //tick = 0;
  m_dynamicsWorld->setInternalTickCallback(robotPreTickCallback, this, true);
  
  // Setup a big ground box
  {
    btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(200.),
                                                             btScalar(10.),btScalar(200.)));
    m_collisionShapes.push_back(groundShape);
    btTransform groundTransform;
    groundTransform.setIdentity();
    groundTransform.setOrigin(btVector3(0,-10,0));

    btCollisionObject* fixedGround = new btCollisionObject();
    fixedGround->setCollisionShape(groundShape);
    fixedGround->setWorldTransform(groundTransform);
    m_dynamicsWorld->addCollisionObject(fixedGround);
  }

  // Spawn one ragdoll
  btVector3 startOffset(1,0.5,0);
  spawnRagdoll(startOffset);
}
Example #26
0
// Bullet engine initialisation
btDynamicsWorld* Scene::initBulletEngine()
{
    btDefaultCollisionConfiguration * collisionConfiguration = new btDefaultCollisionConfiguration();
    btCollisionDispatcher * dispatcher = new btCollisionDispatcher( collisionConfiguration );
    btConstraintSolver * solver = new btSequentialImpulseConstraintSolver;
    solver->reset();

    // Anything outside this area won't be taken into account by bullet
    btVector3 worldAabbMin( -10000, -10000, -10000 );
    btVector3 worldAabbMax( 10000, 10000, 10000 );
    btBroadphaseInterface * inter = new btAxisSweep3( worldAabbMin, worldAabbMax, 1000 );

    // You can now use: dynamicsWorld->addRigidBody( btRigidBody ); to add an object the simulation
    btDynamicsWorld * dynamicsWorld = new btDiscreteDynamicsWorld( dispatcher, inter, solver, collisionConfiguration );

    dynamicsWorld->getPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
    dynamicsWorld->setGravity( btVector3( 0, 0, -250 ) );

    return( dynamicsWorld );
}
Example #27
0
int main(int argc,char** argv)
{
	clientResetScene();

	SimdMatrix3x3 basisA;
	basisA.setIdentity();

	SimdMatrix3x3 basisB;
	basisB.setIdentity();

	objects[0].m_worldTransform.setBasis(basisA);
	objects[1].m_worldTransform.setBasis(basisB);

	SimdPoint3	points0[3]={SimdPoint3(1,0,0),SimdPoint3(0,1,0),SimdPoint3(0,0,1)};
	SimdPoint3	points1[5]={SimdPoint3(1,0,0),SimdPoint3(0,1,0),SimdPoint3(0,0,1),SimdPoint3(0,0,-1),SimdPoint3(-1,-1,0)};
	
	BoxShape boxA(SimdVector3(1,1,1));
	BoxShape boxB(SimdVector3(0.5,0.5,0.5));
	//ConvexHullShape	hullA(points0,3);
	//hullA.setLocalScaling(SimdVector3(3,3,3));
	//ConvexHullShape	hullB(points1,4);
	//hullB.setLocalScaling(SimdVector3(4,4,4));


	objects[0].m_collisionShape = &boxA;//&hullA;
	objects[1].m_collisionShape = &boxB;//&hullB;

	CollisionDispatcher dispatcher;
	//SimpleBroadphase	broadphase;
	SimdVector3	worldAabbMin(-1000,-1000,-1000);
	SimdVector3	worldAabbMax(1000,1000,1000);

	AxisSweep3	broadphase(worldAabbMin,worldAabbMax);

	collisionWorld = new CollisionWorld(&dispatcher,&broadphase);
	
	collisionWorld->AddCollisionObject(&objects[0]);
	collisionWorld->AddCollisionObject(&objects[1]);

	return glutmain(argc, argv,screenWidth,screenHeight,"Collision Interface Demo");
}
Example #28
0
File: init.cpp Project: pzsz/mold
BB_World* BB_NewWorld() {
  BB_World* ret = new BB_World();

  ret->collisionConfiguration = new btDefaultCollisionConfiguration();
  ret->dispatcher = new btCollisionDispatcher(ret->collisionConfiguration);

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

  ret->broadphase = new btAxisSweep3(worldAabbMin, worldAabbMax);

  ret->solver = new btSequentialImpulseConstraintSolver();
  ret->dynamicsWorld = 
    new btDiscreteDynamicsWorld(
				ret->dispatcher, 
				ret->broadphase,
				ret->solver, 
				ret->collisionConfiguration);  

  ret->broadphase->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
  return ret;
}
void GenericJointDemo::initPhysics()
{
    setTexturing(true);
    setShadows(true);

    // Setup the basic world

    btDefaultCollisionConfiguration * collision_config = new btDefaultCollisionConfiguration();

    btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collision_config);

    btVector3 worldAabbMin(-10000,-10000,-10000);
    btVector3 worldAabbMax(10000,10000,10000);
    btBroadphaseInterface* overlappingPairCache = new btAxisSweep3 (worldAabbMin, worldAabbMax);

    btConstraintSolver* constraintSolver = new btSequentialImpulseConstraintSolver;

    m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,overlappingPairCache,constraintSolver,collision_config);

    m_dynamicsWorld->setGravity(btVector3(0,-10,0));

    m_dynamicsWorld->setDebugDrawer(&debugDrawer);

    //m_dynamicsWorld->getSolverInfo().m_restingContactRestitutionThreshold = 0.f; //   m_singleAxisRollingFrictionThreshold = 0.f;//faster but lower quality

    // Setup a big ground box
    {
        btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(200.),btScalar(0.),btScalar(200.))); //! 0 thickness
        btTransform groundTransform;
        groundTransform.setIdentity();
        groundTransform.setOrigin(btVector3(0,-8,0));
        m_ground = localCreateRigidBody(btScalar(0.),groundTransform,groundShape);
    }

    Swing* swing1 = new Swing( m_dynamicsWorld, btVector3(0,9,0), 4.0f, m_ground );
    Swing* swing2 = new Swing( m_dynamicsWorld, btVector3(4,9,0), 4.0f, m_ground );

    clientResetScene();
}
Example #30
0
void GenericJointDemo::initPhysics()
{
	setTexturing(true);
	setShadows(true);

	// Setup the basic world

	btDefaultCollisionConfiguration * collision_config = new btDefaultCollisionConfiguration();

	btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collision_config);

	btVector3 worldAabbMin(-10000,-10000,-10000);
	btVector3 worldAabbMax(10000,10000,10000);
	btBroadphaseInterface* overlappingPairCache = new btAxisSweep3 (worldAabbMin, worldAabbMax);

	btConstraintSolver* constraintSolver = new btSequentialImpulseConstraintSolver;


	m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,overlappingPairCache,constraintSolver,collision_config);

	m_dynamicsWorld->setGravity(btVector3(0,-30,0));

	m_dynamicsWorld->setDebugDrawer(&debugDrawer);

	// Setup a big ground box
	{
		btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(200.),btScalar(10.),btScalar(200.)));
		btTransform groundTransform;
		groundTransform.setIdentity();
		groundTransform.setOrigin(btVector3(0,-15,0));
		localCreateRigidBody(btScalar(0.),groundTransform,groundShape);
	}

	// Spawn one ragdoll
	spawnRagdoll();

	clientResetScene();
}