Пример #1
0
        public void DrawLines(System.Action <Vector3, Vector3> drawLine)
        {
            var matrix      = this.matrix;
            var radius      = this.radius;
            var localLength = (b - a).magnitude;

            if (localLength == 0f)
            {
                localLength = 0.0001f;
            }
            var localDirection = (b - a) / localLength;

            var circle = new Geometry.Circle(
                center: a + localDirection * localLength * lengthFraction,
                direction: localDirection,
                radius: radius,
                overrideMatrix: matrix
                );
            var startPos = matrix.MultiplyPoint3x4(a);
            var endPos   = matrix.MultiplyPoint3x4(b);

            foreach (var point in circle.Points(polySegments))
            {
                drawLine(startPos, point);
                drawLine(point, endPos);
            }
            foreach (var edge in circle.Segments(polySegments))
            {
                drawLine(edge.a, edge.b);
            }
        }
Пример #2
0
        public void Draw(Drawer drawer)
        {
            var forward = Vector3.forward;
            var alpha   = 0.3f;
            var color   = LeapColor.cerulean.WithAlpha(alpha);

            // Near surface.
            var nearVec    = forward * near;
            var nearRad    = Mathf.Tan(angle / 2f * Mathf.Deg2Rad) * near;
            var nearCircle = new Geometry.Circle(center: nearVec,
                                                 direction: forward, radius: nearRad, transform: transform);

            nearCircle.Draw(drawer, color);

            // Far surface.
            var farVec    = forward * far;
            var farRad    = Mathf.Tan(angle / 2f * Mathf.Deg2Rad) * far;
            var farCircle = new Geometry.Circle(center: farVec,
                                                direction: forward, radius: farRad, transform: transform);

            farCircle.Draw(drawer, color);

            var nearCirclePoints = nearCircle.Points(7);
            var farCirclePoints  = farCircle.Points(7);

            for (var i = 0; i < 7; i++)
            {
                nearCirclePoints.MoveNext();
                farCirclePoints.MoveNext();
                drawer.Line(nearCirclePoints.Current, farCirclePoints.Current);
            }

            for (var rMult = 0.8f; rMult > 0.1f; rMult -= 0.2f)
            {
                drawer.color      = color.WithAlpha(rMult * rMult * alpha);
                nearCircle.radius = nearRad * rMult;
                nearCircle.Draw(drawer);
            }

            for (var rMult = 0.8f; rMult > 0.1f; rMult -= 0.2f)
            {
                drawer.color     = color.WithAlpha(rMult * rMult * alpha);
                farCircle.radius = farRad * rMult;
                farCircle.Draw(drawer);
            }
        }