public BoxWithPoints GetBoundingBoxPointsRotated() { BoundingBoxNonAligned box = new BoundingBoxNonAligned(GetBoundingBoxNonRotated(), Rotation); BoxWithPoints result = box.GetPoints(); return(result); }
public BoundingBoxNonAligned(BoundingBoxNonAligned cpy) { CenterX = cpy.CenterX; CenterY = cpy.CenterY; Width = cpy.Width; Height = cpy.Height; Theta = cpy.Theta; }
public bool Intersects(BoundingBoxNonAligned box) { // Work with copies of the boxes instead of modifying the originals BoundingBoxNonAligned thisCopy = new BoundingBoxNonAligned(this); BoundingBoxNonAligned target = new BoundingBoxNonAligned(box); // Use thisCopy's point as the origin Vector2 origin = new Vector2(thisCopy.CenterX, thisCopy.CenterY); thisCopy.CenterX -= origin.X; thisCopy.CenterY -= origin.Y; target.CenterX -= origin.X; target.CenterY -= origin.Y; // Rotate so that box 1 is axis aligned BoxWithPoints thisPoints = thisCopy.GetPoints(); BoxWithPoints targetPoints = target.GetPoints(); float angle = -target.Theta; thisPoints.RotateAroundOrigin(angle); targetPoints.RotateAroundOrigin(angle); // Check if any points in box 1 are contained within box 2 // At this point, assume points are from top left and go clockwise // TODO: Add some kind of checking to the box with points so we don't have to assume if (targetPoints.PointIsInside(thisPoints.P1)) { return(true); } if (targetPoints.PointIsInside(thisPoints.P2)) { return(true); } if (targetPoints.PointIsInside(thisPoints.P3)) { return(true); } if (targetPoints.PointIsInside(thisPoints.P4)) { return(true); } return(false); }
public BoundingBoxNonAligned GetBoundingBoxNonAligned() { BoundingBoxNonAligned box = new BoundingBoxNonAligned(GetBoundingBoxNonRotated(), Rotation); return(box); }