我在 JBullet 中使用动态盒形物体进行碰撞。它们正确地相互碰撞。但我在构建世界时遇到了一些奇怪的问题。
当我尝试使凸刚体(BoxShape 或 TriangleShape)静态(通过将质量设置为 0)时,碰撞仅在 (0,0,0) 处的某种点起作用,而不是在给定的形状处起作用。如果它是动态的,那么它运行良好。
额外的问题,也许有一些链接:如果我使用 BvhTriangleMeshShape 或 GImpactMeshShape,只有在动态时它才能正常工作,并且在静态时不会发生碰撞(尽管事实上 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 版本。 提前致谢。
最佳答案
看来我发现了问题。我通过更换线路解决了这个问题
MotionState motion = new DefaultMotionState(new Transform());
由
Transform transform = new Transform();
transform.setIdentity();
MotionState motion = new DefaultMotionState(transform);
看起来 Transform 的默认构造函数不会像我期望的那样创建身份 Transform。
关于java - JBullet - 静态时凸形状无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31249008/