我已尝试首先设置6dof约束。然而,无论我是否添加约束,刚体都表现相同,直接落到地面,我可以自由地拖动它们。所以我添加了一个滑块约束来测试它是否只是我的6dof设置的问题。仍然没有运气。我查看了子弹源限制演示,甚至我的一些旧代码成功使用了子弹约束。我在初始化时遗漏了一些简单的东西,可能是新鲜的眼睛可以发现吗?
编辑:使用bullet 2.81 rev 2613
子弹设置
btBroadphaseInterface* broadphase =new btDbvtBroadphase();
btDefaultCollisionConfiguration* collisionConfiguration =new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher =new btCollisionDispatcher(collisionConfiguration);
btSequentialImpulseConstraintSolver* solver =new btSequentialImpulseConstraintSolver;
bullet_dynamics_world =new btDiscreteDynamicsWorld(
dispatcher,broadphase,solver,collisionConfiguration);
bullet_dynamics_world->setGravity(btVector3(0,-10.0f,0));
刚体设置
btConvexHullShape* part_shape(new btConvexHullShape());
part_shape->addPoint(vp0);
part_shape->addPoint(vp1);
part_shape->addPoint(vp2);
part_shape->addPoint(vp3);
btVector3 intertia(0.0f,0.0f,0.0f);
part_shape->calculateLocalInertia(1.0,intertia);
start_trans.setOrigin(start_trans.getOrigin()+center);
quetz::CBulletMotionState* motion_state(new CBulletMotionState(part, start_trans));
btRigidBody* part_body(0);
btRigidBody::btRigidBodyConstructionInfo inf(1.0f, motion_state, part_shape,intertia);
part_body =new btRigidBody(inf);
part_body->setUserPointer(this);
part_body->setMotionState(motion_state);
part_body->setWorldTransform(motion_state->absolute_transform);
part_body->setActivationState(DISABLE_DEACTIVATION);
core->bullet_dynamics_world->addRigidBody(part_body);
约束设置代码
btTransform fromA(btTransform::getIdentity());
btTransform fromB(btTransform::getIdentity());
fromA.setOrigin( btVector3(-1.0f,0.0f,0.0f));
fromB.setOrigin( btVector3(1.0f,0.0f,0.0f));
btRigidBody* ref_bodyA(partA->m_physics);
btSliderConstraint* bt_constraint =
new btSliderConstraint(
*ref_bodyA,
fromB,true);
bt_constraint->setLowerLinLimit(-10.0f);
bt_constraint->setUpperLinLimit(10.0f);
bt_constraint->setLowerAngLimit(0.0f);
bt_constraint->setUpperAngLimit(0.0f);
core->bullet_dynamics_world->addConstraint(bt_constraint, false);