Ray used for selection not returning any results
So I have this program, were I need to select a building from a birds eye view. I used the tutorial for mouse selection to create this code:
CollisionResults results = new CollisionResults();
Vector2f click2d = Start.MAIN_STATIC_REF.getInputManager().getCursorPosition();
Vector3f click3d = Start.MAIN_STATIC_REF.getCamera().getWorldCoordinates(click2d, 1f).clone();
Vector3f dir = Start.MAIN_STATIC_REF.getCamera().getWorldCoordinates(new Vector2f(click2d.x,click2d.y), 0f);
Ray ray = new Ray(click3d,dir);
fps.addArrow("Mouse_Selection_Path",click3d, dir, ColorRGBA.Green);
fps.main.getRootNode().collideWith(ray, results);
CollisionResult result = results.getClosestCollision();
System.out.println("Mouse selection closest result out of " + results.size());
Vector2f loc = new Vector2f(result.getContactPoint().x,result.getContactPoint().z);
System.out.println("Click selection at " + loc);
For some reason I was getting a NullPointer when trying to access getContactPoint(), and on further inspection results.size() returns 0! fps.main is a reference to the SimpleApplication. fps.addArrow just adds a geometry to the scene of an arrow which represents a vector. I was using it to check weather the ray was actually going in that direction. Could somebody please help?