示例#1
0
 /// Test for inequality with another color without epsilon.
 public static bool operator !=(Color lhs, Color rhs)
 {
     return(!MathDefs.Equals(lhs.R, rhs.R) ||
            !MathDefs.Equals(lhs.G, rhs.G) ||
            !MathDefs.Equals(lhs.B, rhs.B) ||
            !MathDefs.Equals(lhs.A, rhs.A));
 }
示例#2
0
        /// <summary>
        /// Scale a vector to approximately unit length
        /// </summary>
        /// <param name="vec">The input vector</param>
        /// <param name="result">The normalized vector</param>
        public static void NormalizeFast(ref IntVector2 vec, out IntVector2 result)
        {
            float scale = MathDefs.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);

            result.X = (int)Math.Round(vec.X * scale);
            result.Y = (int)Math.Round(vec.Y * scale);
        }
示例#3
0
        /// <summary>
        /// Scales the IntVector2 to approximately unit length.
        /// </summary>
        public void NormalizeFast()
        {
            float scale = MathDefs.InverseSqrtFast(X * X + Y * Y);

            X = (int)Math.Round(X * scale);
            Y = (int)Math.Round(Y * scale);
        }
示例#4
0
        /// Return hue value given greatest and least RGB component, value-wise.
        private float Hue(float min, float max)
        {
            float chroma = max - min;

            // If chroma equals zero, hue is undefined
            if (chroma <= MathDefs.Epsilon)
            {
                return(0.0f);
            }

            // Calculate and return hue
            if (MathDefs.Equals(G, max))
            {
                return((B + 2.0f * chroma - R) / (6.0f * chroma));
            }
            else if (MathDefs.Equals(B, max))
            {
                return((4.0f * chroma - G + R) / (6.0f * chroma));
            }
            else
            {
                float r = (G - B) / (6.0f * chroma);
                return((r < 0.0f) ? 1.0f + r : ((r >= 1.0f) ? r - 1.0f : r));
            }
        }
示例#5
0
 /// Test for equality with another color without epsilon.
 public static bool operator ==(Color lhs, Color rhs)
 {
     return(MathDefs.Equals(lhs.R, rhs.R) &&
            MathDefs.Equals(lhs.G, rhs.G) &&
            MathDefs.Equals(lhs.B, rhs.B) &&
            MathDefs.Equals(lhs.A, rhs.A));
 }
示例#6
0
 /// Test for equality with another color with epsilon.
 public bool Equals(Color obj)
 {
     return(MathDefs.Equals(R, obj.R) &&
            MathDefs.Equals(G, obj.G) &&
            MathDefs.Equals(B, obj.B) &&
            MathDefs.Equals(A, obj.A));
 }
        /// <summary>
        /// Scale a vector to approximately unit length
        /// </summary>
        /// <param name="vec">The input vector</param>
        /// <param name="result">The normalized vector</param>
        public static void NormalizeFast(ref Vector2 vec, out Vector2 result)
        {
            float scale = MathDefs.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);

            result.X = vec.X * scale;
            result.Y = vec.Y * scale;
        }
        /// <summary>
        /// Scales the Vector2 to approximately unit length.
        /// </summary>
        public void NormalizeFast()
        {
            float scale = MathDefs.InverseSqrtFast(X * X + Y * Y);

            X *= scale;
            Y *= scale;
        }
示例#9
0
        /// <summary>
        /// Scale a vector to approximately unit length
        /// </summary>
        /// <param name="vec">The input vector</param>
        /// <returns>The normalized vector</returns>
        public static IntVector2 NormalizeFast(IntVector2 vec)
        {
            float scale = MathDefs.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);

            vec.X = (int)Math.Round(vec.X * scale);
            vec.Y = (int)Math.Round(vec.Y * scale);
            return(vec);
        }
示例#10
0
        /// <summary>
        /// Scale a vector to approximately unit length
        /// </summary>
        /// <param name="vec">The input vector</param>
        /// <returns>The normalized vector</returns>
        public static Vector2 NormalizeFast(Vector2 vec)
        {
            float scale = MathDefs.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);

            vec.X *= scale;
            vec.Y *= scale;
            return(vec);
        }
示例#11
0
        /// Return color packed to a 32-bit integer, with B component in the lowest 8 bits. Components are clamped to [0, 1] range.
        public uint ToUIntArgb()
        {
            uint r = (uint)MathDefs.Clamp(((int)(R * 255.0f)), 0, 255);
            uint g = (uint)MathDefs.Clamp(((int)(G * 255.0f)), 0, 255);
            uint b = (uint)MathDefs.Clamp(((int)(B * 255.0f)), 0, 255);
            uint a = (uint)MathDefs.Clamp(((int)(A * 255.0f)), 0, 255);

            return((a << 24) | (r << 16) | (g << 8) | b);
        }
示例#12
0
        /// Return color packed to a 32-bit integer, with R component in the lowest 8 bits. Components are clamped to [0, 1] range.
        public uint ToUInt()
        {
            var r = (uint)MathDefs.Clamp(((int)(R * 255.0f)), 0, 255);
            var g = (uint)MathDefs.Clamp(((int)(G * 255.0f)), 0, 255);
            var b = (uint)MathDefs.Clamp(((int)(B * 255.0f)), 0, 255);
            var a = (uint)MathDefs.Clamp(((int)(A * 255.0f)), 0, 255);

            return((a << 24) | (b << 16) | (g << 8) | r);
        }
示例#13
0
        /// <summary>
        /// Construct a new Quaternion from given Euler angles in degrees.
        /// The rotations will get applied in following order:
        /// 1. around Z axis, 2. around X axis, 3. around Y axis
        /// </summary>
        /// <param name="rotationX">Counterclockwise rotation around X axis in radian</param>
        /// <param name="rotationY">Counterclockwise rotation around Y axis in radian</param>
        /// <param name="rotationZ">Counterclockwise rotation around Z axis in radian</param>
        public Quaternion(float rotationX, float rotationY, float rotationZ)
        {
            rotationX = MathDefs.DegreesToRadians(rotationX) * 0.5f;
            rotationY = MathDefs.DegreesToRadians(rotationY) * 0.5f;
            rotationZ = MathDefs.DegreesToRadians(rotationZ) * 0.5f;

            float c1 = (float)Math.Cos(rotationX);
            float c2 = (float)Math.Cos(rotationY);
            float c3 = (float)Math.Cos(rotationZ);
            float s1 = (float)Math.Sin(rotationX);
            float s2 = (float)Math.Sin(rotationY);
            float s3 = (float)Math.Sin(rotationZ);

            W     = c2 * c1 * c3 + s2 * s1 * s3;
            Xyz.X = c2 * s1 * c3 + s2 * c1 * s3;
            Xyz.Y = s2 * c1 * c3 - c2 * s1 * s3;
            Xyz.Z = c2 * c1 * s3 - s2 * s1 * c3;
        }