public static EdgePosition WhichEdge( Rectangle rect, float angleInRadians, Vector2 point, int edgeWidth ) { var topGrap = new Rectangle( rect.X, rect.Y, rect.Width, edgeWidth ) ; var bottomGrab = new Rectangle( rect.X, rect.Bottom - edgeWidth, rect.Width, edgeWidth ) ; var leftGrab = new Rectangle( rect.X, rect.Y, edgeWidth, rect.Height ) ; var rightGrab = new Rectangle( rect.X + rect.Width - edgeWidth, rect.Y, edgeWidth, rect.Height ) ; var center = rect.Center ; Vector2 pivot = center.ToVector2( ) ; if( topGrap.ToPolygon( ).RotateAroundPoint( pivot, angleInRadians ).ContainsPoint(point ) ) { return EdgePosition.Top ; } if( bottomGrab.ToPolygon( ).RotateAroundPoint( pivot, angleInRadians ).ContainsPoint(point ) ) { return EdgePosition.Bottom ; } if( leftGrab.ToPolygon( ).RotateAroundPoint( pivot, angleInRadians ).ContainsPoint(point ) ) { return EdgePosition.Left ; } if( rightGrab.ToPolygon( ).RotateAroundPoint( pivot, angleInRadians ).ContainsPoint(point ) ) { return EdgePosition.Right ; } return EdgePosition.None ; }
public override void drawSelectionFrame(SpriteBatch spriteBatch, Matrix matrix) { Primitives.Instance.drawBox(spriteBatch, this.rectangle, Color.Yellow, 2); Vector2[] poly = rectangle.ToPolygon(); foreach (Vector2 p in poly) { Primitives.Instance.drawCircleFilled(spriteBatch, p, 4, Color.Yellow); } }
static Vector2[] rotateRectangleAroundCenter( Rectangle rectangle, float angleInRadians ) { Vector2[ ] points = rectangle.ToPolygon( ) ; Vector2 center = rectangle.Center.ToVector2( ) ; for( int i = 0; i < points.Length; i++ ) { points[ i ] = points[ i ].RotateAroundPoint(center, angleInRadians ) ; } return points ; }