Hey - I have written a bit of code which lists the intersections a ray from the mouse cursor to infinity touches.
The problem is - it occasionally null pointers on the getName() call on geometry. I am presuming this is because some geometry's have no name?? This is probably normal though i would imagine but not necessarily good practice. I get round it with a try catch - however the detail I really want is the node's name , not the geometry's.
Does anybody know how to get that based upon the code I am currently using :
CollisionResults results = new CollisionResults();
System.out.println("
Collisions? " + results.size() + "
");
SnowReference.getRootNode().collideWith(ray, results);
for (int p = 0; p < results.size(); p++) {
// For each hit, we know distance, impact point, name of geometry.
try {
float dist = results.getCollision(p).getDistance();
Vector3f pt = results.getCollision(p).getContactPoint();
String hit = results.getCollision(p).getGeometry().getName();
System.out.println("* Collision #" + p);
System.out.println(" You shot " + hit + " at " + pt + ", " + dist + " wu away.");
} catch (Exception e) {
e.printStackTrace();
}
}