如何使球体在bullet3d中旋转

时间:2009-07-12 20:10:06

标签: iphone bulletphysics

我正在使用Bullet3D中的FallingCubes演示,并注意到立方体在碰撞时会旋转。但是,当我将程序更改为使用spheres(btSphereShape)时,它们不会旋转。请注意,我正在使用iphone sdk。有没有人对如何让这些球体旋转有任何建议?以下是一些相关代码:

btTransform bodyTransform;
bodyTransform.setIdentity();
bodyTransform.setOrigin(btVector3(0,10+i*3,0));
//btCollisionShape* boxShape = new btBoxShape(btVector3(1,1,1));
btCollisionShape* boxShape = new btSphereShape(0.5f);
btScalar mass(1.);//positive mass means dynamic/moving  object
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0);
if (isDynamic)
   boxShape->calculateLocalInertia(mass,localInertia);

btDefaultMotionState* myMotionState = new btDefaultMotionState(bodyTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,
                                               boxShape,localInertia);
btRigidBody* boxBody=new btRigidBody(rbInfo);
boxBody->setFriction(.3f);
sBoxBodies.push_back(boxBody);

boxBody->setActivationState(DISABLE_DEACTIVATION);
//add the body to the dynamics world
sDynamicsWorld->addRigidBody(boxBody);      

1 个答案:

答案 0 :(得分:1)

您可以添加联系人事件处理程序并在那里设置旋转。