@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(); } }
public int collideWith(Collidable other, CollisionResults results) { if (other instanceof Ray) { Ray ray = (Ray) other; return collideWithRay(ray, results); } 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 if (other instanceof Spatial) { return ((Spatial)other).collideWith(this, results); } else { throw new UnsupportedCollisionException(); } }
@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(); } }
public int collideWith(Collidable other, CollisionResults results) { if (other instanceof Ray) { Ray ray = (Ray) other; return collideWithRay(ray, results); } 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 if (other instanceof Spatial) { return ((Spatial)other).collideWith(this, results); } else { throw new UnsupportedCollisionException(); } }
public int collideWith(Collidable other, CollisionResults results) { if (other instanceof Ray) { Ray ray = (Ray) other; return collideWithRay(ray, results); } else if (other instanceof Triangle){ Triangle t = (Triangle) other; float r2 = radius * radius; float d1 = center.distanceSquared(t.get1()); float d2 = center.distanceSquared(t.get2()); float d3 = center.distanceSquared(t.get3()); if (d1 <= r2 || d2 <= r2 || d3 <= r2) { CollisionResult r = new CollisionResult(); r.setDistance(FastMath.sqrt(Math.min(Math.min(d1, d2), d3)) - radius); results.addCollision(r); return 1; } return 0; } else { throw new UnsupportedCollisionException(); } }