Ejemplo n.º 1
0
        /// <summary> Draws a bipyramidal basis axis using red, green, and blue for
        /// the X, Y, and Z axes at the argument pose.
        ///
        /// You can override the axis color with a single value (`overrideAxesColor`),
        /// or you can pass a hue shift value to apply to the axis colors
        /// (`axesHueShift`). </summary>
        public static void Draw(this Pose pose, Drawer drawer,
                                float length, Color?overrideAxesColor = null,
                                float?hueShift = null)
        {
            Color xColor = Color.red, yColor = Color.green, zColor = Color.blue;

            if (overrideAxesColor != null)
            {
                xColor = yColor = zColor = overrideAxesColor.Value;
            }
            if (hueShift != null)
            {
                var useHueShift = hueShift.Value;
                xColor = xColor.ShiftHue((float)useHueShift);
                yColor = yColor.ShiftHue((float)useHueShift);
                zColor = zColor.ShiftHue((float)useHueShift);
            }

            Utils.Require(ref _basisColors, 3);
            _basisColors[0] = xColor;
            _basisColors[1] = yColor;
            _basisColors[2] = zColor;

            var bipyramid = new Geometry.Bipyramid(a: Vector3.zero, b: Vector3.zero,
                                                   polySegments: 16, lengthFraction: 0.5f, overrideMatrix: pose.matrix());

            for (var bIdx = 0; bIdx < 3; bIdx++)
            {
                var b = Vector3.zero; b[bIdx] = length;
                bipyramid.b  = b;
                drawer.color = _basisColors[bIdx];
                bipyramid.DrawLines(drawer.implDrawLine);
            }
        }
Ejemplo n.º 2
0
        public static void Draw(this Matrix4x4 m, Drawer drawer,
                                float axisLengths, float?hueShift = null,
                                Color?color   = null,
                                Color?xColor  = null, Color?yColor = null, Color?zColor = null,
                                bool drawBips = false)
        {
            var useXColor = xColor ?? color ?? Color.red;
            var useYColor = yColor ?? color ?? Color.green;
            var useZColor = zColor ?? color ?? Color.blue;

            if (hueShift != null)
            {
                useXColor = useXColor.ShiftHue(hueShift.Value);
                useYColor = useYColor.ShiftHue(hueShift.Value);
                useZColor = useZColor.ShiftHue(hueShift.Value);
            }
            if (drawBips)
            {
                var bipyramid = new Geometry.Bipyramid(a: Vector3.zero, b: Vector3.zero,
                                                       polySegments: 16, lengthFraction: 0.5f, overrideMatrix: m);
                for (var bIdx = 0; bIdx < 3; bIdx++)
                {
                    var b = Vector3.zero; b[bIdx] = axisLengths;
                    bipyramid.b = b;
                    if (bIdx == 0)
                    {
                        drawer.color = useXColor;
                    }
                    if (bIdx == 1)
                    {
                        drawer.color = useYColor;
                    }
                    if (bIdx == 2)
                    {
                        drawer.color = useZColor;
                    }
                    bipyramid.DrawLines(drawer.implDrawLine);
                }
            }
            else
            {
                for (var i = 0; i < 3; i++)
                {
                    var pos = m.GetPosition();
                    if (i == 0)
                    {
                        drawer.color = useXColor;
                    }
                    if (i == 1)
                    {
                        drawer.color = useYColor;
                    }
                    if (i == 2)
                    {
                        drawer.color = useZColor;
                    }
                    drawer.implDrawLine(pos, pos + m.GetAxis(i) * axisLengths);
                }
            }
        }
Ejemplo n.º 3
0
        public static void DrawBasis(this Transform t, Drawer drawer,
                                     float?length             = null,
                                     Color?overrideAxesColor  = null,
                                     float?axesHueShift       = null,
                                     Matrix4x4?overrideMatrix = null)
        {
            var   useLength = length.UnwrapOr(0.5f);
            var   useMatrix = overrideMatrix.UnwrapOr(t.localToWorldMatrix);
            var   a = Vector3.zero;
            Color xColor = Color.red, yColor = Color.green, zColor = Color.blue;

            if (overrideAxesColor != null)
            {
                xColor = yColor = zColor = overrideAxesColor.Value;
            }
            if (axesHueShift != null)
            {
                var hueShift = axesHueShift.Value;
                xColor = xColor.ShiftHue(hueShift);
                yColor = yColor.ShiftHue(hueShift);
                zColor = zColor.ShiftHue(hueShift);
            }
            Utils.Require(ref _basisColors, 3);
            _basisColors[0] = xColor;
            _basisColors[1] = yColor;
            _basisColors[2] = zColor;

            var octahedron = new Geometry.Bipyramid(a: a, b: Vector3.zero,
                                                    polySegments: 4, lengthFraction: 0.5f,
                                                    overrideMatrix: useMatrix);

            for (var bIdx = 0; bIdx < 3; bIdx++)
            {
                var b = Vector3.zero; b[bIdx] = useLength;
                octahedron.b = b;
                drawer.color = _basisColors[bIdx];
                octahedron.DrawLines(drawer.implDrawLine);
            }
        }