@Override public int collideWith(Collidable other, CollisionResults results) throws UnsupportedCollisionException { if (refreshFlags != 0) throw new IllegalStateException("Scene graph must be updated" + " before checking collision"); if (other instanceof BoundingVolume) if (!getWorldBound().intersects((BoundingVolume)other)) return 0; if(other instanceof Ray) return collideWithRay((Ray)other, results); else if (other instanceof BoundingVolume) return collideWithBoundingVolume((BoundingVolume)other, results); else { throw new UnsupportedCollisionException("TerrainPatch cannnot collide with "+other.getClass().getName()); } }
@Override public int collideWith(Collidable other, CollisionResults results){ int total = 0; if (other instanceof Ray) return collideWithRay((Ray)other, results); // if it didn't collide with this bbox, return if (other instanceof BoundingVolume) if (!this.getWorldBound().intersects((BoundingVolume)other)) return total; for (Spatial child : children){ total += child.collideWith(other, results); } return total; }
BoundingVolume vVol = cubeModel.getWorldBound(); if (pVol.intersects(vVol)){ gameLost(); return;
/** * Gather the terrain patches that intersect the given ray (toTest). * This only tests the bounding boxes * @param toTest * @param results */ public void findPick(Ray toTest, List<TerrainPickData> results) { if (getWorldBound() != null) { if (getWorldBound().intersects(toTest)) { // further checking needed. for (int i = 0; i < getQuantity(); i++) { if (children.get(i) instanceof TerrainPatch) { TerrainPatch tp = (TerrainPatch) children.get(i); tp.ensurePositiveVolumeBBox(); if (tp.getWorldBound().intersects(toTest)) { CollisionResults cr = new CollisionResults(); toTest.collideWith(tp.getWorldBound(), cr); if (cr != null && cr.getClosestCollision() != null) { cr.getClosestCollision().getDistance(); results.add(new TerrainPickData(tp, cr.getClosestCollision())); } } } else if (children.get(i) instanceof TerrainQuad) { ((TerrainQuad) children.get(i)).findPick(toTest, results); } } } } }
private static void checkCollisionBase(Collidable a, Collidable b, int expected) { // Test bounding volume methods if (a instanceof BoundingVolume && b instanceof BoundingVolume) { BoundingVolume bv1 = (BoundingVolume) a; BoundingVolume bv2 = (BoundingVolume) b; assert bv1.intersects(bv2) == (expected != 0); } // Test standard collideWith method CollisionResults results = new CollisionResults(); int numCollisions = a.collideWith(b, results); assert results.size() == numCollisions; assert numCollisions == expected; // force the results to be sorted here.. results.getClosestCollision(); if (results.size() > 0) { assert results.getCollision(0) == results.getClosestCollision(); } if (results.size() == 1) { assert results.getClosestCollision() == results.getFarthestCollision(); } }
@Override public int collideWith(Collidable other, CollisionResults results) throws UnsupportedCollisionException { if (refreshFlags != 0) throw new IllegalStateException("Scene graph must be updated" + " before checking collision"); if (other instanceof BoundingVolume) if (!getWorldBound().intersects((BoundingVolume)other)) return 0; if(other instanceof Ray) return collideWithRay((Ray)other, results); else if (other instanceof BoundingVolume) return collideWithBoundingVolume((BoundingVolume)other, results); else { throw new UnsupportedCollisionException("TerrainPatch cannnot collide with "+other.getClass().getName()); } }
@Override public int collideWith(Collidable other, CollisionResults results){ int total = 0; if (other instanceof Ray) return collideWithRay((Ray)other, results); // if it didn't collide with this bbox, return if (other instanceof BoundingVolume) if (!this.getWorldBound().intersects((BoundingVolume)other)) return total; for (Spatial child : children){ total += child.collideWith(other, results); } return total; }
BoundingVolume vVol = cubeModel.getWorldBound(); if (pVol.intersects(vVol)){ gameLost(); return;
/** * Gather the terrain patches that intersect the given ray (toTest). * This only tests the bounding boxes * @param toTest * @param results */ public void findPick(Ray toTest, List<TerrainPickData> results) { if (getWorldBound() != null) { if (getWorldBound().intersects(toTest)) { // further checking needed. for (int i = 0; i < getQuantity(); i++) { if (children.get(i) instanceof TerrainPatch) { TerrainPatch tp = (TerrainPatch) children.get(i); tp.ensurePositiveVolumeBBox(); if (tp.getWorldBound().intersects(toTest)) { CollisionResults cr = new CollisionResults(); toTest.collideWith(tp.getWorldBound(), cr); if (cr != null && cr.getClosestCollision() != null) { cr.getClosestCollision().getDistance(); results.add(new TerrainPickData(tp, cr.getClosestCollision())); } } } else if (children.get(i) instanceof TerrainQuad) { ((TerrainQuad) children.get(i)).findPick(toTest, results); } } } } }
if(poi.getWorldBound().intersects(p.getBounds())){