Esempio n. 1
0
        public void SemiCircle(Vector2 center, float startRadians, float endRadians, float radius, int steps, Color color)
        {
            var last = Calc.AngleToVector(startRadians, radius);

            for (int i = 1; i <= steps; i++)
            {
                var next = Calc.AngleToVector(Calc.AngleLerp(startRadians, endRadians, (i / (float)steps)), radius);
                Triangle(center + last, center + next, center, color);
                last = next;
            }
        }
Esempio n. 2
0
        public void HollowCircle(Vector2 center, float radius, float thickness, int steps, Color color)
        {
            var last = Calc.AngleToVector(0, radius);

            for (int i = 1; i <= steps; i++)
            {
                var next = Calc.AngleToVector((i / (float)steps) * Calc.TAU, radius);
                Line(center + last, center + next, thickness, color);
                last = next;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Normalizes a Vector2 and snaps it to the closest of the 8 cardinal or diagonal directions (a zero-length Vector2 returns 0)
        /// </summary>
        public static Vector2 EightWayNormal(this Vector2 vector)
        {
            if (vector == Vector2.Zero)
            {
                return(vector);
            }

            vector = Calc.AngleToVector(Calc.Snap(vector.Angle(), Calc.PI / 4));
            if (MathF.Abs(vector.X) < .1f)
            {
                vector.X = 0;
                vector.Y = MathF.Sign(vector.Y);
            }
            else if (MathF.Abs(vector.Y) < .1f)
            {
                vector.X = MathF.Sign(vector.X);
                vector.Y = 0;
            }

            return(vector);
        }