bounding: properly implement collideWith against other bounds
This commit is contained in:
parent
9f9daa13dc
commit
45f8893f13
@ -790,6 +790,7 @@ public class BoundingBox extends BoundingVolume {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int collideWith(Collidable other, CollisionResults results) {
|
public int collideWith(Collidable other, CollisionResults results) {
|
||||||
if (other instanceof Ray) {
|
if (other instanceof Ray) {
|
||||||
Ray ray = (Ray) other;
|
Ray ray = (Ray) other;
|
||||||
@ -802,6 +803,13 @@ public class BoundingBox extends BoundingVolume {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
} else if (other instanceof BoundingVolume) {
|
||||||
|
if (intersects((BoundingVolume) other)) {
|
||||||
|
CollisionResult r = new CollisionResult();
|
||||||
|
results.addCollision(r);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedCollisionException("With: " + other.getClass().getSimpleName());
|
throw new UnsupportedCollisionException("With: " + other.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
@ -818,6 +826,8 @@ public class BoundingBox extends BoundingVolume {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
} else if (other instanceof BoundingVolume) {
|
||||||
|
return intersects((BoundingVolume) other) ? 1 : 0;
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedCollisionException("With: " + other.getClass().getSimpleName());
|
throw new UnsupportedCollisionException("With: " + other.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
|
@ -1013,17 +1013,27 @@ public class BoundingSphere extends BoundingVolume {
|
|||||||
} else if (other instanceof Triangle){
|
} else if (other instanceof Triangle){
|
||||||
Triangle t = (Triangle) other;
|
Triangle t = (Triangle) other;
|
||||||
return collideWithTri(t, results);
|
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 {
|
} else {
|
||||||
throw new UnsupportedCollisionException();
|
throw new UnsupportedCollisionException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public int collideWith(Collidable other) {
|
@Override
|
||||||
|
public int collideWith(Collidable other) {
|
||||||
if (other instanceof Ray) {
|
if (other instanceof Ray) {
|
||||||
Ray ray = (Ray) other;
|
Ray ray = (Ray) other;
|
||||||
return collideWithRay(ray);
|
return collideWithRay(ray);
|
||||||
} else if (other instanceof Triangle){
|
} else if (other instanceof Triangle){
|
||||||
return super.collideWith(other);
|
return super.collideWith(other);
|
||||||
|
} else if (other instanceof BoundingVolume) {
|
||||||
|
return intersects((BoundingVolume)other) ? 1 : 0;
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedCollisionException();
|
throw new UnsupportedCollisionException();
|
||||||
}
|
}
|
||||||
|
@ -327,12 +327,13 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
|
|||||||
|
|
||||||
public int collideWith(Collidable other) {
|
public int collideWith(Collidable other) {
|
||||||
TempVars tempVars = TempVars.get();
|
TempVars tempVars = TempVars.get();
|
||||||
CollisionResults tempResults = tempVars.collisionResults;
|
try {
|
||||||
tempResults.clear();
|
CollisionResults tempResults = tempVars.collisionResults;
|
||||||
int retval = collideWith(other, tempResults);
|
tempResults.clear();
|
||||||
tempVars.release();
|
return collideWith(other, tempResults);
|
||||||
return retval;
|
} finally {
|
||||||
|
tempVars.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user