I’ve been working on doing some collisions with rays and BoundingBoxes and found some behavior that seems unexpected. Whenever I have an Ray point at a volume, but the volume is beyond the limit of the Ray, a collision is still being detected. Additionally, it seems collisions are being detected along the negative axis of the ray, i.e. when the ray is pointed away from the volume.
Both of these seem very odd to me and I was wondering if this behavior is intended. I’ve compiled some unit tests around how I believe the collision should be registered, am I off the rocker, or is this behaving strangely?
public class JmonkeyTest {
@Test //Passes
public void testCollisionWhilePointedAtVolume() {
BoundingVolume volume = new BoundingBox(Vector3f.ZERO, 1, 1, 1);
Ray ray = new Ray(new Vector3f(10f, 0f, 0f), new Vector3f(-1, 0f, 0f));
CollisionResults results = new CollisionResults();
ray.collideWith(volume, results);
assertTrue(results.size() > 0);
}
//Edit : This one was failing due to an assertion in Ray:479
//@Test
//public void testNoCollisionPointedAway() {
// BoundingVolume volume = new BoundingBox(Vector3f.ZERO, 1, 1, 1);
// Ray ray = new Ray(new Vector3f(10f, 0f, 0f), new Vector3f(100, 0f, 0f));
// CollisionResults results = new CollisionResults();
// ray.collideWith(volume, results);
// assertTrue(results.size() == 0);
//}
@Test //Fails
public void testNoCollisionWhenOutsideLimit() {
BoundingVolume volume = new BoundingBox(Vector3f.ZERO, 1, 1, 1);
Ray ray = new Ray(new Vector3f(10f, 0f, 0f), new Vector3f(-1, 0f, 0f));
ray.setLimit(1);
CollisionResults results = new CollisionResults();
ray.collideWith(volume, results);
assertTrue(results.size() == 0);
}
}