Esempio n. 1
0
void physics_simulate()
{
	PfxPerfCounter pc;

	for(int i=1;i<numRigidBodies;i++) {
		pfxApplyExternalForce(states[i],bodies[i],bodies[i].getMass()*PfxVector3(0.0f,-9.8f,0.0f),PfxVector3(0.0f),timeStep);
	}
	
	perf_push_marker("broadphase");
	pc.countBegin("broadphase");
	broadphase();
	pc.countEnd();
	perf_pop_marker();
	
	perf_push_marker("collision");
	pc.countBegin("collision");
	collision();
	pc.countEnd();
	perf_pop_marker();
	
	perf_push_marker("solver");
	pc.countBegin("solver");
	constraintSolver();
	pc.countEnd();
	perf_pop_marker();
	
	perf_push_marker("sleepCheck");
	pc.countBegin("sleepCheck");
	sleepOrWakeup();
	pc.countEnd();
	perf_pop_marker();
	
	perf_push_marker("integrate");
	pc.countBegin("integrate");
	integrate();
	pc.countEnd();
	perf_pop_marker();

	perf_push_marker("castRays");
	pc.countBegin("castRays");
	castRays();
	pc.countEnd();
	perf_pop_marker();
	
	frame++;
	
	if(frame%100 == 0) {
		float broadphaseTime  = pc.getCountTime(0);
		float collisionTime   = pc.getCountTime(2);
		float solverTime      = pc.getCountTime(4);
		float sleepTime		  = pc.getCountTime(6);
		float integrateTime   = pc.getCountTime(8);
		float raycastTime     = pc.getCountTime(10);
		SCE_PFX_PRINTF("frame %3d broadphase %.2f collision %.2f solver %.2f sleepCheck %.2f integrate %.2f raycast %.2f | total %.2f\n",frame,
			broadphaseTime,collisionTime,solverTime,sleepTime,integrateTime,raycastTime,
			broadphaseTime+collisionTime+solverTime+sleepTime+integrateTime+raycastTime);
	}
}
Esempio n. 2
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");
}
Esempio n. 3
0
void physics_simulate()
{
	BT_PROFILE("physics_simulate");

	PfxPerfCounter pc;

	for(int i=1;i<numRigidBodies;i++) {
		pfxApplyExternalForce(states[i],bodies[i],bodies[i].getMass()*PfxVector3(0.0f,-9.8f,0.0f),PfxVector3(0.0f),timeStep);
	}
	
//	perf_push_marker("broadphase");
//	pc.countBegin("broadphase");

	{
		BT_PROFILE("broadphase");
		broadphase();
	}
//	
//pc.countEnd();
//	perf_pop_marker();
	
//	perf_push_marker("collision");
//	pc.countBegin("collision");
	{
		BT_PROFILE("collision");
		collision();
	}
//	pc.countEnd();
//	perf_pop_marker();
	
//	perf_push_marker("solver");
//	pc.countBegin("solver");
	{
		BT_PROFILE("constraintSolver");
		constraintSolver();
		if (!peSolverEnabled)
			BulletConstraintSolver();
			

	}
//	pc.countEnd();
//	perf_pop_marker();
	
//	perf_push_marker("integrate");
//	pc.countBegin("integrate");
	{
		BT_PROFILE("integrate");
		integrate();
	}
//	pc.countEnd();
//	perf_pop_marker();
	
	frame++;
	
	if (0)////if(frame%100 == 0)
	{
		float broadphaseTime = pc.getCountTime(0);
		float collisionTime  = pc.getCountTime(2);
		float solverTime     = pc.getCountTime(4);
		float integrateTime  = pc.getCountTime(6);
		SCE_PFX_PRINTF("#pairs = %d, #contacts = %d\n", curNumPairs, curTotalContacts);

		SCE_PFX_PRINTF("frame %3d broadphase %.2f collision %.2f solver %.2f integrate %.2f | total %.2f\n",frame,
			broadphaseTime,collisionTime,solverTime,integrateTime,
			broadphaseTime+collisionTime+solverTime+integrateTime);


	}
}
Esempio n. 4
0
int main(int argc, char** argv) {
        sf::RenderWindow* RenderWin = new sf::RenderWindow(sf::VideoMode(WIDTH, HEIGHT, 32), "lol test");
        RenderWin->UseVerticalSync(true);

        // Collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration.
		boost::shared_ptr<btDefaultCollisionConfiguration> collisionConfiguration(new btDefaultCollisionConfiguration());

        // Use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded).
		boost::shared_ptr<btCollisionDispatcher> dispatcher(new btCollisionDispatcher(collisionConfiguration.get()));

        // btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep.
		boost::shared_ptr<btBroadphaseInterface> broadphase(new btDbvtBroadphase());

        // The default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded).

		boost::shared_ptr<btVoronoiSimplexSolver> simplex(new btVoronoiSimplexSolver());
		boost::shared_ptr<btMinkowskiPenetrationDepthSolver> pd_solver(new btMinkowskiPenetrationDepthSolver());
		boost::shared_ptr<btSequentialImpulseConstraintSolver> solver(new btSequentialImpulseConstraintSolver());

		boost::shared_ptr<btDiscreteDynamicsWorld> dynamicsWorld(new btDiscreteDynamicsWorld(dispatcher.get(), broadphase.get(), solver.get(), collisionConfiguration.get()));

		boost::shared_ptr<btConvex2dConvex2dAlgorithm::CreateFunc> convex_algo_2d(new btConvex2dConvex2dAlgorithm::CreateFunc(simplex.get(),pd_solver.get()));
		
		dispatcher->registerCollisionCreateFunc(CONVEX_2D_SHAPE_PROXYTYPE,CONVEX_2D_SHAPE_PROXYTYPE, convex_algo_2d.get());
		dispatcher->registerCollisionCreateFunc(BOX_2D_SHAPE_PROXYTYPE,CONVEX_2D_SHAPE_PROXYTYPE, convex_algo_2d.get());
		dispatcher->registerCollisionCreateFunc(CONVEX_2D_SHAPE_PROXYTYPE,BOX_2D_SHAPE_PROXYTYPE, convex_algo_2d.get());
		dispatcher->registerCollisionCreateFunc(BOX_2D_SHAPE_PROXYTYPE,BOX_2D_SHAPE_PROXYTYPE, new btBox2dBox2dCollisionAlgorithm::CreateFunc());

        // Set gravity to 9.8m/s² along y-axis.
        dynamicsWorld->setGravity(btVector3(0, 1, 0));

        // Get us some debug output. Without this, we'd see nothing at all.
		boost::shared_ptr<DebugDraw> debugDraw(new DebugDraw(RenderWin));
        debugDraw->setDebugMode(btIDebugDraw::DBG_DrawWireframe);

        dynamicsWorld->setDebugDrawer(debugDraw.get());

        // Keep track of the shapes, we release memory at exit.
        // Make sure to re-use collision shapes among rigid bodies whenever possible!
        btAlignedObjectArray<btCollisionShape*> collisionShapes;

        // Create a ground body.
        btScalar thickness(0.2);
		boost::shared_ptr<btCollisionShape> groundShape(new btBoxShape(btVector3(btScalar(WIDTH / 2 * METERS_PER_PIXEL), thickness, btScalar(10))));
        collisionShapes.push_back(groundShape.get());
        btTransform groundTransform(btQuaternion(0, 0, 0, 1), btVector3(WIDTH / 2 * METERS_PER_PIXEL, HEIGHT * METERS_PER_PIXEL, 0));
        // Using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects.
		boost::shared_ptr<btDefaultMotionState> groundMotionState(new btDefaultMotionState(groundTransform));
        btRigidBody::btRigidBodyConstructionInfo ground_rbInfo(0, groundMotionState.get(), groundShape.get(), btVector3(0, 0, 0));
		boost::shared_ptr<btRigidBody> ground_body(new btRigidBody(ground_rbInfo));
		ground_body->setLinearFactor(btVector3(1,1,0));
		ground_body->setAngularFactor(btVector3(0,0,1));
        // Add the body to the dynamics world.
        dynamicsWorld->addRigidBody(ground_body.get());

        // Create left wall.
        btTransform leftWallTransform(btQuaternion(0, 0, 1, 1), btVector3(0, HEIGHT / 2 * METERS_PER_PIXEL, 0));
		boost::shared_ptr<btDefaultMotionState> leftWallMotionState(new btDefaultMotionState(leftWallTransform));
        btRigidBody::btRigidBodyConstructionInfo leftWall_rbInfo(0, leftWallMotionState.get(), groundShape.get(), btVector3(0, 0, 0));
		boost::shared_ptr<btRigidBody> leftwall_body(new btRigidBody(leftWall_rbInfo));
		leftwall_body->setLinearFactor(btVector3(1,1,0));
		leftwall_body->setAngularFactor(btVector3(0,0,1));
        // Add the body to the dynamics world.
        dynamicsWorld->addRigidBody(leftwall_body.get());

        // Create right wall.
        btTransform rightWallTransform(btQuaternion(0, 0, 1, 1), btVector3(WIDTH * METERS_PER_PIXEL, HEIGHT / 2 * METERS_PER_PIXEL, 0));
		boost::shared_ptr<btDefaultMotionState> rightWallMotionState(new btDefaultMotionState(rightWallTransform));
        btRigidBody::btRigidBodyConstructionInfo rightWall_rbInfo(0, rightWallMotionState.get(), groundShape.get(), btVector3(0, 0, 0));
		boost::shared_ptr<btRigidBody> rightwall_body(new btRigidBody(rightWall_rbInfo));
		rightwall_body->setLinearFactor(btVector3(1,1,0));
		rightwall_body->setAngularFactor(btVector3(0,0,1));
        // Add the body to the dynamics world.
        dynamicsWorld->addRigidBody(rightwall_body.get());

        // Create ceiling
        btTransform topWallTransform(btQuaternion(0, 0, 0, 1), btVector3(WIDTH / 2 * METERS_PER_PIXEL, 0, 0));
		boost::shared_ptr<btDefaultMotionState> topWallMotionState(new btDefaultMotionState(topWallTransform));
        btRigidBody::btRigidBodyConstructionInfo topWall_rbInfo(0, topWallMotionState.get(), groundShape.get(), btVector3(0, 0, 0));
		boost::shared_ptr<btRigidBody> topwall_body(new btRigidBody(topWall_rbInfo));
		topwall_body->setLinearFactor(btVector3(1,1,0));
		topwall_body->setAngularFactor(btVector3(0,0,1));
        // Add the body to the dynamics world.
        dynamicsWorld->addRigidBody(topwall_body.get());


        // Create dynamic rigid body.

        //btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));
		boost::shared_ptr<btCollisionShape> colShape(new btSphereShape(btScalar(0.6)));
        collisionShapes.push_back(colShape.get());

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

        btScalar mass(1.f);

        //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)
                colShape->calculateLocalInertia(mass,localInertia);

        startTransform.setOrigin(btVector3(2, 5, 0));

        //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
		boost::shared_ptr<btDefaultMotionState> myMotionState(new btDefaultMotionState(startTransform));
        btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState.get(),colShape.get(),localInertia);
		boost::shared_ptr<btRigidBody> body(new btRigidBody(rbInfo));
		body->setLinearFactor(btVector3(1,1,0));
		body->setAngularFactor(btVector3(0,0,1));

        dynamicsWorld->addRigidBody(body.get());

		// Create lulz
		boost::ptr_list<btRigidBody> body_list;
		boost::ptr_list<btDefaultMotionState> motionstate_list;
		boost::ptr_list<btCollisionShape> colshape_list;
		for (int i=0;i <= 10; ++i) {
			if (i < 5)
				colshape_list.push_back(new btSphereShape(btScalar(sf::Randomizer::Random(0.1f, 0.8f))));
			else
				colshape_list.push_back(new btBoxShape(btVector3(sf::Randomizer::Random(0.1f,0.8f), sf::Randomizer::Random(0.1f,0.8f), 10)));
			if (isDynamic)
                colshape_list.back().calculateLocalInertia(mass,localInertia);
			collisionShapes.push_back(&(colshape_list.back()));
			startTransform.setIdentity();
			startTransform.setOrigin(btVector3(i,i,0));
			motionstate_list.push_back(new btDefaultMotionState(startTransform));
			btRigidBody* lol = new btRigidBody(btRigidBody::btRigidBodyConstructionInfo(mass,&(motionstate_list.back()),&(colshape_list.back()),localInertia));
			lol->setLinearFactor(btVector3(1,1,0));
			lol->setAngularFactor(btVector3(0,0,1));
            body_list.push_back(lol);
		}
		BOOST_FOREACH (btRigidBody& body, body_list) {
			dynamicsWorld->addRigidBody(&body);
		}