2014-09-30 2 views
1

저는 일반적으로 3D 엔진을 처음 사용합니다. 기하학과 BoundingVolume 객체를 충돌 시키려고하면이 NullPointerException이 발생합니다. 여기JMonkeyEngine- 기하학 교차점 NullPointerException

내가 내 개체 (죄송합니다,이 순간에 오히려 혼란의)

public void simpleInitApp() { 



    Quad q= new Quad(100, 100); 
    Dome mesh = new Dome(Vector3f.ZERO, 2, 32, 1f,false); 

    geom = new Geometry("Cylinder", mesh); //declared elsewhere 

    g3 = new Geometry("lel", q); 
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 
    mat.setColor("Color", ColorRGBA.Blue); 
    Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 
    mat2.setColor("Color", ColorRGBA.Red); 
    geom.setMaterial(mat); 

    g3.setMaterial(mat2); 

    rootNode.attachChild(geom); 
    rootNode.attachChild(g3); 

여기 내 업데이트 루프

public void simpleUpdate(float tpf) { 

    // System.out.println("hi"); 
    BoundingVolume b = g3.getWorldBound(); //should give boundingvolume of the quad 

    System.out.println(b.getVolume()); //just to test if this works 
    CollisionResults r2 = new CollisionResults(); //declare and initialize the collisionresults 
    geom.collideWith(b, r2); //collide 
    System.out.println(r2.size()); //this returns a value, usually between 0-2 


    for(CollisionResult x:r2){ 


     System.out.println("x = "+ x.getContactPoint().getX()); 
    /*and oddly enough, i get a NullPointerException here even though the collision appeared successful - this never prints anything either so it's not going out of bounds or anything*/ 


    } 


} 

TL의 선언 방법은, 내가하려고 할 때 NullPointerException이 DR-수 BoundingVolume과 Geometry의 교차점에서 각 CollisionResult의 좌표를 인쇄하십시오.

JMonkey 포럼이나 JMonkey 문서는 도움이되지 않습니다. 당신 중 누구라도 도울 수 있습니까? 미리 감사드립니다.

답변

1

귀하의 모델은 JBullet 물리학에 첨부되지 않았습니다. 이 같은 시도의 SG : 당신이 충돌을 확인할 수 후

BulletAppState buleltAppState; 

public void simpleInitApp() { 

    Quad q= new Quad(100, 100); 
    Dome mesh = new Dome(Vector3f.ZERO, 2, 32, 1f,false); 

    geom = new Geometry("Cylinder", mesh); //declared elsewhere 

    g3 = new Geometry("lel", q); 
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 
    mat.setColor("Color", ColorRGBA.Blue); 
    Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 
    mat2.setColor("Color", ColorRGBA.Red); 
    geom.setMaterial(mat); 

    g3.setMaterial(mat2); 

    bulletAppState = new BulletAppState(); 
    stateManager.attach(bulletAppState); 
    bulletAppState.getPhysicsSpace().attachChild(geom); 
    bulletAppState.getPhysicsSpace().attachChild(g3); 

    rootNode.attachChild(geom); 
    rootNode.attachChild(g3); 
} 

!

+0

나는 피 묻은 바보 야 ... 고마워. – user2701956

0

내가 조금 연구를 봤는데, 문제가 2 2D/3D 객체 사이에 하나의 충돌 지점이되지 않는 것입니다 생각하는 2D/3D 충돌 지역있다. 따라서 단일 점을 사용할 수 없으므로 null이 반환됩니다. 이것은 a comment by a developer에 의해 백업됩니다. 나는 JMonkey 충돌 탐지가 실제로 수학적으로 복잡하기 때문에 실제로 교차 영역을 계산하지 않는다고 믿는다. (충돌에 관련된 삼각형을 제공한다.)

두 모양이 모두 볼록하다면 계산시이 포스트에 관심이있을 수있다. 3 차원 다각형 교차점 : Finding the intersection of two 3D polygons.

+0

흥미 롭습니다. 기하학적 인 교차점이 있음을 알았지 만 개별 점을 가져올 수 없다는 것을 전혀 모릅니다. 나는 그저 광선 검사 나 그저 뭔가를 사용할지도 모른다. 고마워. – user2701956