盒子在子弹物理中不滚动
Posted
技术标签:
【中文标题】盒子在子弹物理中不滚动【英文标题】:Box doesn't roll in Bullet Physics 【发布时间】:2015-08-29 13:51:06 【问题描述】:如图所示,The Box 不会滚动,而是会在斜坡上滑动。
这是我在代码中创建盒子的方法,
config = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(config);
broadphase = new btDbvtBroadphase();
solver = new btSequentialImpulseConstraintSolver();
bWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, config);
bWorld->setGravity(btVector3(0, -9.8f, 0));
// ...
btTransform t;
t.setIdentity();
t.setOrigin(btVector3(position.x, position.y, position.z));
btBoxShape* box = new btBoxShape(btVector3(size.x, size.y, size.z));
btVector3 inertia(0, 0, 0);
float mass = 10.f;
box->calculateLocalInertia(mass, inertia);
btMotionState* mState = new btDefaultMotionState(t);
btRigidBody::btRigidBodyConstructionInfo cInfo(mass, mState, box);
//cInfo.m_restitution = 0.4f;
//cInfo.m_friction = 0.5f;
btRigidBody* body = new btRigidBody(cInfo);
//body->setLinearFactor(btVector3(1,1,0));
//body->setAngularFactor(btVector3(0,0,1));
m_impl->bWorld->addRigidBody(body);
我尝试了摩擦力和其他参数,但结果是一样的。让我知道我在这里做错了什么。
【问题讨论】:
【参考方案1】:您需要将inertia
向量传递给btRigidBodyConstructionInfo
。
检查btRigidBodyConstructionInfo
构造函数上的第四个参数(具有默认值的那个)。
【讨论】:
以上是关于盒子在子弹物理中不滚动的主要内容,如果未能解决你的问题,请参考以下文章