Skip to content

Commit e2e9a94

Browse files
jMonkeyEngine#2284 Double check the collision really has happened in world space (jMonkeyEngine#2285)
(otherwise glancing blows can end up "happening" but at infinite distance due to numerical precision)
1 parent bc346ed commit e2e9a94

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

jme3-core/src/main/java/com/jme3/collision/bih/BIHNode.java

+14-9
Original file line numberDiff line numberDiff line change
@@ -411,15 +411,20 @@ public final int intersectWhere(Ray r,
411411
t = t_world;
412412
}
413413

414-
Vector3f contactNormal = Triangle.computeTriangleNormal(v1, v2, v3, null);
415-
Vector3f contactPoint = new Vector3f(d).multLocal(t).addLocal(o);
416-
float worldSpaceDist = o.distance(contactPoint);
417-
418-
CollisionResult cr = new CollisionResult(contactPoint, worldSpaceDist);
419-
cr.setContactNormal(contactNormal);
420-
cr.setTriangleIndex(tree.getTriangleIndex(i));
421-
results.addCollision(cr);
422-
cols++;
414+
// this second isInfinite test is unlikely to fail but due to numeric precision it might
415+
// be the case that in local coordinates it just hits and in world coordinates it just misses
416+
// this filters those cases out (treating them as misses).
417+
if (!Float.isInfinite(t)){
418+
Vector3f contactNormal = Triangle.computeTriangleNormal(v1, v2, v3, null);
419+
Vector3f contactPoint = new Vector3f(d).multLocal(t).addLocal(o);
420+
float worldSpaceDist = o.distance(contactPoint);
421+
422+
CollisionResult cr = new CollisionResult(contactPoint, worldSpaceDist);
423+
cr.setContactNormal(contactNormal);
424+
cr.setTriangleIndex(tree.getTriangleIndex(i));
425+
results.addCollision(cr);
426+
cols++;
427+
}
423428
}
424429
}
425430
}

0 commit comments

Comments
 (0)