Exemplo n.º 1
0
        /// <summary>
        ///     Gets the bounds.
        /// </summary>
        /// <returns>The bounds.</returns>
        /// <param name="positions">Positions.</param>
        public static Bounds GetBounds(Vector3[] positions)
        {
            Vector3 min = (positions.Length > 0) ? positions[0] : Vector3.zero;
            Vector3 max = min;

            float xMin = min.x;
            float xMax = max.x;
            float yMin = min.y;
            float yMax = max.y;
            float zMin = min.z;
            float zMax = max.z;

            for (int index = 1; index < positions.Length; index++)
            {
                Vector3 thisCenter = positions[index];

                xMin = HydraMathUtils.Min(xMin, thisCenter.x);
                xMax = HydraMathUtils.Max(xMax, thisCenter.x);
                yMin = HydraMathUtils.Min(yMin, thisCenter.y);
                yMax = HydraMathUtils.Max(yMax, thisCenter.y);
                zMin = HydraMathUtils.Min(zMin, thisCenter.z);
                zMax = HydraMathUtils.Max(zMax, thisCenter.z);
            }

            return(MinMax(new Vector3(xMin, yMin, zMin), new Vector3(xMax, yMax, zMax)));
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Returns the bounds of the given Bounds list
        /// </summary>
        /// <returns>The combined bounds.</returns>
        /// <param name="bounds">Bounds.</param>
        public static Bounds CombineBounds(Bounds[] bounds)
        {
            if (bounds.Length == 0)
            {
                return(new Bounds());
            }

            Bounds first = bounds[0];

            Vector3 firstCenter  = first.center;
            Vector3 firstExtents = first.extents;

            Vector3 min = firstCenter - firstExtents;
            Vector3 max = firstCenter + firstExtents;

            float xMin = min.x;
            float xMax = max.x;
            float yMin = min.y;
            float yMax = max.y;
            float zMin = min.z;
            float zMax = max.z;

            for (int index = 1; index < bounds.Length; index++)
            {
                Bounds thisBounds = bounds[index];

                Vector3 thisCenter  = thisBounds.center;
                Vector3 thisExtents = thisBounds.extents;

                Vector3 thisMin = thisCenter - thisExtents;
                Vector3 thisMax = thisCenter + thisExtents;

                xMin = HydraMathUtils.Min(xMin, thisMin.x);
                xMax = HydraMathUtils.Max(xMax, thisMax.x);
                yMin = HydraMathUtils.Min(yMin, thisMin.y);
                yMax = HydraMathUtils.Max(yMax, thisMax.y);
                zMin = HydraMathUtils.Min(zMin, thisMin.z);
                zMax = HydraMathUtils.Max(zMax, thisMax.z);
            }

            return(MinMax(new Vector3(xMin, yMin, zMin), new Vector3(xMax, yMax, zMax)));
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Converts RGB color values to HSL.
        /// </summary>
        /// <returns>The HSL value.</returns>
        /// <param name="red">Red.</param>
        /// <param name="green">Green.</param>
        /// <param name="blue">Blue.</param>
        /// <param name="alpha">Alpha.</param>
        public static Vector4 RgbToHsl(float red, float green, float blue, float alpha)
        {
            float max = HydraMathUtils.Max(red, green, blue);
            float min = HydraMathUtils.Min(red, green, blue);

            float hue = (max + min) / 2.0f;
            float saturation;
            float lightness = hue;

            if (HydraMathUtils.Approximately(max, min))
            {
                // achromatic
                hue        = 0.0f;
                saturation = 0.0f;
            }
            else
            {
                float delta = max - min;

                saturation = (lightness > 0.5f) ? delta / (2.0f - max - min) : delta / (max + min);

                if (red >= green && red >= blue)
                {
                    hue = (green - blue) / delta + (green < blue ? 6.0f : 0.0f);
                }
                else if (green >= red && green >= blue)
                {
                    hue = (blue - red) / delta + 2.0f;
                }
                else
                {
                    hue = (red - green) / delta + 4.0f;
                }

                hue /= 6.0f;
            }

            return(new Vector4(hue, saturation, lightness, alpha));
        }
Exemplo n.º 4
0
 /// <summary>
 ///     Returns the top layer subtracted from the base layer.
 /// </summary>
 /// <returns>The blend.</returns>
 /// <param name="baseLayer">Base layer.</param>
 /// <param name="topLayer">Top layer.</param>
 public static Color BlendSubtract(Color baseLayer, Color topLayer)
 {
     return(new Color(HydraMathUtils.Max(baseLayer.r - topLayer.r, 0.0f),
                      HydraMathUtils.Max(baseLayer.g - topLayer.g, 0.0f), HydraMathUtils.Max(baseLayer.b - topLayer.b, 0.0f),
                      HydraMathUtils.Max(baseLayer.a - topLayer.a, 0.0f)));
 }
Exemplo n.º 5
0
 /// <summary>
 ///     Returns the largest value in each channel.
 /// </summary>
 /// <returns>The largest channels.</returns>
 /// <param name="baseLayer">Base layer.</param>
 /// <param name="topLayer">Top layer.</param>
 public static Color BlendLighten(Color baseLayer, Color topLayer)
 {
     return(new Color(HydraMathUtils.Max(baseLayer.r, topLayer.r), HydraMathUtils.Max(baseLayer.g, topLayer.g),
                      HydraMathUtils.Max(baseLayer.b, topLayer.b), HydraMathUtils.Max(baseLayer.a, topLayer.a)));
 }