From 5c0d6780765545dbb7a2273eae2da7a979519b2e Mon Sep 17 00:00:00 2001 From: Recrown Date: Fri, 22 Feb 2019 02:17:50 -0600 Subject: [PATCH] rotation functioning in rectangle renderer. --- CameraTest/CameraTest.cs | 6 ++++-- RecrownedAthenaeum/Render/RectangleRenderer.cs | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CameraTest/CameraTest.cs b/CameraTest/CameraTest.cs index 7c47999..defb9ae 100644 --- a/CameraTest/CameraTest.cs +++ b/CameraTest/CameraTest.cs @@ -99,20 +99,22 @@ namespace CameraTest base.Update(gameTime); } - + float angleDeg = 0; /// /// This is called when the game should draw itself. /// /// Provides a snapshot of timing values. protected override void Draw(GameTime gameTime) { + angleDeg++; + if (angleDeg > 360) angleDeg = 0; GraphicsDevice.Clear(Color.Black); rr.Begin(true); rr.Draw(25, 25, 70, 70, Color.Purple); rr.End(); rr.Begin(false); - rr.Draw(75, 75, 70, 70, Color.Green); + rr.Draw(75, 75, 70, 70, Color.Green, MathHelper.ToRadians(angleDeg)); rr.End(); base.Draw(gameTime); } diff --git a/RecrownedAthenaeum/Render/RectangleRenderer.cs b/RecrownedAthenaeum/Render/RectangleRenderer.cs index c85de92..716f021 100644 --- a/RecrownedAthenaeum/Render/RectangleRenderer.cs +++ b/RecrownedAthenaeum/Render/RectangleRenderer.cs @@ -75,22 +75,22 @@ namespace RecrownedAthenaeum.Render /// Height of rectangle. /// Color of all vertices of this rectangle. /// Rotation of rectangle. Default is 0 radians. - /// If this rectangle should be filled. public void Draw(int x, int y, int width, int height, Color color, float rotation = 0) { primitiveBatch.primitiveCount = filled ? 3 : 4; Vector2[] corners = new Vector2[4]; - corners[0] = new Vector2(x, y); - corners[1] = new Vector2(x + width, y); - corners[2] = new Vector2(x + width, y + height); - corners[3] = new Vector2(x, y + height); + corners[1] = new Vector2 (width, 0); + corners[2] = new Vector2(width, height); + corners[3] = new Vector2(0, height); if (rotation != 0) { Matrix rotMat = Matrix.CreateRotationZ(rotation); for (int i = 0; i < corners.Length; i++) { - Vector2.Transform(corners[i], rotMat); + corners[i] = Vector2.Transform(corners[i], rotMat); + corners[i].X += x; + corners[i].Y += y; } }