JBullet - 凸形在静态时不能正常工作

时间:2015-07-06 14:53:08

标签: java physics jbullet

我在JBullet中使用动态框形体进行碰撞。它们正确地相互碰撞。但是,我正在摆弄建筑世界,并遇到了一些奇怪的问题。

当我试图将凸RigidBodies(BoxShape或TriangleShape)设置为静态(通过将质量设置为0)时,碰撞仅在(0,0,0)处的某种点处起作用而不是给定的形状。如果它是动态的,它运作良好。

附加问题,也许还有一些链接:如果我使用BvhTriangleMeshShape或者GImpactMeshShape,它只在动态时才能正常工作,并且当它是静态的时候不会碰撞0(尽管事实上BvhTriangleMeshShape用于静态物体)。

以下是我如何创造世界:

BroadphaseInterface broadphase = new DbvtBroadphase();
CollisionConfiguration collisionConfiguration = new DefaultCollisionConfiguration();
CollisionDispatcher dispatcher = new CollisionDispatcher(collisionConfiguration);
ConstraintSolver solver = new SequentialImpulseConstraintSolver();
dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
dynamicsWorld.setGravity(new Vector3f(0, 0, 0));
GImpactCollisionAlgorithm.registerAlgorithm(dispatcher);

有问题的对象:

Vector3f inertia = new Vector3f(0, 0, 0);
MotionState motion = new DefaultMotionState(new Transform());

//BvhTriangleMeshShape shape = ShapeUtil.getShapeFromModel(testSphere);
//CompoundShape shape = ShapeUtil.getCompoundShapeFromModel(testSphere);
//GImpactMeshShape shape = ShapeUtil.getGImpactShapeFromModel(testSphere);
BoxShape shape = new BoxShape (new Vector3f(2,2,2));
//TriangleShape shape = new TriangleShape(new Vector3f(-20,0,-10), new Vector3f(20,20,-10), new Vector3f(20,-20,-10));

RigidBodyConstructionInfo constructionInfo = new RigidBodyConstructionInfo(0, motion, shape, inertia);
RigidBody body = new RigidBody(constructionInfo);
//body.setCollisionFlags(CollisionFlags.STATIC_OBJECT);

dynamicsWorld.addRigidBody(body);
this.bodies[64] = body;

任何人都可以帮助我吗?我正在使用2010年10月10日的JBullet版本。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

我似乎发现了这个问题。我通过替换

来解决这个问题
MotionState motion = new DefaultMotionState(new Transform());

通过

Transform transform = new Transform();
transform.setIdentity();
MotionState motion = new DefaultMotionState(transform);

看起来Transform的默认构造函数不会像我期望的那样创建一个标识变换。