In my game the player uses a Rectangle for his bounding box, he can do this because I only need to rotate the player image and not the acctual rectangle but for a eletric beam that one of the bosses have I need to use a Shape because I need to rotate the acctual bounding box and not only the image. The problem is that because I have one Rectangle and one Shape I can’t use rectangle.intersect(shape) nor rectangle.intersect((Rectangle)shape), I also can’t use the Shapes getBounds() method because that woud defeat the purpose of using a Shape so how would I be able to check the collision between the rectangle and the shape? or is there a way that I can rotate a rectangle on instead of a shape (I use the createTransformedShape instance of an AffineTransform to rotate the shape )?
SAT.
back2basic.phatcode.net/?Issue_%231:2D_Convex_Polygon_Collision_using_SAT
Also, because your shapes are just rotated boxes, you can optimize it further by projecting 1/2 of the edges.
Fix the link?
Sorry using phone right now.
Seems a little complicated. I will print and study that because, well, it seems fun.
Thought, i wonder if theres an easier way without much precision.
Sure, you can use java.awt.geom.Area
To test if 2 arbitrary shapes intersect you just have to do this
Area area = new Area(shape1);
area.intersect(new Area(shape2));
boolean isIntersecting = !area.isEmpty();
You can even test how much they intersect with area.getBounds2D().