Beispiel #1
0
        /// <summary>
        /// Restricts the specified color withing the specified range.
        /// </summary>
        /// <param name="result">Output variable for the result.</param>
        /// <param name="value">A <see cref="Color3"/>.</param>
        /// <param name="min">A <see cref="Color3"/>.</param>
        /// <param name="max">A <see cref="Color3"/>.</param>
        public static void Clamp(out Color3 result, ref Color3 value, ref Color3 min, ref Color3 max)
        {
            float r = value.R;

            r = (r > max.R) ? max.R : r;
            r = (r < min.R) ? min.R : r;

            float g = value.G;

            g = (g > max.G) ? max.G : g;
            g = (g < min.G) ? min.G : g;

            float b = value.B;

            b = (b > max.B) ? max.B : b;
            b = (b < min.B) ? min.B : b;

            result.R = r;
            result.G = g;
            result.B = b;
        }
Beispiel #2
0
 /// <summary>
 /// Performs a linear interpolation between the specified colors.
 /// </summary>
 /// <param name="result">Output variable for the result.</param>
 /// <param name="value1">A <see cref="Color3"/>.</param>
 /// <param name="value2">A <see cref="Color3"/>.</param>
 /// <param name="amount">Interpolation value in range [0, 1].</param>
 public static void Lerp(out Color3 result, ref Color3 value1, ref Color3 value2, float amount)
 {
     result.R = value1.R + ((value2.R - value1.R) * amount);
     result.G = value1.G + ((value2.G - value1.G) * amount);
     result.B = value1.B + ((value2.B - value1.B) * amount);
 }
Beispiel #3
0
 /// <summary>
 /// Calculates the maximum of the specified colors.
 /// </summary>
 /// <param name="result">Output variable for the result.</param>
 /// <param name="value1">A <see cref="Color3"/>.</param>
 /// <param name="value2">A <see cref="Color3"/>.</param>
 public static void Max(out Color3 result, ref Color3 value1, ref Color3 value2)
 {
     result.R = (value1.R > value2.R) ? value1.R : value2.R;
     result.G = (value1.G > value2.G) ? value1.G : value2.G;
     result.B = (value1.B > value2.B) ? value1.B : value2.B;
 }
Beispiel #4
0
 /// <summary>
 /// Scales the specified color.
 /// </summary>
 /// <param name="result">Output variable for the result.</param>
 /// <param name="value">A <see cref="Color3"/>.</param>
 /// <param name="amount">Scaling factor.</param>
 public static void Scale(out Color3 result, ref Color3 value, float amount)
 {
     result.R = value.R * amount;
     result.G = value.G * amount;
     result.B = value.B * amount;
 }
Beispiel #5
0
        /// <summary>
        /// Performs a Catmull-Rom spline interpolation between the specified colors.
        /// </summary>
        /// <param name="result">Output variable for the result.</param>
        /// <param name="value1">A <see cref="Color3"/>.</param>
        /// <param name="value2">A <see cref="Color3"/>.</param>
        /// <param name="value3">A <see cref="Color3"/>.</param>
        /// <param name="value4">A <see cref="Color3"/>.</param>
        /// <param name="amount">Interpolation value in range [0, 1].</param>
        public static void CatmullRom(out Color3 result, ref Color3 value1, ref Color3 value2, ref Color3 value3, ref Color3 value4, float amount)
        {
            float amount2 = amount * amount;
            float amount3 = amount * amount2;

            result.R = 0.5f * (2 * value2.R + amount * (value3.R - value1.R) + amount2 * (2 * value1.R - 5 * value2.R + 4 * value3.R - value4.R) + amount3 * (value4.R - 3 * value3.R + 3 * value2.R - value1.R));
            result.G = 0.5f * (2 * value2.G + amount * (value3.G - value1.G) + amount2 * (2 * value1.G - 5 * value2.G + 4 * value3.G - value4.G) + amount3 * (value4.G - 3 * value3.G + 3 * value2.G - value1.G));
            result.B = 0.5f * (2 * value2.B + amount * (value3.B - value1.B) + amount2 * (2 * value1.B - 5 * value2.B + 4 * value3.B - value4.B) + amount3 * (value4.B - 3 * value3.B + 3 * value2.B - value1.B));
        }
Beispiel #6
0
 /// <summary>
 /// Calculates the sum of the specified colors.
 /// </summary>
 /// <param name="result">Output variable for the result.</param>
 /// <param name="value1">A <see cref="Color3"/>.</param>
 /// <param name="value2">A <see cref="Color3"/>.</param>
 public static void Add(out Color3 result, ref Color3 value1, ref Color3 value2)
 {
     result.R = value1.R + value2.R;
     result.G = value1.G + value2.G;
     result.B = value1.B + value2.B;
 }
Beispiel #7
0
 /// <summary>
 /// Calculates the difference of the specified colors.
 /// </summary>
 /// <param name="result">Output variable for the result.</param>
 /// <param name="value1">A <see cref="Color3"/>.</param>
 /// <param name="value2">A <see cref="Color3"/>.</param>
 public static void Subtract(out Color3 result, ref Color3 value1, ref Color3 value2)
 {
     result.R = value1.R - value2.R;
     result.G = value1.G - value2.G;
     result.B = value1.B - value2.B;
 }
Beispiel #8
0
        /// <summary>
        /// Performs a Hermite spline interpolation between the specified colors.
        /// </summary>
        /// <param name="result">Output variable for the result.</param>
        /// <param name="value1">A <see cref="Color3"/>.</param>
        /// <param name="tangent1">A <see cref="Color3"/>.</param>
        /// <param name="value2">A <see cref="Color3"/>.</param>
        /// <param name="tangent2">A <see cref="Color3"/>.</param>
        /// <param name="amount">Interpolation value in range [0, 1].</param>
        public static void Hermite(out Color3 result, ref Color3 value1, ref Color3 tangent1, ref Color3 value2, ref Color3 tangent2, float amount)
        {
            float amount2 = amount * amount;
            float amount3 = amount * amount2;
            float h1      = (2 * amount3) - (3 * amount2) + 1;
            float h2      = (3 * amount2) - (2 * amount3);
            float h3      = amount3 - (2 * amount2) + amount;
            float h4      = amount3 - amount2;

            result.R = value1.R * h1 + value2.R * h2 + tangent1.R * h3 + tangent2.R * h4;
            result.G = value1.G * h1 + value2.G * h2 + tangent1.G * h3 + tangent2.G * h4;
            result.B = value1.B * h1 + value2.B * h2 + tangent1.B * h3 + tangent2.B * h4;
        }
Beispiel #9
0
 /// <summary>
 /// Calculates the sum of the specified colors where the second color is scaled with the specified amount.
 /// </summary>
 /// <param name="result">Output variable for the result.</param>
 /// <param name="value1">A <see cref="Color3"/>.</param>
 /// <param name="value2">A <see cref="Color3"/>.</param>
 /// <param name="amount">Scaling factor.</param>
 public static void AddScaled(out Color3 result, ref Color3 value1, ref Color3 value2, float amount)
 {
     result.R = value1.R + value2.R * amount;
     result.G = value1.G + value2.G * amount;
     result.B = value1.B + value2.B * amount;
 }
Beispiel #10
0
 /// <summary>
 /// Performs a linear interpolation between the specified colors using barycentric coordinates.
 /// </summary>
 /// <param name="result">Output variable for the result.</param>
 /// <param name="value1">A <see cref="Color3"/>.</param>
 /// <param name="value2">A <see cref="Color3"/>.</param>
 /// <param name="value3">A <see cref="Color3"/>.</param>
 /// <param name="u">Barycentric coordinate u, expressing weight towards <paramref name="value2"/>.</param>
 /// <param name="v">Barycentric coordinate v, expressing weight towards <paramref name="value3"/>.</param>
 public static void Barycentric(out Color3 result, ref Color3 value1, ref Color3 value2, ref Color3 value3, float u, float v)
 {
     result.R = value1.R + u * (value2.R - value1.R) + v * (value3.R - value1.R);
     result.G = value1.G + u * (value2.G - value1.G) + v * (value3.G - value1.G);
     result.B = value1.B + u * (value2.B - value1.B) + v * (value3.B - value1.B);
 }