Java JMonkeyEngine几何图形交点NullPointerException

Java JMonkeyEngine几何图形交点NullPointerException,java,nullpointerexception,jmonkeyengine,Java,Nullpointerexception,Jmonkeyengine,一般来说,我不熟悉3d引擎,当我尝试碰撞一个几何体和一个BoundingVolume对象时,我得到了这个NullPointerException 下面是我如何声明我的对象(对不起,现在很混乱) 这是我的更新循环 public void simpleUpdate(float tpf) { // System.out.println("hi"); BoundingVolume b = g3.getWorldBound(); //should give boundingvolume

一般来说,我不熟悉3d引擎,当我尝试碰撞一个几何体和一个BoundingVolume对象时,我得到了这个NullPointerException

下面是我如何声明我的对象(对不起,现在很混乱)

这是我的更新循环

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;当我试图打印边界体积和几何体相交的每个碰撞结果的坐标时,dr得到一个NullPointerException


JMonkey论坛和JMonkey文档似乎都没有任何帮助。你们谁能帮忙?提前感谢。

我做了一些研究,我相信问题在于两个2D/3D对象之间没有一个碰撞点,而是存在一个2D/3D碰撞区域。因此,由于没有可用的单点,因此返回null。这一点得到了国际社会的支持。我相信JMonkey碰撞检测实际上并没有计算相交区域,因为它在数学上相当复杂(尽管它确实给出了碰撞中涉及的三角形)


如果你的两个形状都是凸的,你可能会对这篇关于计算三维多边形交点的文章感兴趣:。

你的模型没有附加到JBullet physics上。 试着这样做:

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

之后,您可以检查碰撞

有趣。我知道存在一个几何相交区域,但我不知道单个点无法检索。我可以用射线测试或者其他方法,谢谢。
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);
}