子弹物理盒不旋转
我使用下面的代码来设置一个简单的世界使用子弹物理引擎。 当我运行它时,由于它们不旋转,所以这些盒子并不现实。 这就像他们的旋转被锁定。 有没有人见过这样的事情,或知道可能是什么原因造成的? 谢谢。
World::World()
{
mBroadphase = new btDbvtBroadphase();
mCollisionConfiguration = new btDefaultCollisionConfiguration();
mDispatcher = new btCollisionDispatcher(mCollisionConfiguration);
mSolver = new btSequentialImpulseConstraintSolver();
mWorld = new btDiscreteDynamicsWorld(mDispatcher, mBroadphase, mSolver, mCollisionConfiguration);
mWorld->setGravity(btVector3(0, -10, 0));
mGroundShape = new btStaticPlaneShape(btVector3(0, 1, 0), 1);
mBoxShape = new btBoxShape(btVector3(4, 1.5, 1));
mGroundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, -10, 0)));
btRigidBody::btRigidBodyConstructionInfo groundRBCI(0, mGroundMotionState, mGroundShape, btVector3(0, 0, 0));
mGroundRigidBody = new btRigidBody(groundRBCI);
mGroundRigidBody->setUserIndex(1);
mWorld->addRigidBody(mGroundRigidBody);
btScalar mass = 1;
btVector3 boxInertia(0, 0, 0);
mBoxShape->calculateLocalInertia(mass, boxInertia);
mBoxMotionState1 = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 35, -20)));
btRigidBody::btRigidBodyConstructionInfo BoxRBCI1(mass, mBoxMotionState1, mBoxShape, btVector3(0, 0, 0));
mBoxRigidBody1 = new btRigidBody(BoxRBCI1);
mBoxRigidBody1->setUserIndex(2);
mBoxMotionState2 = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(2, 20, -20)));
btRigidBody::btRigidBodyConstructionInfo BoxRBCI2(mass, mBoxMotionState2, mBoxShape, btVector3(0, 0, 0));
mBoxRigidBody2 = new btRigidBody(BoxRBCI2);
mBoxRigidBody2->setUserIndex(3);
mBoxMotionState3 = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(-5, 12, -20)));
btRigidBody::btRigidBodyConstructionInfo BoxRBCI3(mass, mBoxMotionState3, mBoxShape, btVector3(0, 0, 0));
mBoxRigidBody3 = new btRigidBody(BoxRBCI3);
mBoxRigidBody3->setUserIndex(4);
mWorld->addRigidBody(mBoxRigidBody1);
mWorld->addRigidBody(mBoxRigidBody2);
mWorld->addRigidBody(mBoxRigidBody3);
}
啊哈! 我有这个问题,我无法找到年龄的答案,所以我很乐意提供帮助!
该线
mBoxShape->calculateLocalInertia(mass, boxInertia);
修改boxInertia
,然后您需要将它传递给构造函数btRigidBody::btRigidBodyConstructionInfo
如下所示:
btRigidBody::btRigidBodyConstructionInfo BoxRBCI1(mass, mBoxMotionState1, mBoxShape, boxInertia);
然后你的盒子应该旋转:)
链接地址: http://www.djcxy.com/p/95475.html