actually rotate displayed photo correctly

This commit is contained in:
Colin McMillen 2023-09-15 11:46:22 -04:00
parent 4f3e9f50ed
commit 96526a5b76

View File

@ -1140,13 +1140,20 @@ public class Game : GameWindow {
GL.Viewport(0, 0, e.Width, e.Height); 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) { private void SetVertices(float left, float top, float width, float height, float rotationDegrees) {
Matrix2 transform = Matrix2.CreateRotation(MathHelper.DegreesToRadians(rotationDegrees)); Matrix2 transform = Matrix2.CreateRotation(MathHelper.DegreesToRadians(rotationDegrees));
Vector2 topLeft = new Vector2(left, top) * transform; Vector2 center = new(left + width / 2, top + height / 2);
Vector2 topRight = new Vector2(left + width, top) * transform; Vector2 topLeft = RotateAboutCenter(new Vector2(left, top), center, transform);
Vector2 bottomRight = new Vector2(left + width, top + height) * transform; Vector2 topRight = RotateAboutCenter(new Vector2(left + width, top), center, transform);
Vector2 bottomLeft = new Vector2(left, top + height) * transform; Vector2 bottomRight = RotateAboutCenter(new Vector2(left + width, top + height), center, transform);
Vector2 bottomLeft = RotateAboutCenter(new Vector2(left, top + height), center, transform);
// top left // top left
vertices[0] = topLeft.X; vertices[0] = topLeft.X;