1

I'm new to 3d engines in general, and I'm getting this NullPointerException when I try to collide a Geometry and a BoundingVolume object.

Here's how I declare my objects (sorry, it's rather messy at the moment)

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

and here's my update loop

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-get a NullPointerException when I try to print off the coordinates of each CollisionResult from the intersection of a BoundingVolume and a Geometry

Neither the JMonkey Forums nor the JMonkey docs seem to be of any assistance. Would any of you be able to help? Thanks in advance.

2 Answers2

1

Your models not attached to JBullet physics. try sg like this:

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

after that you can check collision!

Paal Gyula
  • 28
  • 5
0

I've done a little research and I believe the problem is that there isn't a single collision point between 2 2D/3D objects, there is a 2D/3D collision region. Therefore null is returned as no single point is available. This is backed up by a comment by a developer. I believe the JMonkey collision detection doesn't actually calculate the intersection region because its quite mathematically complex (although it does give the triangle involved in the collision)

If both your shapes are convex you may be interested in this post on calculating 3d polygon intersections: Finding the intersection of two 3D polygons.

Community
  • 1
  • 1
Richard Tingle
  • 16,906
  • 5
  • 52
  • 77
  • Interesting. I knew that there was a geometric region of intersection but I had no idea individual points couldn't be retrieved. I may just use ray tests or something in that case, thanks. – user2701956 Oct 01 '14 at 18:33