Ejemplo n.º 1
0
        /// <summary>
        ///   Remove a renderer from the system.
        /// </summary>
        /// <param name="renderer">
        ///   The renderer to add to the system.
        /// </param>
        /// <returns>
        ///   <c>True</c> if the renderers has successfully been unregistered,
        ///   <c>false</c> otherwise.
        /// </returns>
        /// <remarks>
        ///   <para>
        ///     If the renderer has been unregistered the system will no longer
        ///     listen to the renderer's <c>PriorityChanged</c> event.
        ///   </para>
        /// </remarks>
        public static bool UnregisterRenderer(GridRenderer renderer)
        {
            var removed = _renderers.Remove(renderer);

            if (removed)
            {
                renderer.PriorityChanged -= OnPriorityChanged;
            }

            return(removed);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Add a renderer to the system.
        /// </summary>
        /// <param name="renderer">
        ///   The renderer to add to the system.
        /// </param>
        /// <returns>
        ///   <c>True</c> if the renderers has successfully been registered,
        ///   <c>false</c> otherwise.
        /// </returns>
        /// <remarks>
        ///   <para>
        ///     If the renderer has already been registered nothing will happen
        ///     and the method will return <c>false</c>. After adding a
        ///     renderer all renderers are re-sorted by their priority, so only
        ///     add and remove renderers if you really mean it. If you just
        ///     want to disable a renderer temporarily set all its colours to
        ///     zero alpha, this will make the system skip
        ///     it.
        ///   </para>
        /// </remarks>
        public static bool RegisterRenderer(GridRenderer renderer)
        {
            var unregistered = !_renderers.Contains(renderer);

            if (unregistered)
            {
                _renderers.Add(renderer);
                renderer.PriorityChanged += OnPriorityChanged;
                _renderers.Sort(PriorityComparison);
            }

            return(unregistered);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   Get a list of renderer points ready for use with Vectrosity.
        /// </summary>
        /// <returns>
        ///   List of all points for all three axes.
        /// </returns>
        /// <param name="renderer">
        ///   The instance to extend.
        /// </param>
        /// <remarks>
        ///   <para>
        ///     The axes are sorted from <c>x</c> to <c>z</c>.
        ///   </para>
        /// </remarks>
        public static List <Vector3> GetVectrosityPoints(this GridRenderer renderer)
        {
            var lineSets = renderer.LineSets;

            // Make lines into points
            var points = new List <Vector3>();

            foreach (var lineSet in lineSets)
            {
                foreach (var line in lineSet)
                {
                    points.Add(line[0]);
                    points.Add(line[1]);
                }
            }
            return(points);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   Get a list of renderer points ready for use with Vectrosity
        ///   from one axis.
        /// </summary>
        /// <returns>
        ///   List of all points for one of the three axes.
        /// </returns>
        /// <param name="renderer">
        ///   The instance to extend.
        /// </param>
        /// <param name="index">
        ///   Index of the axis: <c>x=0</c>, <c>y=1</c>, <c>z=2</c>.
        /// </param>
        /// <remarks>
        ///   <para>
        ///     If the index is less than <c>0</c> or greater than <c>2</c> an
        ///     error will be thrown.
        ///   </para>
        /// </remarks>
        public static List <Vector3> GetVectrosityPointsSeparate(this GridRenderer renderer, int index)
        {
            // Pre-condition: index must be 0 <= i < 3
            if (index < 0 || index > 2)
            {
                var message = "The index " + index + " must be between zero (inclusive) and three (exclusive).";
                throw new System.IndexOutOfRangeException(message);
            }

            var lineSet = renderer.LineSets[index];

            // Make lines into points
            var points = new List <Vector3>();

            foreach (var line in lineSet)
            {
                points.Add(line[0]);
                points.Add(line[1]);
            }
            return(points);
        }
Ejemplo n.º 5
0
        private void RenderGrid(GridRenderer gridRenderer)
        {
            gridRenderer.Refresh();

            var material   = gridRenderer.Material;
            var width      = gridRenderer.LineWidth;
            var lines      = gridRenderer.LineSets;
            var axisColors = new [] {
                gridRenderer.ColorX,
                gridRenderer.ColorY,
                gridRenderer.ColorZ
            };

            material.SetPass(0);

            if (Mathf.Abs(width) < Mathf.Epsilon)
            {
                RenderThinLines(lines, axisColors);
            }
            else                  // quads for "lines" with width
            {
                RenderWideLines(lines, axisColors, width);
            }
        }
Ejemplo n.º 6
0
 private static int CompareRenderersByPriority(GridRenderer r1, GridRenderer r2)
 {
     return(r2.Priority - r1.Priority);
 }