public bool IsAxisColliding(RotatedRectangleF rectangle, Vector2 axis) { thisScalars[0] = Vector2.Dot(TopLeft, axis); thisScalars[1] = Vector2.Dot(TopRight, axis); thisScalars[2] = Vector2.Dot(BottomLeft, axis); thisScalars[3] = Vector2.Dot(BottomRight, axis); otherScalars[0] = Vector2.Dot(rectangle.TopLeft, axis); otherScalars[1] = Vector2.Dot(rectangle.TopRight, axis); otherScalars[2] = Vector2.Dot(rectangle.BottomLeft, axis); otherScalars[3] = Vector2.Dot(rectangle.BottomRight, axis); float thisRectMin = thisScalars.Min(); float thisRectMax = thisScalars.Max(); float otherRectMin = otherScalars.Min(); float otherRectMax = otherScalars.Max(); if (thisRectMax >= otherRectMax && thisRectMin <= otherRectMax) { return(true); } if (otherRectMax >= thisRectMax && otherRectMin <= thisRectMax) { return(true); } return(false); }
public static void DrawRotatedRectangle(this SpriteBatch batch, RotatedRectangleF rectangle, Vector2 offset, Color color, float depth) { RotatedRectangleF offsetRect = rectangle.Offset(offset); batch.DrawLine(offsetRect.TopLeft, offsetRect.TopRight, color, 1, depth); batch.DrawLine(offsetRect.TopRight, offsetRect.BottomRight, color, 1, depth); batch.DrawLine(offsetRect.BottomRight, offsetRect.BottomLeft, color, 1, depth); batch.DrawLine(offsetRect.BottomLeft, offsetRect.TopLeft, color, 1, depth); batch.DrawHollowCircle((new Vector2(offsetRect.baseRectangle.Left, offsetRect.baseRectangle.Top) + offsetRect.origin), 8, color, 1, 16, 1); }
public bool Intersects(RotatedRectangleF rectangle) { Vector2 axisTop = TopRight - TopLeft; Vector2 axisRight = TopRight - BottomRight; Vector2 axisOTop = rectangle.TopRight - rectangle.TopLeft; Vector2 axisORight = rectangle.TopRight - rectangle.BottomRight; if (!IsAxisColliding(rectangle, axisTop) || !IsAxisColliding(rectangle, axisRight) || !rectangle.IsAxisColliding(this, axisOTop) || !rectangle.IsAxisColliding(this, axisORight)) { return(false); } else { return(true); } }