Exemplo n.º 1
0
void PendulumApplication::buildDoublePendulumRigid()
{
    //TODO
    btTransform trans;
    trans.setIdentity();
    trans.setOrigin(btVector3(0,10,0));

    btSphereShape * sphere = new btSphereShape(1.);
    btRigidBody * pendule = localCreateRigidBody(1.,trans,sphere);
    m_cameraTarget = pendule;
    m_collisionShapes.push_back(sphere);

    btPoint2PointConstraint * constraint = new btPoint2PointConstraint (*pendule, btVector3(0,5,0));
    m_dynamicsWorld->addConstraint(constraint);
    constraint->setBreakingImpulseThreshold(5.);

    pendule->applyCentralImpulse(btVector3(3,0,0));

    ///------------------------------------------------------
    //btTransform trans2;
    //trans2.setIdentity();
    //trans2.setOrigin(btVector3(0,1,0));
    trans.setOrigin(btVector3(0,5,0));
    //btSphereShape * sphere2 = new btSphereShape(1.);
    btRigidBody * pendule2 = localCreateRigidBody(1.,trans,sphere);
    //m_collisionShapes.push_back(sphere2);
    btVector3 v = pendule->getWorldTransform().getOrigin() - trans.getOrigin();
    btPoint2PointConstraint * constraint2 = new btPoint2PointConstraint (*pendule, *pendule2, btVector3(0,0,0), v);
    m_dynamicsWorld->addConstraint(constraint2);
    constraint2->setDbgDrawSize(2.f);
}
Exemplo n.º 2
0
void PendulumApplication::buildDoublePendulumSoft()
{
    //TODO
    btTransform trans;
    trans.setIdentity();
    trans.setOrigin(btVector3(0,10,0));

    btSphereShape * sphere = new btSphereShape(1.);
    btRigidBody * pendule = localCreateRigidBody(1.,trans,sphere);
    m_cameraTarget = pendule;
    m_collisionShapes.push_back(sphere);

    btSoftBody * corde =
        btSoftBodyHelpers::CreateRope(m_softBodyWorldInfo, btVector3(0,15,0),pendule->getWorldTransform().getOrigin(),7,1);

    corde->setTotalMass(1.);
    this->getSoftDynamicsWorld()->addSoftBody(corde,1,1) ;

    //corde->appendAnchor(1,corde,false,1);
    m_corde = corde;

    corde->appendAnchor(corde->m_nodes.size()-1,pendule,btVector3(0,0.5,0),true,1);

    btVector3 beg = corde->m_nodes[0].m_x;
    btVector3 end = corde->m_nodes[corde->m_nodes.size()-1].m_x;

    m_size_corde = beg - end;


    ///------------------------------------------------------

    trans.setOrigin(btVector3(0,5,0));

    btRigidBody * pendule2 = localCreateRigidBody(1.,trans,sphere);

    btVector3 v = pendule->getWorldTransform().getOrigin() - trans.getOrigin();

    btSoftBody * corde2 =
        btSoftBodyHelpers::CreateRope(m_softBodyWorldInfo, pendule->getWorldTransform().getOrigin(),pendule2->getWorldTransform().getOrigin(),7,0);

    m_corde2 = corde2;

    beg = corde2->m_nodes[0].m_x;
    end = corde2->m_nodes[corde2->m_nodes.size()-1].m_x;

    m_size_corde2 = beg - end;

    corde2->setTotalMass(1.);
    this->getSoftDynamicsWorld()->addSoftBody(corde2,1,1) ;

    corde2->appendAnchor(0,pendule,btVector3(0,-0.5,0),true,1);

    corde2->appendAnchor(corde2->m_nodes.size()-1,pendule2,btVector3(0,0.5,0),true,1);

}
Exemplo n.º 3
0
void BenchmarkDemo::createTowerCircle(const btVector3& offsetPosition,int stackSize,int rotSize,const btVector3& boxSize)
{

	btBoxShape* blockShape = new btBoxShape(btVector3(boxSize[0]-COLLISION_RADIUS,boxSize[1]-COLLISION_RADIUS,boxSize[2]-COLLISION_RADIUS));

	btTransform trans;
	trans.setIdentity();

	float mass = 1.f;
	btVector3 localInertia(0,0,0);
	blockShape->calculateLocalInertia(mass,localInertia);


	float radius = 1.3f * rotSize * boxSize[0] / SIMD_PI;

	// create active boxes
	btQuaternion rotY(0,1,0,0);
	float posY = boxSize[1];

	for(int i=0;i<stackSize;i++) {
		for(int j=0;j<rotSize;j++) {
		

			trans.setOrigin(offsetPosition+  rotate(rotY,btVector3(0.0f , posY, radius)));
			trans.setRotation(rotY);
			localCreateRigidBody(mass,trans,blockShape);

			rotY *= btQuaternion(btVector3(0,1,0),SIMD_PI/(rotSize*btScalar(0.5)));
		}

		posY += boxSize[1] * 2.0f;
		rotY *= btQuaternion(btVector3(0,1,0),SIMD_PI/(float)rotSize);
	}
	
}
Exemplo n.º 4
0
void BenchmarkDemo::createWall(const btVector3& offsetPosition,int stackSize,const btVector3& boxSize)
{
	
	btBoxShape* blockShape = new btBoxShape(btVector3(boxSize[0]-COLLISION_RADIUS,boxSize[1]-COLLISION_RADIUS,boxSize[2]-COLLISION_RADIUS));

	float mass = 1.f;
	btVector3 localInertia(0,0,0);
	blockShape->calculateLocalInertia(mass,localInertia);

//	btScalar  diffX = boxSize[0] * 1.0f;
	btScalar  diffY = boxSize[1] * 1.0f;
	btScalar  diffZ = boxSize[2] * 1.0f;

	btScalar  offset = -stackSize * (diffZ * 2.0f) * 0.5f;
	btVector3 pos(0.0f, diffY, 0.0f);

	btTransform trans;
	trans.setIdentity();

	while(stackSize) {
		for(int i=0;i<stackSize;i++) {
			pos[2] = offset + (float)i * (diffZ * 2.0f);

		trans.setOrigin(offsetPosition + pos);
		localCreateRigidBody(mass,trans,blockShape);
		
		}
		offset += diffZ;
		pos[1] += (diffY * 2.0f);
		stackSize--;
	}
}
Exemplo n.º 5
0
void	BenchmarkDemo::createTest1()
{
	// 3000
	int size = 8;
	const float cubeSize = 1.0f;
	float spacing = cubeSize;
	btVector3 pos(0.0f, cubeSize * 2,0.f);
	float offset = -size * (cubeSize * 2.0f + spacing) * 0.5f;

	btBoxShape* blockShape = new btBoxShape(btVector3(cubeSize-COLLISION_RADIUS,cubeSize-COLLISION_RADIUS,cubeSize-COLLISION_RADIUS));
	btVector3 localInertia(0,0,0);
	float mass = 2.f;
	blockShape->calculateLocalInertia(mass,localInertia);
	
	btTransform trans;
	trans.setIdentity();

	for(int k=0;k<47;k++) {
		for(int j=0;j<size;j++) {
			pos[2] = offset + (float)j * (cubeSize * 2.0f + spacing);
			for(int i=0;i<size;i++) {
				pos[0] = offset + (float)i * (cubeSize * 2.0f + spacing);

				trans.setOrigin(pos);
				btRigidBody* cmbody;
				cmbody= localCreateRigidBody(mass,trans,blockShape);
			}
		}
		offset -= 0.05f * spacing * (size-1);
//		spacing *= 1.01f;
		pos[1] += (cubeSize * 2.0f + spacing);
	}
}
Exemplo n.º 6
0
void BenchmarkDemo::createLargeMeshBody()
{
	btTransform trans;
	trans.setIdentity();

	for(int i=0;i<8;i++) {

		btTriangleIndexVertexArray* meshInterface = new btTriangleIndexVertexArray();
		btIndexedMesh part;

		part.m_vertexBase = (const unsigned char*)LandscapeVtx[i];
		part.m_vertexStride = sizeof(btScalar) * 3;
		part.m_numVertices = LandscapeVtxCount[i];
		part.m_triangleIndexBase = (const unsigned char*)LandscapeIdx[i];
		part.m_triangleIndexStride = sizeof( short) * 3;
		part.m_numTriangles = LandscapeIdxCount[i]/3;
		part.m_indexType = PHY_SHORT;

		meshInterface->addIndexedMesh(part,PHY_SHORT);

		bool	useQuantizedAabbCompression = true;
		btBvhTriangleMeshShape* trimeshShape = new btBvhTriangleMeshShape(meshInterface,useQuantizedAabbCompression);
		btVector3 localInertia(0,0,0);
		trans.setOrigin(btVector3(0,-25,0));

		btRigidBody* body = localCreateRigidBody(0,trans,trimeshShape);
		body->setFriction (btScalar(0.9));
		
	}
	
}
Exemplo n.º 7
0
void shootBox(const btVector3& destination)
{
	float mass = 1.f;
	btTransform startTransform;
	startTransform.setIdentity();
	btVector3 camPos = getCameraPosition();
	startTransform.setOrigin(camPos);



	const btScalar BOX_DIMENSIONS = 3.0f;

	btBoxShape* box = new btBoxShape( btVector3(BOX_DIMENSIONS, 0.1f, BOX_DIMENSIONS*4/3) );
	box->initializePolyhedralFeatures();
	m_shootBoxShape = box;

	btRigidBody* body = localCreateRigidBody(mass, startTransform,m_shootBoxShape);
	body->setLinearFactor(btVector3(1,1,1));
	//body->setRestitution(1);

	btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]);
	linVel.normalize();
	linVel*=m_ShootBoxInitialSpeed;

	body->getWorldTransform().setOrigin(camPos);
	body->getWorldTransform().setRotation(btQuaternion(0,0,0,1));
	body->setLinearVelocity(linVel);
	body->setAngularVelocity(btVector3(0,0,0));
	body->setCcdMotionThreshold(0.5);
	body->setCcdSweptSphereRadius(0.4f);//value should be smaller (embedded) than the half extends of the box (see ::setShootBoxShape)
	LOGI("shootBox uid=%d\n", body->getBroadphaseHandle()->getUid());
	LOGI("camPos=%f,%f,%f\n",camPos.getX(),camPos.getY(),camPos.getZ());
	LOGI("destination=%f,%f,%f\n",destination.getX(),destination.getY(),destination.getZ());

}
Exemplo n.º 8
0
ChainObject::ChainObject(btDynamicsWorld *m_ownerWorld,
             const btVector3 &origin,
             int edges,
             float edgeLength,
             float edgeThickness)
:
BaseConstrains(m_ownerWorld),
m_thickness(4.0f)
{
    // Setup all the rigid bodies
    m_edgeLength = edgeLength;
    m_edgeThickness = edgeThickness;
    
    btTransform offset; offset.setIdentity();
    offset.setOrigin(origin);
    
    for (int i=0; i<edges; i++) {
        btTransform transform = createTransform(i);
        m_bodies.push_back(localCreateRigidBody(btScalar(1.0f),
                                                offset*transform,
                                                m_shapes.at(i)));
    }

    for (int i=0; i<edges-1; i++) {
        createConeTwistJoint(m_bodies.at(i),
                             m_bodies.at(i+1),
                             btVector3(0.0f, 0.0f, -m_edgeLength),
                             btVector3(0.0f, 0.0f,  m_edgeLength),
                             0, 0, 0,
                             0, 0, 0);
    }
}
Exemplo n.º 9
0
void CcdPhysicsDemo::createStack( btCollisionShape* boxShape, float halfCubeSize, int size, float zPos )
{
	btTransform trans;
	trans.setIdentity();

	for(int i=0; i<size; i++)
	{
		// This constructs a row, from left to right
		int rowSize = size - i;
		for(int j=0; j< rowSize; j++)
		{
			btVector3 pos;
			pos.setValue(
				-rowSize * halfCubeSize + halfCubeSize + j * 2.0f * halfCubeSize,
				halfCubeSize + i * halfCubeSize * 2.0f,
				zPos);

			trans.setOrigin(pos);
			btScalar mass = 1.f;

			btRigidBody* body = 0;
			body = localCreateRigidBody(mass,trans,boxShape);
#ifdef USER_DEFINED_FRICTION_MODEL
		///Advanced use: override the friction solver
		body->m_frictionSolverType = USER_CONTACT_SOLVER_TYPE1;
#endif //USER_DEFINED_FRICTION_MODEL

		}
	}
}
Exemplo n.º 10
0
 void CreateBox(int index,
                double x, double y, double z,
                double length, double width, double height)
 {
     
     btCollisionShape* box;
     btRigidBody* boxBody;
     
     // Setup the geometry
     box = new btBoxShape(btVector3(length, width, height));
     
     //btCollisionShape* geom[9];
     //geom[index]= box;
     
     // Setup all the rigid bodies
     btTransform offset;
     offset.setIdentity();
     
     btTransform transform;
     transform.setIdentity();
     transform.setOrigin(btVector3(x, y, z));
     boxBody = localCreateRigidBody(btScalar(1.), offset*transform, box);
     //btRigidBody* body[9];
     //body[index]= boxBody;
     
     
 }
Exemplo n.º 11
0
void PendulumApplication::initPhysics()
{
	setTexturing(true);
	setShadows(true);
	m_debugMode |= btIDebugDraw::DBG_NoHelpText;
	setCameraDistance(btScalar(20.));

	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);

	///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);

	btSphereShape* sphereShape = new btSphereShape(1.);
	m_collisionShapes.push_back(sphereShape);

	btTransform pendulumTransform;
	pendulumTransform.setIdentity();

    m_theta.m_value = SIMD_HALF_PI;
    m_theta.m_dot = 1.;
    m_r.m_value = 10;
    m_r.m_dot = 0;
    temp = 0;
	btVector3 to_Remplace; // to replace with te pendulum position

	pendulumTransform.setOrigin( to_Remplace);
	m_pendulumBody = localCreateRigidBody(1,pendulumTransform,sphereShape);
	m_pendulumBody->setCollisionFlags( m_pendulumBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
}
Exemplo n.º 12
0
Swing::Swing( btDynamicsWorld* ownerWorld,
	const btVector3& jointPosition, 
	btScalar scale_swing, btRigidBody *ground ) : m_ownerWorld (ownerWorld)
{

//	scale_swing = 1.0;
	m_shape = new btCapsuleShape( btScalar(scale_swing * 0.1), btScalar(scale_swing) );

	btTransform offset;
	offset.setIdentity();
//	offset.setOrigin( positionOffset );

	btTransform transform;
	transform.setIdentity();
	transform.setOrigin( btVector3( btScalar(0.0), btScalar(0.0), btScalar(0.0) ) );
	m_body = localCreateRigidBody( btScalar(1.0), offset * transform, m_shape );
	

	m_joint = new btPoint2PointConstraint(*m_body, *ground, 
		btVector3(btScalar(0.), btScalar(0.5 * scale_swing), btScalar(0.)),
		jointPosition
		);

	/* setup the a hinge */
	//btGeneric6DofConstraint * joint6DOF;
	//btTransform localA, localB;
	//bool useLinearReferenceFrameA = true;
	//localA.setIdentity();
	//localB.setIdentity();
	//localA.setOrigin(btVector3(btScalar(0.), btScalar(0.5 * scale_swing), btScalar(0.))); //! hinge relative to capsule centres
	//localB.setOrigin(jointPosition); //! hinge relative to ground
	//m_joint = new btGeneric6DofConstraint(*m_body, *ground, localA, localB, useLinearReferenceFrameA);

//	m_body->setRestitution(2.0f);
//	m_body->setRollingFriction(0.0f);

	//m_body->setDamping( 0.1f, 0.7f );
	//m_body->setDeactivationTime( 0.0f );
	m_body->setSleepingThresholds( 0.0f, 0.0f );
	m_body->setDamping( 0.05f, 0.85f );
	m_body->setDeactivationTime( 0.8f );
	//m_body->setSleepingThresholds( 1.6f, 2.5f );
	m_body->setActivationState(DISABLE_DEACTIVATION);
	//ground->setActivationState(DISABLE_DEACTIVATION);
	//ground->setRestitution(0.0f);
	//ground->setRollingFriction(0.0f);

	
#ifdef RIGID
	m_joint->setAngularLowerLimit(btVector3(-SIMD_EPSILON,-SIMD_EPSILON,-SIMD_EPSILON));
	m_joint->setAngularUpperLimit(btVector3(SIMD_EPSILON,SIMD_EPSILON,SIMD_EPSILON));
#else
	/* uncomment these to set the movement limits. */
	//joint6DOF->setAngularLowerLimit(btVector3(-SIMD_PI*0.3f,-SIMD_EPSILON,-SIMD_PI*0.3f));
	//joint6DOF->setAngularUpperLimit(btVector3(SIMD_PI*0.5f,SIMD_EPSILON,SIMD_PI*0.3f));
#endif
	m_ownerWorld->addConstraint(m_joint, true);
}
Exemplo n.º 13
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);

}
Exemplo n.º 14
0
void LogicWorld::CreateFlatFloor()
{
    btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,0,1), 0);
    m_collisionShapes.push_back(groundShape);
    float mass = 0.0f;
    btTransform startTransform;
    startTransform.setIdentity();
    startTransform.setOrigin(btVector3(0,0,0));
    localCreateRigidBody(mass, startTransform, groundShape);
}
Exemplo n.º 15
0
void LogicWorld::AddCylinderShape(const btVector3& pos, const btVector3& size)
{
    btCollisionShape* cylShape = new btCylinderShapeZ(size);
    m_collisionShapes.push_back(cylShape);
    float mass = 0.0f;
    btTransform startTransform;
    startTransform.setIdentity();
    startTransform.setOrigin(pos);
    localCreateRigidBody(mass, startTransform, cylShape);
}
	// -------------------------------------------------------------------------
	RagDoll::RagDoll (btDynamicsWorld* ownerWorld, const btVector3& positionOffset)
		: 
		m_ownerWorld (ownerWorld)
	{
		// Setup all the rigid bodies
		btTransform offset; offset.setIdentity();
		offset.setOrigin(positionOffset);


		btTransform transform;

		// for
		{
			transform.setIdentity();
			transform.setOrigin(btVector3(btScalar(0.), btScalar(1.), btScalar(0.)));
			m_bodies.push_back(
				localCreateRigidBody(btScalar(1.), 
										offset*transform, 
										new btCapsuleShape(btScalar(0.15), btScalar(0.20))
										)
									);
		}

		// Setup some damping on the m_bodies
		for(std::vector<btRigidBody* >::iterator i=m_bodies.begin();
			i!=m_bodies.end();
			++i) 
		{
			(*i)->setDamping(0.05f, 0.85f);
			(*i)->setDeactivationTime(0.8f);
			(*i)->setSleepingThresholds(1.6f, 2.5f);
		}

		// Now setup the constraints
		btHingeConstraint* hingeC;
		//btConeTwistConstraint* coneC;
		btTransform localA, localB;

		// for
		{
			localA.setIdentity(); localB.setIdentity();
			localA.getBasis().setEulerZYX(0, Ogre::Math::TWO_PI,0); 
			localA.setOrigin(btVector3(btScalar(0.), btScalar(0.15), btScalar(0.)));
			localB.getBasis().setEulerZYX(0,Ogre::Math::TWO_PI,0); 
			localB.setOrigin(btVector3(btScalar(0.), btScalar(-0.15), btScalar(0.)));
			hingeC =  new btHingeConstraint(*m_bodies[0], *m_bodies[1], 
				localA, localB);
			hingeC->setLimit(btScalar(-Ogre::Math::TWO_PI*2), btScalar(Ogre::Math::TWO_PI));
			m_joints.push_back(hingeC);
			m_ownerWorld->addConstraint(hingeC, true);
		}

	}
Exemplo n.º 17
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.º 18
0
void	BenchmarkDemo::createTest6()
{
	setCameraDistance(btScalar(250.));

	btVector3 boxSize(1.5f,1.5f,1.5f);

	btConvexHullShape* convexHullShape = new btConvexHullShape();

	for (int i=0;i<TaruVtxCount;i++)
	{
		btVector3 vtx(TaruVtx[i*3],TaruVtx[i*3+1],TaruVtx[i*3+2]);
		convexHullShape->addPoint(vtx);
	}

	btTransform trans;
	trans.setIdentity();

	float mass = 1.f;
	btVector3 localInertia(0,0,0);
	convexHullShape->calculateLocalInertia(mass,localInertia);


	{
		int size = 10;
		int height = 10;

		const float cubeSize = boxSize[0];
		float spacing = 2.0f;
		btVector3 pos(0.0f, 20.0f, 0.0f);
		float offset = -size * (cubeSize * 2.0f + spacing) * 0.5f;
		
	
		for(int k=0;k<height;k++) {
			for(int j=0;j<size;j++) {
				pos[2] = offset + (float)j * (cubeSize * 2.0f + spacing);
				for(int i=0;i<size;i++) {
					pos[0] = offset + (float)i * (cubeSize * 2.0f + spacing);
					btVector3 bpos = btVector3(0,25,0) + btVector3(5.0f,1.0f,5.0f)*pos;
					trans.setOrigin(bpos);
					
					localCreateRigidBody(mass,trans,convexHullShape);
				}
			}
			offset -= 0.05f * spacing * (size-1);
			spacing *= 1.1f;
			pos[1] += (cubeSize * 2.0f + spacing);
		}
	}


	createLargeMeshBody();
}
/** Initializes the physics world and simulation
*
**/
void Physics::initPhysics(){
	dead=false;
	totaltime=0;
	currentBoxIndex=0;
	currentJointIndex=0;
	noBoxes =0;
	fitness=0;
	enableEffectors=true;

	setTexturing(true);
	setShadows(true);

	setCameraDistance(btScalar(20.));

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

	///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 ground body
	btBoxShape* groundShape = new btBoxShape(btVector3(btScalar(1000.),btScalar(10.),btScalar(1000.)));
	int* userP = new int();
	*userP = 0;
	groundShape->setUserPointer2((void*)userP);

	m_collisionShapes.push_back(groundShape);

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

	btRigidBody* ground = localCreateRigidBody(0.,groundTransform,groundShape,COL_GROUND,COL_BOX); //ground collides with boxes only
	ground->setUserPointer((void*)(-1));;

	groundY =  ground->getWorldTransform().getOrigin().getY()+groundShape->getHalfExtentsWithMargin().getY();

	currentBoxIndex++;

	theNet=NULL;
}
Exemplo n.º 20
0
//phsics
void PhsicsAttrib::init(btDynamicsWorld *world, float mass, const btTransform& startTransform, SHAPE_TYPE type)
{
	switch(type)
	{
	case SHAPE_TYPE_BOX:
		mpShape = new btBoxShape(btVector3(50,3,50));
		break;
	default:
		return;
	}
	mpOwnerWorld = world;
	localCreateRigidBody(mass, startTransform, mpShape);
}
Exemplo n.º 21
0
KeplerCube::KeplerCube(btDynamicsWorld* ownerWorld, const btVector3& positionOffset)
: m_ownerWorld (ownerWorld)
{
    //    const int R = 3.0f;
    const int L = R_LENGTH/2.0f;
    //
    //    const float d = L/2.0f;
    
    //    for (int i=0; i<N_EDGES; i++)
    //        m_shapes.push_back(new btBoxShape(btVector3());
    
    // Setup all the rigid bodies
    btTransform offset; offset.setIdentity();
    offset.setOrigin(positionOffset);
    
    for (int i=0; i<N_EDGES; i++) {
        btTransform transform = createBoxTransform(i);
        m_bodies.push_back(localCreateRigidBody(btScalar(1.0f), offset*transform, m_shapes.at(i)));
    }
    
    // Setup some damping on the m_bodies
    for (int i = 0; i < m_bodies.size(); ++i) {
        //        m_bodies.at(i)->setDamping(0.05, 0.85);
        //        m_bodies.at(i)->setDeactivationTime(0.8);
        //        m_bodies.at(i)->setSleepingThresholds(1.6, 2.5);
        
        //        m_bodies.at(i)->setActivationState(DISABLE_DEACTIVATION);
        //        m_bodies.at(i)->setCollisionFlags(m_bodies.at(i)->getCollisionFlags() |
        //                                          btCollisionObject::CF_KINEMATIC_OBJECT);
    }
    
    createJoint(m_bodies.at(0), m_bodies.at(1), btVector3( 0, 0,-L), btVector3(-L, 0, 0), 0, 0, 0, 0, 0, 0);
    createJoint(m_bodies.at(1), m_bodies.at(2), btVector3( L, 0, 0), btVector3( 0, 0,-L), 0, 0, 0, 0, 0, 0);
    createJoint(m_bodies.at(2), m_bodies.at(3), btVector3( 0, 0, L), btVector3( L, 0, 0), 0, 0, 0, 0, 0, 0);
    createJoint(m_bodies.at(3), m_bodies.at(0), btVector3(-L, 0, 0), btVector3( 0, 0, L), 0, 0, 0, 0, 0, 0);
    
    createJoint(m_bodies.at(4), m_bodies.at(0), btVector3( 0,-L, 0), btVector3( 0, 0,-L), 0, 0, 0, 0, 0, 0);
    createJoint(m_bodies.at(5), m_bodies.at(1), btVector3( 0,-L, 0), btVector3( L, 0, 0), 0, 0, 0, 0, 0, 0);
    createJoint(m_bodies.at(6), m_bodies.at(2), btVector3( 0,-L, 0), btVector3( 0, 0, L), 0, 0, 0, 0, 0, 0);
    createJoint(m_bodies.at(7), m_bodies.at(3), btVector3( 0,-L, 0), btVector3(-L, 0, 0), 0, 0, 0, 0, 0, 0);
    
    createJoint(m_bodies.at(4), m_bodies.at( 8), btVector3( 0, L, 0), btVector3( 0, 0,-L), 0, 0, 0, 0, 0, 0);
    createJoint(m_bodies.at(5), m_bodies.at( 9), btVector3( 0, L, 0), btVector3( L, 0, 0), 0, 0, 0, 0, 0, 0);
    createJoint(m_bodies.at(6), m_bodies.at(10), btVector3( 0, L, 0), btVector3( 0, 0, L), 0, 0, 0, 0, 0, 0);
    createJoint(m_bodies.at(7), m_bodies.at(11), btVector3( 0, L, 0), btVector3(-L, 0, 0), 0, 0, 0, 0, 0, 0);
    
    createJoint(m_bodies.at( 8), m_bodies.at( 9), btVector3( 0, 0,-L), btVector3(-L, 0, 0), 0, 0, 0, 0, 0, 0);
    createJoint(m_bodies.at( 9), m_bodies.at(10), btVector3( L, 0, 0), btVector3( 0, 0,-L), 0, 0, 0, 0, 0, 0);
    createJoint(m_bodies.at(10), m_bodies.at(11), btVector3( 0, 0, L), btVector3( L, 0, 0), 0, 0, 0, 0, 0, 0);
    createJoint(m_bodies.at(11), m_bodies.at( 8), btVector3(-L, 0, 0), btVector3( 0, 0, L), 0, 0, 0, 0, 0, 0);
}
Exemplo n.º 22
0
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();		
}
Exemplo n.º 23
0
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();		
}
Exemplo n.º 24
0
btRigidBody* RagdollDemo::create_kinematic_box(double x, double y, double z, double length, double width, double height) {
    btTransform offset;
    offset.setIdentity();
    offset.setOrigin(btVector3(btScalar(x), btScalar(y), btScalar(z)));
    btCollisionShape* geom = new btBoxShape(btVector3(btScalar(length / 2), btScalar(width / 2), btScalar(height / 2)));
    btRigidBody* body = localCreateRigidBody(btScalar(0.), offset, geom);

    body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
    //body->setActivationState(DISABLE_DEACTIVATION);

    body->setUserPointer(0);
    m_dynamicsWorld->addRigidBody(body);
    return body;
}
Exemplo n.º 25
0
btRigidBody* RagdollDemo::create_kinematic_cylinder(double x, double y, double z, double len, double rad, 
				 double rot_X, double rot_Y, double rot_Z) {
    btTransform offset;
    offset.setIdentity();
    offset.setOrigin(btVector3(btScalar(x), btScalar(y), btScalar(z)));
    offset.getBasis().setEulerZYX(rot_X, rot_Y, rot_Z);
    btVector3 half_extents(rad, len / 2, 0);
    btCollisionShape* geom = new btCylinderShape(half_extents);
    btRigidBody* body = localCreateRigidBody(btScalar(0.), offset, geom);

    body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);

    body->setUserPointer(0);
    m_dynamicsWorld->addRigidBody(body);
    return body;
}
Exemplo n.º 26
0
void	BenchmarkDemo::createTest4()
{
	setCameraDistance(btScalar(50.));

	int size = 8;
	const float cubeSize = 1.5f;
	float spacing = cubeSize;
	btVector3 pos(0.0f, cubeSize * 2, 0.0f);
	float offset = -size * (cubeSize * 2.0f + spacing) * 0.5f;

	btConvexHullShape* convexHullShape = new btConvexHullShape();

	btScalar scaling(1);

	convexHullShape->setLocalScaling(btVector3(scaling,scaling,scaling));

	for (int i=0;i<TaruVtxCount;i++)
	{
		btVector3 vtx(TaruVtx[i*3],TaruVtx[i*3+1],TaruVtx[i*3+2]);
		convexHullShape->addPoint(vtx*btScalar(1./scaling));
	}

	//this will enable polyhedral contact clipping, better quality, slightly slower
	//convexHullShape->initializePolyhedralFeatures();

	btTransform trans;
	trans.setIdentity();

	float mass = 1.f;
	btVector3 localInertia(0,0,0);
	convexHullShape->calculateLocalInertia(mass,localInertia);

	for(int k=0;k<15;k++) {
		for(int j=0;j<size;j++) {
			pos[2] = offset + (float)j * (cubeSize * 2.0f + spacing);
			for(int i=0;i<size;i++) {
				pos[0] = offset + (float)i * (cubeSize * 2.0f + spacing);
				trans.setOrigin(pos);
				localCreateRigidBody(mass,trans,convexHullShape);		
			}
		}
		offset -= 0.05f * spacing * (size-1);
		spacing *= 1.01f;
		pos[1] += (cubeSize * 2.0f + spacing);
	}
}
Exemplo n.º 27
0
//Assignment 5
void RagdollDemo::CreateBox(int index,double x, double y, double z,double length, 
double width, double height)
{ 
	geom[index] = new btBoxShape(btVector3(btScalar(length),btScalar(width),btScalar(height))); 
	btTransform offset; 
	offset.setIdentity(); 
	offset.setOrigin(btVector3(btScalar(x),btScalar(y),btScalar(z))); 
	body[index] = localCreateRigidBody(btScalar(1.0),offset,geom[index]); 
	body[index]->setCollisionFlags(body[index]->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
	collisionID[currentIndex] = new collisionObject(currentIndex, body[index]);
	body[index]->setUserPointer(collisionID[currentIndex]);
	
	cout << "OBJECT ID: " << collisionID[currentIndex]->id;
	cout << " | POINTER ID: " << ((collisionObject*)body[index]->getUserPointer())->id;
	cout << " | ADDRESS " << collisionID[currentIndex];
	cout << " | FLAGS " << collisionID[currentIndex]->body->getCollisionFlags() << endl;

	currentIndex++;
} 
//creates a box with side lengths x,y,z
int Physics::createBox(int x1, int y1, int z1){
	if(noBoxes==0){scews.push_back(new btQuaternion(0,0,0));}
	noBoxes++;
	if(noBoxes>maxBoxes){
		fitness= -999999;
		dead=true;
		totaltime=simulationTime;
	}

	// max 10 & min 0.05
	if(x1==0){x1=95;}
	if(y1==0){y1=95;}
	if(z1==0){z1=95;}
	float x=(x1%995+5)/100.f;
	float y=(y1%995+5)/100.f;
	float z=(z1%995+5)/100.f;

	btAssert(x>=0.05 && x<=10);
	btAssert(y>=0.05 && y<=10);
	btAssert(z>=0.05 && z<=10);

	btBoxShape* boxShape = new btBoxShape(btVector3(x/2.f,y/2.f,z/2.f));
	int* userP = new int();
	*userP = 1;
	boxShape->setUserPointer2((void*)userP);
	m_collisionShapes.push_back(boxShape);

	btTransform startTransform;
	startTransform.setIdentity();
	btRigidBody* box;
	btScalar mass = btScalar(x*y*z*DensityHuman);
	//btScalar mass = btScalar(0);
	startTransform.setOrigin(btVector3(0,0,0));

	box= localCreateRigidBody(mass,startTransform,boxShape,COL_BOX,COL_GROUND);

	box->setUserPointer((void*)-1);

	int returnVal = currentBoxIndex;
	currentBoxIndex++;
	return returnVal;
}
Exemplo n.º 29
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,-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();
}
Exemplo n.º 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();
}