在jMonkeyEngine的物理模拟中使用空心形状(环)

时间:2014-10-22 17:26:10

标签: collision shape jmonkeyengine

我正试图在JMonkey中制作一个环形折腾游戏,但是当我尝试使用Torus时它只是在销钉上弹跳(因为碰撞扩散到空心中心)。
我一直在寻找一种让Torus工作的方法,以及戒指的替代品,但我找不到任何有用的东西。
任何有关修复的提示或提示都非常感谢。

1 个答案:

答案 0 :(得分:0)

默认情况下,物理引擎(Bullet)使用简单的形状,可以轻松快速地计算碰撞。圆环看起来像物理引擎的盒子。要使其凹陷,您可以将圆环的网格转换为Bullet接受的CollisionShape 这里列出了可用的类:http://hub.jmonkeyengine.org/wiki/doku.php/jme3:advanced:physics

GImpactCollisionShape是适用于动态凹面物体的public void simpleInitApp() { Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/ShowNormals.j3md"); // Create pin Cylinder cylinderMesh = new Cylinder(4, 12, 1.0f, 7.0f, true); Geometry pin = new Geometry("Pin", cylinderMesh); pin.setMaterial(mat); pin.rotate(90 * FastMath.DEG_TO_RAD, 0, 0); // Create a smooth ring Torus torusMesh = new Torus(64, 48, 1.0f, 3.0f); Geometry ring = new Geometry("Ring", torusMesh); ring.setMaterial(mat); ring.rotate(90 * FastMath.DEG_TO_RAD, 0, 0); ring.rotate(0, 51 * FastMath.DEG_TO_RAD, 0); ring.setLocalTranslation(0, 10, 0); rootNode.attachChild(pin); rootNode.attachChild(ring); // Define the shape that the ring uses for collision checks Torus simpleTorusMesh = new Torus(16, 12, 1.0f, 3.0f); GImpactCollisionShape collisionShape = new GImpactCollisionShape(simpleTorusMesh); ring.addControl(new RigidBodyControl(collisionShape, 0.1f)); // Default CollisionShape for the pin pin.addControl(new RigidBodyControl(0)); BulletAppState bulletState = new BulletAppState(); stateManager.attach(bulletState); bulletState.getPhysicsSpace().add(pin); bulletState.getPhysicsSpace().add(ring); cam.setLocation(new Vector3f(20, 5, 35)); cam.lookAt(new Vector3f(0, 4, 0), Vector3f.UNIT_Y); flyCam.setMoveSpeed(30); } 。它附带了一个可以方便地转换网格的构造函数。

然而,复杂的形状意味着更多的发动机工作。使用粗略近似值作为CollisionShape通常就足够了。这是一个使用复杂圆环进行显示的示例,以及一个更简单的物理模拟示例:

{{1}}