bounding: properly implement collideWith against other bounds

experimental
Kirill Vainer 9 years ago
parent 9f9daa13dc
commit 45f8893f13
  1. 10
      jme3-core/src/main/java/com/jme3/bounding/BoundingBox.java
  2. 12
      jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java
  3. 13
      jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.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());
}

@ -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();
}

@ -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();
}
}
}

Loading…
Cancel
Save