From 45f8893f13ea19c16287da95734baabb10e3ff5d Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Sun, 13 Sep 2015 18:40:08 -0400 Subject: [PATCH] bounding: properly implement collideWith against other bounds --- .../main/java/com/jme3/bounding/BoundingBox.java | 10 ++++++++++ .../main/java/com/jme3/bounding/BoundingSphere.java | 12 +++++++++++- .../main/java/com/jme3/bounding/BoundingVolume.java | 13 +++++++------ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/bounding/BoundingBox.java b/jme3-core/src/main/java/com/jme3/bounding/BoundingBox.java index bdba19fe3..11ee8b2ea 100644 --- a/jme3-core/src/main/java/com/jme3/bounding/BoundingBox.java +++ b/jme3-core/src/main/java/com/jme3/bounding/BoundingBox.java @@ -790,6 +790,7 @@ public class BoundingBox extends BoundingVolume { } } + @Override public int collideWith(Collidable other, CollisionResults results) { if (other instanceof Ray) { Ray ray = (Ray) other; @@ -802,6 +803,13 @@ public class BoundingBox extends BoundingVolume { return 1; } return 0; + } else if (other instanceof BoundingVolume) { + if (intersects((BoundingVolume) other)) { + CollisionResult r = new CollisionResult(); + results.addCollision(r); + return 1; + } + return 0; } else { throw new UnsupportedCollisionException("With: " + other.getClass().getSimpleName()); } @@ -818,6 +826,8 @@ public class BoundingBox extends BoundingVolume { return 1; } return 0; + } else if (other instanceof BoundingVolume) { + return intersects((BoundingVolume) other) ? 1 : 0; } else { throw new UnsupportedCollisionException("With: " + other.getClass().getSimpleName()); } diff --git a/jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java b/jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java index d5dd56203..adb763f83 100644 --- a/jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java +++ b/jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java @@ -1013,17 +1013,27 @@ public class BoundingSphere extends BoundingVolume { } else if (other instanceof Triangle){ Triangle t = (Triangle) other; return collideWithTri(t, results); + } else if (other instanceof BoundingVolume) { + if (intersects((BoundingVolume)other)) { + CollisionResult result = new CollisionResult(); + results.addCollision(result); + return 1; + } + return 0; } else { throw new UnsupportedCollisionException(); } } - @Override public int collideWith(Collidable other) { + @Override + public int collideWith(Collidable other) { if (other instanceof Ray) { Ray ray = (Ray) other; return collideWithRay(ray); } else if (other instanceof Triangle){ return super.collideWith(other); + } else if (other instanceof BoundingVolume) { + return intersects((BoundingVolume)other) ? 1 : 0; } else { throw new UnsupportedCollisionException(); } diff --git a/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java b/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java index f9be2e573..4491fcedf 100644 --- a/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java +++ b/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java @@ -327,12 +327,13 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable { public int collideWith(Collidable other) { TempVars tempVars = TempVars.get(); - CollisionResults tempResults = tempVars.collisionResults; - tempResults.clear(); - int retval = collideWith(other, tempResults); - tempVars.release(); - return retval; + try { + CollisionResults tempResults = tempVars.collisionResults; + tempResults.clear(); + return collideWith(other, tempResults); + } finally { + tempVars.release(); + } } - }