2014-10-22 2 views
0

JMonkey에서 링 던지기 게임을 만들려고하지만 Torus를 사용하여봤을 때 핀이 튀어 나오게됩니다.).
저는 Torus가 작동하도록하는 방법을 찾고 있었고, 링의 대안을 찾고 있었지만 작동하는 것을 찾을 수 없었습니다.
수정 사항에 대한 팁이나 힌트는 정말 감사하겠습니다.jMonkeyEngine의 물리 시뮬레이션에서 중공 모양 (링) 사용

답변

0

기본적으로 물리 엔진 (Bullet)은 충돌 계산을 쉽고 빠르게하는 간단한 모양을 사용합니다. 원환 체는 아마 물리학 엔진의 상자처럼 보입니다. 그것을 비어있게 만들려면 토러스의 메쉬를 불릿에서 허용하는 CollisionShape으로 변환하면됩니다.
사용 가능한 클래스는 여기에 나열되어 있습니다. http://hub.jmonkeyengine.org/wiki/doku.php/jme3:advanced:physics

GImpactCollisionShape은 동적 인 오목한 개체에 적합합니다. 메쉬를 편리하게 변환하는 생성자가 제공됩니다.

그러나 복잡한 모양은 엔진에 더 많은 작업을 의미합니다. CollisionShape와 같이 대충 근사를 사용하는 것으로 충분합니다. 다음은 디스플레이에 복잡한 토러스를 사용하고 물리 시뮬레이션을 위해 더 간단한 토러스를 사용하는 예입니다.

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); 
}