void BulletDynamicsBody::CreateRigidBody( const Integration::DynamicsBodySettings& bodySettings, Dali::Integration::DynamicsShape* shape,
                                          const Vector3& startPosition, const Quaternion& startRotation )
{
  DEBUG_PRINTF("%s\n", __func__ );

  Vector3 axis;
  float angle( 0.0f );
  startRotation.ToAxisAngle( axis, angle );

  btVector3 inertia( 0.0f ,0.0f ,0.0f );
  btCollisionShape* collisionShape( ((BulletDynamicsShape*)shape)->GetShape() );
  if( ! EqualsZero( bodySettings.mass ) )
  {
    collisionShape->calculateLocalInertia(bodySettings.mass, inertia);
  }

  btRigidBody::btRigidBodyConstructionInfo constructionInfo(bodySettings.mass, NULL, collisionShape, inertia);
  constructionInfo.m_restitution = bodySettings.elasticity;
  constructionInfo.m_linearDamping = bodySettings.linearDamping;
  constructionInfo.m_angularDamping = bodySettings.angularDamping;
  constructionInfo.m_friction = bodySettings.friction;
  constructionInfo.m_linearSleepingThreshold = bodySettings.linearSleepVelocity;
  constructionInfo.m_angularSleepingThreshold = bodySettings.angularSleepVelocity;
  constructionInfo.m_startWorldTransform.setOrigin(btVector3(startPosition.x, startPosition.y, startPosition.z));
  if( axis != Vector3::ZERO )
  {
    constructionInfo.m_startWorldTransform.setRotation( btQuaternion(btVector3(axis.x, axis.y, axis.z), btScalar(angle)) );
  }

  mBody = new btRigidBody( constructionInfo );
  mBody->setUserPointer(this);
}
示例#2
0
b3ThreadSupportInterface* createThreadSupport( int numThreads, btThreadFunc threadFunc, btThreadLocalStorageFunc localStoreFunc, const char* uniqueName )
{
    b3Win32ThreadSupport::Win32ThreadConstructionInfo constructionInfo( uniqueName, threadFunc, localStoreFunc, numThreads );
    //constructionInfo.m_priority = 0;  // highest priority (the default) -- can cause erratic performance when numThreads > numCores
    //                                     we don't want worker threads to be higher priority than the main thread or the main thread could get
    //                                     totally shut out and unable to tell the workers to stop
    constructionInfo.m_priority = -1;  // normal priority
    b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport( constructionInfo );
    return threadSupport;
}
示例#3
0
文件: main.cpp 项目: Hongtae/bullet3
b3ThreadSupportInterface* createThreadSupport(int numThreads)
{
	b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads",
																  SampleThreadFunc,
																  SamplelsMemoryFunc,
																  numThreads);
	b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo);

	return threadSupport;
}
示例#4
0
b3ThreadSupportInterface* createUDPThreadSupport(int numThreads)
{
	b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("UDPThread",
		UDPThreadFunc,
		UDPlsMemoryFunc,
		numThreads);
	b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo);

	return threadSupport;

}
static b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThreads)
{
	b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads",
                                                                ExampleBrowserThreadFunc,
                                                                ExampleBrowserMemoryFunc,
                                                                numThreads);
    b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo);

	return threadSupport;

}
b3ThreadSupportInterface* createMotionThreadSupport(int numThreads)
{
	b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("MotionThreads",
                                                                MotionThreadFunc,
                                                                MotionlsMemoryFunc,
                                                                numThreads);
    b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo);

	return threadSupport;

}
void PhysicsManager::AddRigidBody(btCollisionShape* collisionShape, btVector3 origin, btScalar mass, btScalar restitution, btVector3 inertia, bool kinematic)
{
    btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), origin));
    if(mass > 0)
        collisionShape->calculateLocalInertia(mass, inertia);
    btRigidBody::btRigidBodyConstructionInfo constructionInfo(mass, motionState, collisionShape, inertia);
    btRigidBody* body = new btRigidBody(constructionInfo);
    body->setRestitution(restitution);
    body->setActivationState(DISABLE_DEACTIVATION);
    if(kinematic)
    {
        body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
        //body->setActivationState(DISABLE_DEACTIVATION);
    }
    dynamicsWorld->addRigidBody(body);
}
btThreadSupportInterface* jmePhysicsSpace::createSolverThreadSupport(int maxNumThreads) {
#ifdef _WIN32
    Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("solverThreads", SolverThreadFunc, SolverlsMemoryFunc, maxNumThreads);
    Win32ThreadSupport* threadSupport = new Win32ThreadSupport(threadConstructionInfo);
    threadSupport->startSPU();
#elif defined (USE_PTHREADS)
    PosixThreadSupport::ThreadConstructionInfo constructionInfo("collision", SolverThreadFunc,
            SolverlsMemoryFunc, maxNumThreads);
    PosixThreadSupport* threadSupport = new PosixThreadSupport(constructionInfo);
    threadSupport->startSPU();
#else
    SequentialThreadSupport::SequentialThreadConstructionInfo tci("solverThreads", SolverThreadFunc, SolverlsMemoryFunc);
    SequentialThreadSupport* threadSupport = new SequentialThreadSupport(tci);
    threadSupport->startSPU();
#endif
    return threadSupport;
}
PlayerPhysicsComponent::PlayerPhysicsComponent(GameObject &gameObject, float mass)
   : PhysicsComponent(gameObject, CollisionGroup::Characters, CollisionGroup::Everything) {
   collisionShape = UPtr<btCollisionShape>(new btCapsuleShape(PLAYER_RADIUS, PLAYER_MIDDLE_HEIGHT));

   collisionShape->setLocalScaling(toBt(gameObject.getScale()));

   motionState = UPtr<btMotionState>(new PlayerMotionState(gameObject));

   btVector3 inertia(0.0f, 0.0f, 0.0f);
   collisionShape->calculateLocalInertia(mass, inertia);
   btRigidBody::btRigidBodyConstructionInfo constructionInfo(mass, motionState.get(), collisionShape.get(), inertia);

   UPtr<btRigidBody> rigidBody(new btRigidBody(constructionInfo));
   rigidBody->setAngularFactor(0.0f); // Prevent the capsule from falling over
   rigidBody->setSleepingThresholds(0.0f, 0.0f); // Prevent the capsule from sleeping

   collisionObject = std::move(rigidBody);
}
示例#10
0
 GameObject::GameObject(Mesh* mesh, Shader* shader, btScalar mass = 0, float scale = 1, const btVector3& position = btVector3(0,0,0), const btQuaternion& orientation = btQuaternion::getIdentity(), btCollisionShape* shape = nullptr) {
     this->mesh = mesh;
     this->shader = shader;
     
     this->mass  = mass;
     this->scale = scale;
     
     this->shape = (shape != nullptr) ? shape : new btEmptyShape();
     
     this->motionState = new btDefaultMotionState(btTransform(orientation, position));
     
     btRigidBody::btRigidBodyConstructionInfo constructionInfo(
         this->mass,        // mass > 0 will move and mass == 0 will not be affected by physical forces (ex. gravity)
         this->motionState, // initial position information
         this->shape,       // collision shape of the body
         btVector3(0,0,0)); // local inertia
     
     this->body = new btRigidBody(constructionInfo);
 }
示例#11
0
void collisionTester::initCollisionWorld(){
    btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
	
#if defined (USE_TBB) && defined(USE_TBB_COLLISIION)
    int maxNumOutstandingTasks = 4;
    PosixThreadSupport::ThreadConstructionInfo constructionInfo("collision",
                                                                processCollisionTask,
                                                                createCollisionLocalStoreMemory,
                                                                maxNumOutstandingTasks);

    m_threadSupportCollision = new PosixThreadSupport(constructionInfo);
    
	btCollisionDispatcher * dispatcher = new SpuGatheringCollisionDispatcher(m_threadSupportCollision,maxNumOutstandingTasks, collisionConfiguration);
#else
    btCollisionDispatcher * dispatcher = new btCollisionDispatcher(collisionConfiguration);
#endif

    btVector3	worldAabbMin(-10000,-10000,-10000);
	btVector3	worldAabbMax( 10000, 10000, 10000);
	btAxisSweep3*	broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);
	collisionWorld = new btCollisionWorld(dispatcher, broadphase, collisionConfiguration);
	collisionWorld->setDebugDrawer(&debugDrawer);    
}
示例#12
0
btRigidBody *Enco3D::Component::RigidBody::createBulletPhysicsInstance()
{
	btDefaultMotionState *motionState = new btDefaultMotionState(btTransform(Physics::PhysicsHelper::toBulletPhysicsQuat(getTransform()->getRotation()), Physics::PhysicsHelper::toBulletPhysicsVec3(getTransform()->getTranslation())));
	btCollisionShape *shape = m_collisionShape->toBulletPhysicsCollisionShape();
	btVector3 inertia(0, 0, 0);

	if (m_mass > 0.0f)
		shape->calculateLocalInertia(m_mass, inertia);

	btRigidBody::btRigidBodyConstructionInfo constructionInfo(m_mass, motionState, shape, inertia);
	m_bulletPhysicsInstance = new btRigidBody(constructionInfo);
	m_bulletPhysicsInstance->setRestitution(m_restitution);
	m_bulletPhysicsInstance->setFriction(m_friction);
	m_bulletPhysicsInstance->setDamping(m_linearDamping, m_angularDamping);

	if (m_alwaysStanding)
	{
		m_bulletPhysicsInstance->setInvInertiaDiagLocal(btVector3(0, 0, 0));
		m_bulletPhysicsInstance->updateInertiaTensor();
	}

	return m_bulletPhysicsInstance;
}
示例#13
0
b3ThreadSupportInterface* createThreadSupport( int numThreads, btThreadFunc threadFunc, btThreadLocalStorageFunc localStoreFunc, const char* uniqueName)
{
    b3PosixThreadSupport::ThreadConstructionInfo constructionInfo( uniqueName, threadFunc, localStoreFunc, numThreads );
    b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport( constructionInfo );
    return threadSupport;
}
示例#14
0
void Terrain::loadTerrain() {
	if (!bLoaded) {
		bLoaded = true;

		int width = 65;
		int length = 65;
		data.resize(width * length);
		for (int y = 0; y < length; ++y) {
			for (int x = 0; x < width; ++x)
				data[y * length + x] = sin(((float)y) / 3);
		}


		vector<Vertex> vertices;
		vector<unsigned int> indices;

		for (int y = 0; y < length; ++y) {
			for (int x = 0; x < width; ++x) {
				glm::vec3 tx, ty;

				if (x == 0) {
					tx = glm::vec3(1, data[y * length + x + 1] - data[y * length + x], 0);
				}
				else if (x == width - 1) {
					tx = glm::vec3(1, data[y * length + x] - data[y * length + x - 1], 0);
				}
				else {
					glm::vec3 txL, txR;
					txL = glm::vec3(1, data[y * length + x] - data[y * length + x - 1], 0);
					txR = glm::vec3(1, data[y * length + x + 1] - data[y * length + x], 0);
					txL = glm::normalize(txL);
					txR = glm::normalize(txR);
					tx = txL + txR;
				}
				tx = glm::normalize(tx);

				if (y == 0) {
					ty = glm::vec3(0, data[(y + 1) * length + x] - data[y * length + x], 1);
				}
				else if (y == length - 1) {
					ty = glm::vec3(0, data[y * length + x] - data[(y - 1) * length + x], 1);
				}
				else {
					glm::vec3 tyB, tyT;
					tyB = glm::vec3(0, data[y * length + x] - data[(y - 1) * length + x], 1);
					tyT = glm::vec3(0, data[(y + 1) * length + x] - data[y * length + x], 1);
					tyB = glm::normalize(tyB);
					tyT = glm::normalize(tyT);
					ty = tyB + tyT;
				}
				ty = glm::normalize(ty);
				glm::vec3 n = glm::cross(ty, tx);
				n = glm::normalize(n);

				Vertex v;
				v.pos.x = -(width / 2) + x;
				v.pos.y = data[y * length + x];
				v.pos.z = -(length / 2) + y;
				v.normal = n;
				v.texCoord = glm::vec2(((float)x) / width, ((float)y) / length);

				vertices.push_back(v);
			}
		}

		for (int y = 0; y < length - 1; ++y) {
			for (int x = 0; x < width - 1; ++x) {
				indices.push_back(y * length + x);
				indices.push_back((y + 1) * length + x);
				indices.push_back((y + 1) * length + x + 1);

				indices.push_back(y * length + x);
				indices.push_back((y + 1) * length + x + 1);
				indices.push_back(y * length + x + 1);
			}
		}

		numIndices = indices.size();

		glGenBuffers(1, &vertexBufferId);
		glBindBuffer(GL_ARRAY_BUFFER, vertexBufferId);
		glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * vertices.size(), &vertices[0], GL_STATIC_DRAW);

		glGenBuffers(1, &indexBufferId);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferId);
		glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * numIndices, &indices[0], GL_STATIC_DRAW);

		vaoId = meshShader->createVertexArrayObject(vertexBufferId, sizeof(Vertex), 0, (GLvoid*)(3 * sizeof(float)), (GLvoid*)(6 * sizeof(float)));

		texture.load("Data/test.png");



		terrainShape.reset(new btHeightfieldTerrainShape(width, length, &data[0], 1.0f, -10.0f, 10.0f, 1, PHY_FLOAT, false));
		//terrainShape->setLocalScaling(btVector3(5.0f, 1.0f, 5.0f));
		btVector3 localInertia(0, 0, 0);
		terrainShape->calculateLocalInertia(0, localInertia);
		btTransform transform;
		transform.setIdentity();
		transform.setOrigin(btVector3(0, 0, 0));
		btDefaultMotionState* motionState = new btDefaultMotionState(transform);
		btRigidBody::btRigidBodyConstructionInfo constructionInfo(0, motionState, terrainShape.get(), localInertia);
		rigidBody.reset(new btRigidBody(constructionInfo));
		dynamicsWorld->addRigidBody(rigidBody.get(), COL_WORLD, COL_ALL);
	}
}