基于此tutorial,我已将bullet物理添加到我的opengl引擎中。气缸碰撞器与其他气缸碰撞完美,但它们似乎不会碰撞箱式碰撞器。这是我用来设置我的世界的代码:
btBroadphaseInterface* broadphase = new btDbvtBroadphase();
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* collisionDispatcher = new btCollisionDispatcher(collisionConfiguration);
btSequentialImpulseConstraintSolver* collisionSolver = new btSequentialImpulseConstraintSolver();
btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(collisionDispatcher, broadphase, collisionSolver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0, -10, 0));
// create collision shapes:
// the box is part of the terrain and cannot move, set mass to 0 for now
btCollisionShape* box = new btBoxShape(btVector3(box_length.x, box_length.y, box_length.z));
btDefaultMotionState* box_motion_state = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(box_position.x, box_position.y, box_position.z)));
btRigidBody* box_body = new btRigidBody(btRigidBody::btRigidBodyConstructionInfo(btScalar(0.0f), box_motion_state, box, btVector3(0, 0, 0)));
dynamicsWorld->addRigidBody(box_body);
// the cylinder can move. Mass = 1.0 for now
btCollisionShape* cylinder = new btCylinderShape(btVector3(radius, height, radius));
btDefaultMotionState* cylinder_motion_state = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(cylinder_position.x, cylinder_position.y, cylinder_position.z)));
btRigidBody* cylinder_body = new btRigidBody(btRigidBody::btRigidBodyConstructionInfo(btScalar(1.0f), cylinder_motion_state, cylinder, btVector3(0, 0, 0)));
dynamicsWorld->addRigidBody(cylinder_body);
// ... Carry out same process for every other shape in scene
我知道这个代码正在使形状正确,因为我的btIDebugDraw类完美呈现了所有的碰撞形状。再次气缸到气缸的碰撞都没问题,但我似乎无法让气缸到气缸碰撞工作。
答案 0 :(得分:0)
我明白了。事实证明我的z长度是负面的。使用绝对数学函数修复它。