rotation functioning in rectangle renderer.

This commit is contained in:
Harrison Deng 2019-02-22 02:17:50 -06:00
parent 8d5435ad6c
commit 5c0d678076
2 changed files with 10 additions and 8 deletions

View File

@ -99,20 +99,22 @@ namespace CameraTest
base.Update(gameTime); base.Update(gameTime);
} }
float angleDeg = 0;
/// <summary> /// <summary>
/// This is called when the game should draw itself. /// This is called when the game should draw itself.
/// </summary> /// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param> /// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime) protected override void Draw(GameTime gameTime)
{ {
angleDeg++;
if (angleDeg > 360) angleDeg = 0;
GraphicsDevice.Clear(Color.Black); GraphicsDevice.Clear(Color.Black);
rr.Begin(true); rr.Begin(true);
rr.Draw(25, 25, 70, 70, Color.Purple); rr.Draw(25, 25, 70, 70, Color.Purple);
rr.End(); rr.End();
rr.Begin(false); rr.Begin(false);
rr.Draw(75, 75, 70, 70, Color.Green); rr.Draw(75, 75, 70, 70, Color.Green, MathHelper.ToRadians(angleDeg));
rr.End(); rr.End();
base.Draw(gameTime); base.Draw(gameTime);
} }

View File

@ -75,22 +75,22 @@ namespace RecrownedAthenaeum.Render
/// <param name="height">Height of rectangle.</param> /// <param name="height">Height of rectangle.</param>
/// <param name="color">Color of all vertices of this rectangle.</param> /// <param name="color">Color of all vertices of this rectangle.</param>
/// <param name="rotation">Rotation of rectangle. Default is 0 radians.</param> /// <param name="rotation">Rotation of rectangle. Default is 0 radians.</param>
/// <param name="filled">If this rectangle should be filled.</param>
public void Draw(int x, int y, int width, int height, Color color, float rotation = 0) public void Draw(int x, int y, int width, int height, Color color, float rotation = 0)
{ {
primitiveBatch.primitiveCount = filled ? 3 : 4; primitiveBatch.primitiveCount = filled ? 3 : 4;
Vector2[] corners = new Vector2[4]; Vector2[] corners = new Vector2[4];
corners[0] = new Vector2(x, y); corners[1] = new Vector2 (width, 0);
corners[1] = new Vector2(x + width, y); corners[2] = new Vector2(width, height);
corners[2] = new Vector2(x + width, y + height); corners[3] = new Vector2(0, height);
corners[3] = new Vector2(x, y + height);
if (rotation != 0) if (rotation != 0)
{ {
Matrix rotMat = Matrix.CreateRotationZ(rotation); Matrix rotMat = Matrix.CreateRotationZ(rotation);
for (int i = 0; i < corners.Length; i++) 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;
} }
} }