rotation functioning in rectangle renderer.
This commit is contained in:
		@@ -99,20 +99,22 @@ namespace CameraTest
 | 
			
		||||
 | 
			
		||||
            base.Update(gameTime);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        float angleDeg = 0;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// This is called when the game should draw itself.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
 | 
			
		||||
        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);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -75,22 +75,22 @@ namespace RecrownedAthenaeum.Render
 | 
			
		||||
        /// <param name="height">Height of 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="filled">If this rectangle should be filled.</param>
 | 
			
		||||
        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;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user