Exemplo n.º 1
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();		
}
Exemplo n.º 2
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();		
}
Exemplo n.º 3
0
void GenericJointDemo::keyboardCallback(unsigned char key, int x, int y)
{
	switch (key)
	{
	case 'e':
		spawnRagdoll(true);
		break;
	default:
		DemoApplication::keyboardCallback(key, x, y);
	}


}
Exemplo n.º 4
0
void SimulationVisual::keyboardCallback(unsigned char key, int x, int y)
{
  switch (key)
    {
    case 'e':
      {
        btVector3 startOffset(0,2,0);
        spawnRagdoll(startOffset);
        break;
      }
    default:
      GlutDemoApplication::keyboardCallback(key, x, y);
    }	
}
Exemplo n.º 5
0
void RagdollDemo::keyboardCallback(unsigned char key, int x, int y)
{
	switch (key)
	{
	case 'e':
		{
		btVector3 startOffset(0,2,0);
		spawnRagdoll(startOffset);
		break;
		}
	default:
		DemoApplication::keyboardCallback(key, x, y);
	case 'p':
		{
			if(pause)
				pause = FALSE;
			else
				pause = TRUE;
		}
	case 'o':
		{
			if(oneStep)
			{
				oneStep = FALSE;
			}
			else
			{
				oneStep = TRUE;	
			}
		}
	case 'z':
		{
			//cout << "SIZE: " << sizeof(collisionID)/sizeof(collisionID[0]) << endl;
			
			for(int i = 0; i < sizeof(collisionID)/sizeof(collisionID[0]); i++)
			{
				/*
				cout << i << ": " << collisionID[i]->id;
				cout << " | ADDRESS: " << collisionID[i];
				cout << " | HIT: " << collisionID[i]->hit;
				cout << " | Colliosion Flags: " << collisionID[i]->body->getCollisionFlags() << endl;
				*/
			}
			
		}		
	}

	
}
Exemplo n.º 6
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);
}
Exemplo n.º 7
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();
}
void RagdollDemo::keyboardCallback(unsigned char key, int x, int y)
{
	switch (key)
	{
    case 'p':
      pause = !pause;
      break;
    case 'o':
      oneStep = true;
      break;

	case 'e':
		{
		btVector3 startOffset(0,2,0);
		spawnRagdoll(startOffset);
		break;
		}
	default:
		DemoApplication::keyboardCallback(key, x, y);
	}

	
}
void	BasicDemo::initPhysics()
{

	

	setTexturing(true);
	setShadows(true);

	setCameraDistance(btScalar(40));

	///collision configuration contains default setup for memory, collision setup
	m_collisionConfiguration = new btDefaultCollisionConfiguration();
	//m_collisionConfiguration->setConvexConvexMultipointIterations();

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

	m_broadphase = new btDbvtBroadphase();

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

	m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
	m_dynamicsWorld->setDebugDrawer(&gDebugDraw);
	
	m_dynamicsWorld->setGravity(btVector3(0,-10,0));

	///create a few basic rigid bodies
	btBoxShape* groundShape = new btBoxShape(btVector3(btScalar(500.),btScalar(50.),btScalar(500.)));
	//groundShape->initializePolyhedralFeatures();
//	btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50);
	
	m_collisionShapes.push_back(groundShape);

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

	//We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
	{
		btScalar mass(0.);

		//rigidbody is dynamic if and only if mass is non zero, otherwise static
		bool isDynamic = (mass != 0.f);

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

		//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
		btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
		btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
		btRigidBody* body = new btRigidBody(rbInfo);

		

		//add the body to the dynamics world
		m_dynamicsWorld->addRigidBody(body);
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	///////////// Setting the sphere //////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////////////////
	{
		btCollisionShape* sphereShape = new btSphereShape(4.5f);
		m_collisionShapes.push_back(sphereShape);

		btTransform startTransform;
		startTransform.setIdentity();

		btScalar mass(500.0f);

		bool isDynamic = (mass != 0.0f);

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

		startTransform.setOrigin(btVector3(
			btScalar(-1),
			btScalar(((btSphereShape*)sphereShape)->getRadius()),
			btScalar(-35)
			));

		btDefaultMotionState* motionState = new btDefaultMotionState(startTransform);
		btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, motionState,sphereShape,localInertia);
		btRigidBody* body = new btRigidBody(rbInfo);

		body->applyCentralImpulse(btVector3(0,0,120000));
		body->applyTorqueImpulse(btVector3(200,0,0));
		m_dynamicsWorld->addRigidBody(body);
		m_sphere = body;

	}

	

	///////////////////////////////////////////////////////////////////////////////////////////////
	/////////////// Setting the pins //////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////////////////
	{
		//create a few dynamic rigidbodies
		// Re-using the same collision is better for memory usage and performance

		btCollisionShape* shape = new btCylinderShape(btVector3(0.5f, 4, 1));
		m_collisionShapes.push_back(shape);

		/// Create Dynamic Objects
		btTransform startTransform;
		startTransform.setIdentity();

		btScalar	mass(1.5f);

		//rigidbody is dynamic if and only if mass is non zero, otherwise static
		bool isDynamic = (mass != 0.f);

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

		const btVector3 origin = btVector3(0,1,0);
		const float zdiff = 1.0f;
		const float xdiff = 1.0f;

		for (int rowNumber = 0; rowNumber < LENGTH_OF_CONE; rowNumber++)
		{
			for (int cylinderInRow = 0; cylinderInRow <= rowNumber; cylinderInRow++)
			{
				startTransform.setOrigin(btVector3(
					btScalar(origin.getX() + ((cylinderInRow * xdiff * 2) - (xdiff * (rowNumber)))),
					btScalar(4),
					btScalar(rowNumber*zdiff + origin.getZ())
					));

				spawnRagdoll(startTransform.getOrigin());

				//btDefaultMotionState* motionState = new btDefaultMotionState(startTransform);
				//btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, motionState,shape,localInertia);
				//btRigidBody* body = new btRigidBody(rbInfo);
				
				//m_dynamicsWorld->addRigidBody(body);
			}
		}
	}
}