我试图用子弹定位圆柱体。现在,气缸是模拟中唯一的东西。我在这里找到了一些答案,并且相信我很接近,但仍然没有轮换。这是我创建圆柱体的功能,也许会有人跳出来。
我做错了什么?
void CreateCylinder(int index, double x, double y, double z, double radius, double length, int yaw, int pitch, int roll) {
btScalar mass = 1;
btVector3 position(x,y,z);
btVector3 cylInertia(0,0,0);
//create collision shape
btCollisionShape* cylColl = new btCylinderShape(btVector3(radius,length,1));
//default motion state
btDefaultMotionState* ms = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0,10,0)));
//calculate inertia
cylColl->calculateLocalInertia(mass, cylInertia);
//construction info
btRigidBody::btRigidBodyConstructionInfo cylCI(
mass,
ms,
cylColl, //collision shape
cylInertia //inertia
);
btRigidBody *cylinder = new btRigidBody(cylCI);
//orient cylinder
btTransform tr;
tr.setIdentity();
btQuaternion quat;
quat.setEuler(yaw,pitch,roll); //or quat.setEulerZYX depending on the ordering you want
tr.setRotation(quat);
//apply transform to cylinder rigid body
cylinder->setCenterOfMassTransform(tr);
body[index] = cylinder;
m_dynamicsWorld->addRigidBody(body[index]);
}
答案 0 :(得分:1)
您必须修改正文的WorldTransform
,而不是CenterOfMassTransform
。您可以在DefaultMotionState以及Body本身中执行此操作。