【问题标题】:Bullet physics Cylinder to Box collisionBullet 物理 Cylinder to Box 碰撞
【发布时间】:2016-06-19 02:32:42
【问题描述】:

基于tutorial,我在我的 opengl 引擎中添加了子弹物理。 Cylinders colliders 与其他圆柱体完美碰撞,但它们似乎与 box colliders 没有碰撞。这是我用来设置我的世界的代码:

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 类完美地呈现了所有碰撞形状。再一次圆柱到圆柱的碰撞是可以的,但我似乎无法让圆柱到盒子的碰撞起作用。

【问题讨论】:

    标签: c++ bulletphysics


    【解决方案1】:

    我想通了。结果我的z长度是负的。使用绝对数学函数修复它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-27
      相关资源
      最近更新 更多