diff --git a/Program.cs b/Program.cs index 10399ca..de579d2 100644 --- a/Program.cs +++ b/Program.cs @@ -1140,13 +1140,20 @@ public class Game : GameWindow { GL.Viewport(0, 0, e.Width, e.Height); } + private Vector2 RotateAboutCenter(Vector2 vec, Vector2 center, Matrix2 transform) { + Vector2 centerRelative = vec - center; + centerRelative *= transform; + return centerRelative + center; + } + private void SetVertices(float left, float top, float width, float height, float rotationDegrees) { Matrix2 transform = Matrix2.CreateRotation(MathHelper.DegreesToRadians(rotationDegrees)); - Vector2 topLeft = new Vector2(left, top) * transform; - Vector2 topRight = new Vector2(left + width, top) * transform; - Vector2 bottomRight = new Vector2(left + width, top + height) * transform; - Vector2 bottomLeft = new Vector2(left, top + height) * transform; + Vector2 center = new(left + width / 2, top + height / 2); + Vector2 topLeft = RotateAboutCenter(new Vector2(left, top), center, transform); + Vector2 topRight = RotateAboutCenter(new Vector2(left + width, top), center, transform); + Vector2 bottomRight = RotateAboutCenter(new Vector2(left + width, top + height), center, transform); + Vector2 bottomLeft = RotateAboutCenter(new Vector2(left, top + height), center, transform); // top left vertices[0] = topLeft.X;