예제 #1
0
	btRigidBody* localCreateRigidBody (btScalar mass, const btTransform& startTransform, btConvexShape* shape)
	{
		bool isDynamic = (mass != 0.f);

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

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

		m_ownerWorld->addRigidBody(body);
		
		btVector3 color(1,0,0);
		btVector3 scaling(1,1,1);
		
		btShapeHull* hull = new btShapeHull(shape);
		hull->buildHull(0.01);
		
		{
			int strideInBytes = 9*sizeof(float);
			int numVertices = hull->numVertices();
			int numIndices =hull->numIndices();
			
			btAlignedObjectArray<GraphicsVertex> gvertices;
			
			for (int i=0;i<numVertices;i++)
			{
				GraphicsVertex vtx;
				btVector3 pos =hull->getVertexPointer()[i];
				vtx.pos[0] = pos.x();
				vtx.pos[1] = pos.y();
				vtx.pos[2] = pos.z();
				vtx.pos[3] = 1.f;
				pos.normalize();
				vtx.normal[0] =pos.x();
				vtx.normal[1] =pos.y();
				vtx.normal[2] =pos.z();
				vtx.texcoord[0] = 0.5f;
				vtx.texcoord[1] = 0.5f;
				gvertices.push_back(vtx);
			}
			
			btAlignedObjectArray<int> indices;
			for (int i=0;i<numIndices;i++)
				indices.push_back(hull->getIndexPointer()[i]);
			
			int shapeId = m_app->m_instancingRenderer->registerShape(&gvertices[0].pos[0],numVertices,&indices[0],numIndices);
			
			m_app->m_instancingRenderer->registerGraphicsInstance(shapeId,body->getWorldTransform().getOrigin(),body->getWorldTransform().getRotation(),color,scaling);
			
		}
		delete hull;

		

		return body;
	}
예제 #2
0
  void AddBody(const Json::Value& bodyDesc) {
    std::string shapeName = bodyDesc["shape"].asString();
    float mass = bodyDesc["mass"].asFloat();
    float friction = bodyDesc["friction"].asFloat();
    Json::Value transform = bodyDesc["transform"];
    btCollisionShape* shape = boxShape;
    if (shapes.count(shapeName) == 0) {
      NaClAMPrintf("Could not find shape %s defaulting to unit cube.", shapeName.c_str());
    } else {
      shape = shapes[shapeName];
    }

    btTransform T;
    T.setIdentity();
    {
      float m[16];
      for (int i = 0; i < transform.size(); i++) {
        m[i] = transform[i].asFloat();
      }
      T.setFromOpenGLMatrix(&m[0]);
    }
    

    bool isDynamic = (mass != 0.f);
    btVector3 localInertia(0,0,0);
    if (isDynamic)
      shape->calculateLocalInertia(mass,localInertia);
    btDefaultMotionState* myMotionState = new btDefaultMotionState(T);
    btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,shape,localInertia);
    btRigidBody* body = new btRigidBody(rbInfo);
    body->setFriction(friction);
    dynamicsWorld->addRigidBody(body);
  }
예제 #3
0
 void AddBox(const btTransform& T, float mass) {
   bool isDynamic = (mass != 0.f);
   btVector3 localInertia(0,0,0);
   if (isDynamic)
     boxShape->calculateLocalInertia(mass,localInertia);
     btDefaultMotionState* myMotionState = new btDefaultMotionState(T);
     btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,boxShape,localInertia);
     btRigidBody* body = new btRigidBody(rbInfo);
     dynamicsWorld->addRigidBody(body);
 }
예제 #4
0
        RigidBody(Object3D* parent, Float mass, btCollisionShape* bShape, btDynamicsWorld& bWorld): Object3D{parent}, _bWorld(bWorld) {
            /* Calculate inertia so the object reacts as it should with
               rotation and everything */
            btVector3 bInertia(0.0f, 0.0f, 0.0f);
            if(!Math::TypeTraits<Float>::equals(mass, 0.0f))
                bShape->calculateLocalInertia(mass, bInertia);

            /* Bullet rigid body setup */
            auto* motionState = new BulletIntegration::MotionState{*this};
            _bRigidBody.emplace(btRigidBody::btRigidBodyConstructionInfo{
                mass, &motionState->btMotionState(), bShape, bInertia});
            _bRigidBody->forceActivationState(DISABLE_DEACTIVATION);
            bWorld.addRigidBody(_bRigidBody.get());
        }
예제 #5
0
 void AddGroundPlane() {
   btTransform groundTransform;
   groundTransform.setIdentity();
   btScalar mass = 0.0f;
   bool isDynamic = (mass != 0.f);
   btVector3 localInertia(0,0,0);
   if (isDynamic)
     groundShape->calculateLocalInertia(mass,localInertia);
   btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
   btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
   btRigidBody* body = new btRigidBody(rbInfo);
   //add the body to the dynamics world
   dynamicsWorld->addRigidBody(body);
 }
예제 #6
0
	btRigidBody* localCreateRigidBody (btScalar mass, const btTransform& startTransform, btCollisionShape* shape)
	{
		bool isDynamic = (mass != 0.f);

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

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

		m_ownerWorld->addRigidBody(body);

		return body;
	}