@Test public void test_detect() { assertFalse(collider.detect(big, small)); small.setPosition(4,0); assertTrue(collider.detect(big, small)); small.setPosition(0,-3.6f); assertTrue(collider.detect(big, small)); small.setPosition(0, 6); assertTrue(collider.detect(big, small)); small.setPosition(10,10); assertFalse(collider.detect(big, small)); }
public boolean detect(MassedBeing being1, MassedBeing being2) { float height1 = being1.getBoundingBox().getMax().y - being1.getBoundingBox().getMin().y; float height2 = being2.getBoundingBox().getMax().y - being2.getBoundingBox().getMin().y; float width1 = being1.getBoundingBox().getMax().x - being1.getBoundingBox().getMin().x; float width2 = being2.getBoundingBox().getMax().x - being2.getBoundingBox().getMin().x; MassedBeing smallerBeing; MassedBeing biggerBeing; float smallerBeingHeight, smallerBeingWidth; if(width1>width2 && height1>height2) { biggerBeing = being1; smallerBeing = being2; smallerBeingHeight = height2; smallerBeingWidth = width2; } else if(width1<width2 && height1<height2) { biggerBeing = being2; smallerBeing = being1; smallerBeingHeight = height1; smallerBeingWidth = width1; } else { return false; } PVector projection = biggerBeing.getBoundingBox().projectionVector(smallerBeing.getBoundingBox()); if(projection == null || being1==being2) { return false; } if(projection.x==0 && Math.abs(projection.y)<smallerBeingHeight) { projection.sub(makeVector(0, smallerBeingHeight * sign(projection.y))); MassedBeing.addImpulseCollision(biggerBeing, smallerBeing, projection); return true; } else if (projection.y==0 && Math.abs(projection.x)<smallerBeingWidth) { projection.sub(makeVector(smallerBeingWidth * sign(projection.x), 0)); MassedBeing.addImpulseCollision(biggerBeing, smallerBeing, projection); return true; } else return false; }
InsideMassedCollider extends Interactor<MassedBeing,MassedBeing> { public boolean detect(MassedBeing being1, MassedBeing being2) { float height1 = being1.getBoundingBox().getMax().y - being1.getBoundingBox().getMin().y; float height2 = being2.getBoundingBox().getMax().y - being2.getBoundingBox().getMin().y; float width1 = being1.getBoundingBox().getMax().x - being1.getBoundingBox().getMin().x; float width2 = being2.getBoundingBox().getMax().x - being2.getBoundingBox().getMin().x; MassedBeing smallerBeing; MassedBeing biggerBeing; float smallerBeingHeight, smallerBeingWidth; if(width1>width2 && height1>height2) { biggerBeing = being1; smallerBeing = being2; smallerBeingHeight = height2; smallerBeingWidth = width2; } else if(width1<width2 && height1<height2) { biggerBeing = being2; smallerBeing = being1; smallerBeingHeight = height1; smallerBeingWidth = width1; } else { return false; } PVector projection = biggerBeing.getBoundingBox().projectionVector(smallerBeing.getBoundingBox()); if(projection == null || being1==being2) { return false; } if(projection.x==0 && Math.abs(projection.y)<smallerBeingHeight) { projection.sub(makeVector(0, smallerBeingHeight * sign(projection.y))); MassedBeing.addImpulseCollision(biggerBeing, smallerBeing, projection); return true; } else if (projection.y==0 && Math.abs(projection.x)<smallerBeingWidth) { projection.sub(makeVector(smallerBeingWidth * sign(projection.x), 0)); MassedBeing.addImpulseCollision(biggerBeing, smallerBeing, projection); return true; } else return false; } }
InsideMassedCollider extends Interactor<MassedBeing,MassedBeing> { public boolean detect(MassedBeing being1, MassedBeing being2) { float height1 = being1.getBoundingBox().getMax().y - being1.getBoundingBox().getMin().y; float height2 = being2.getBoundingBox().getMax().y - being2.getBoundingBox().getMin().y; float width1 = being1.getBoundingBox().getMax().x - being1.getBoundingBox().getMin().x; float width2 = being2.getBoundingBox().getMax().x - being2.getBoundingBox().getMin().x; MassedBeing smallerBeing; MassedBeing biggerBeing; float smallerBeingHeight, smallerBeingWidth; if(width1>width2 && height1>height2) { biggerBeing = being1; smallerBeing = being2; smallerBeingHeight = height2; smallerBeingWidth = width2; } else if(width1<width2 && height1<height2) { biggerBeing = being2; smallerBeing = being1; smallerBeingHeight = height1; smallerBeingWidth = width1; } else { return false; } PVector projection = biggerBeing.getBoundingBox().projectionVector(smallerBeing.getBoundingBox()); if(projection == null || being1==being2) { return false; } if(projection.x==0 && Math.abs(projection.y)<smallerBeingHeight) { projection.sub(makeVector(0, smallerBeingHeight * sign(projection.y))); MassedBeing.addImpulseCollision(biggerBeing, smallerBeing, projection); return true; } else if (projection.y==0 && Math.abs(projection.x)<smallerBeingWidth) { projection.sub(makeVector(smallerBeingWidth * sign(projection.x), 0)); MassedBeing.addImpulseCollision(biggerBeing, smallerBeing, projection); return true; } else return false; } InsideMassedCollider(); }
InsideMassedCollider extends Interactor<MassedBeing,MassedBeing> { public boolean detect(MassedBeing being1, MassedBeing being2) { float height1 = being1.getBoundingBox().getMax().y - being1.getBoundingBox().getMin().y; float height2 = being2.getBoundingBox().getMax().y - being2.getBoundingBox().getMin().y; float width1 = being1.getBoundingBox().getMax().x - being1.getBoundingBox().getMin().x; float width2 = being2.getBoundingBox().getMax().x - being2.getBoundingBox().getMin().x; MassedBeing smallerBeing; MassedBeing biggerBeing; float smallerBeingHeight, smallerBeingWidth; if(width1>width2 && height1>height2) { biggerBeing = being1; smallerBeing = being2; smallerBeingHeight = height2; smallerBeingWidth = width2; } else if(width1<width2 && height1<height2) { biggerBeing = being2; smallerBeing = being1; smallerBeingHeight = height1; smallerBeingWidth = width1; } else { return false; } PVector projection = biggerBeing.getBoundingBox().projectionVector(smallerBeing.getBoundingBox()); if(projection == null || being1==being2) { return false; } if(projection.x==0 && Math.abs(projection.y)<smallerBeingHeight) { projection.sub(makeVector(0, smallerBeingHeight * sign(projection.y))); MassedBeing.addImpulseCollision(biggerBeing, smallerBeing, projection); return true; } else if (projection.y==0 && Math.abs(projection.x)<smallerBeingWidth) { projection.sub(makeVector(smallerBeingWidth * sign(projection.x), 0)); MassedBeing.addImpulseCollision(biggerBeing, smallerBeing, projection); return true; } else return false; } InsideMassedCollider(); boolean detect(MassedBeing being1, MassedBeing being2); void handle(MassedBeing being1, MassedBeing being2); }
InsideMassedCollider extends Interactor<MassedBeing,MassedBeing> { public boolean detect(MassedBeing being1, MassedBeing being2) { float height1 = being1.getBoundingBox().getMax().y - being1.getBoundingBox().getMin().y; float height2 = being2.getBoundingBox().getMax().y - being2.getBoundingBox().getMin().y; float width1 = being1.getBoundingBox().getMax().x - being1.getBoundingBox().getMin().x; float width2 = being2.getBoundingBox().getMax().x - being2.getBoundingBox().getMin().x; MassedBeing smallerBeing; MassedBeing biggerBeing; float smallerBeingHeight, smallerBeingWidth; if(width1>width2 && height1>height2) { biggerBeing = being1; smallerBeing = being2; smallerBeingHeight = height2; smallerBeingWidth = width2; } else if(width1<width2 && height1<height2) { biggerBeing = being2; smallerBeing = being1; smallerBeingHeight = height1; smallerBeingWidth = width1; } else { return false; } PVector projection = biggerBeing.getBoundingBox().projectionVector(smallerBeing.getBoundingBox()); if(projection == null || being1==being2) { return false; } if(projection.x==0 && Math.abs(projection.y)<smallerBeingHeight) { projection.sub(makeVector(0, smallerBeingHeight * sign(projection.y))); MassedBeing.addImpulseCollision(biggerBeing, smallerBeing, projection); return true; } else if (projection.y==0 && Math.abs(projection.x)<smallerBeingWidth) { projection.sub(makeVector(smallerBeingWidth * sign(projection.x), 0)); MassedBeing.addImpulseCollision(biggerBeing, smallerBeing, projection); return true; } else return false; } InsideMassedCollider(); boolean detect(MassedBeing being1, MassedBeing being2); void handle(MassedBeing being1, MassedBeing being2);  }