Пример #1
0
        internal static void DrawEllipse(float3 pos, float3 forward, float3 up, float radiusX, float radiusY, Color color, float start = 0, float total = 2 *math.PI, bool delimit = true)
        {
            Assert.IsTrue(total <= 2 * math.PI);
            var segments  = math.max(15, (int)(math.clamp(4 * Math.Circumference(radiusX), 25, 250) * (total / (2 * math.PI)))) * 2;
            var angle     = 0f;
            var rot       = quaternion.LookRotation(forward, up);
            var lastPoint = float3.zero;
            var thisPoint = float3.zero;

            for (var i = 0; i < segments + 1; i++)
            {
                thisPoint.x = math.sin(start + angle) * radiusX;
                thisPoint.z = math.cos(start + angle) * radiusY;

                if (i > 0)
                {
                    DrawLine(math.rotate(rot, lastPoint) + pos, math.rotate(rot, thisPoint) + pos, color);
                }

                lastPoint = thisPoint;
                angle    += total / segments;
            }

            if (delimit && total < 2 * math.PI)
            {
                thisPoint.x = math.sin(start) * radiusX;
                thisPoint.z = math.cos(start) * radiusY;
                DrawLine(math.rotate(rot, thisPoint) + pos, pos, color);

                thisPoint.x = math.sin(start + total) * radiusX;
                thisPoint.z = math.cos(start + total) * radiusY;
                DrawLine(math.rotate(rot, thisPoint) + pos, pos, color);
            }
        }