Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 子弹物理缸对箱碰撞_C++_Bulletphysics - Fatal编程技术网

C++ 子弹物理缸对箱碰撞

C++ 子弹物理缸对箱碰撞,c++,bulletphysics,C++,Bulletphysics,基于此,我将子弹物理添加到我的opengl引擎中。圆柱体碰撞器与其他圆柱体完全碰撞,但它们似乎不会与长方体碰撞器碰撞。以下是我用来设置我的世界的代码: btBroadphaseInterface* broadphase = new btDbvtBroadphase(); btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); btCollisionDispat

基于此,我将子弹物理添加到我的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类完美地呈现了所有碰撞形状。再一次,圆柱体到圆柱体的碰撞是可以的,但我似乎无法让圆柱体到长方体的碰撞起作用

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

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