当前位置: 首页>>代码示例>>C++>>正文


C++ btDynamicsWorld::addRigidBody方法代码示例

本文整理汇总了C++中btDynamicsWorld::addRigidBody方法的典型用法代码示例。如果您正苦于以下问题:C++ btDynamicsWorld::addRigidBody方法的具体用法?C++ btDynamicsWorld::addRigidBody怎么用?C++ btDynamicsWorld::addRigidBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在btDynamicsWorld的用法示例。


在下文中一共展示了btDynamicsWorld::addRigidBody方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: localCreateRigidBody

	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;
	}
开发者ID:DanielNappa,项目名称:bullet3,代码行数:60,代码来源:RagdollDemo.cpp

示例2: AddBody

  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);
  }
开发者ID:fedemarino31,项目名称:leaptower,代码行数:33,代码来源:NaClAMBullet.cpp

示例3: AddBox

 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);
 }
开发者ID:fedemarino31,项目名称:leaptower,代码行数:10,代码来源:NaClAMBullet.cpp

示例4: bInertia

        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());
        }
开发者ID:mosra,项目名称:magnum-examples,代码行数:14,代码来源:BulletExample.cpp

示例5: AddGroundPlane

 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);
 }
开发者ID:fedemarino31,项目名称:leaptower,代码行数:14,代码来源:NaClAMBullet.cpp

示例6: localCreateRigidBody

	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;
	}
开发者ID:henryeherman,项目名称:learninghexapod,代码行数:16,代码来源:MotorDemo.cpp


注:本文中的btDynamicsWorld::addRigidBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。