Example #1
0
        /// <summary>
        /// Initializes a new instance of the SharpDX.AngleSingle structure with the
        /// given unit dependant angle and unit type.
        /// </summary>
        /// <param name="angle">A unit dependant measure of the angle.</param>
        /// <param name="type">The type of unit the angle argument is.</param>
        public MyAngleSingle(float angle, MyAngleType type)
        {
            radiansInt = 0;
            switch (type)
            {
            case MyAngleType.Revolution:
                radians = MyMathf.RevolutionsToRadians(angle);
                break;

            case MyAngleType.Degree:
                radians = MyMathf.DegreesToRadians(angle);
                break;

            case MyAngleType.Radian:
                radians = angle;
                break;

            case MyAngleType.Gradian:
                radians = MyMathf.GradiansToRadians(angle);
                break;

            default:
                radians = 0.0f;
                break;
            }
        }
Example #2
0
 /// <summary>
 /// Performs a linear interpolation between two colors.
 /// </summary>
 /// <param name="start">Start color.</param>
 /// <param name="end">End color.</param>
 /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end"/>.</param>
 /// <param name="result">When the method completes, contains the linear interpolation of the two colors.</param>
 /// <remarks>
 /// Passing <paramref name="amount"/> a value of 0 will cause <paramref name="start"/> to be returned; a value of 1 will cause <paramref name="end"/> to be returned.
 /// </remarks>
 public static void Lerp(ref MyColor4 start, ref MyColor4 end, float amount, out MyColor4 result)
 {
     result.Red   = MyMathf.Lerp(start.Red, end.Red, amount);
     result.Green = MyMathf.Lerp(start.Green, end.Green, amount);
     result.Blue  = MyMathf.Lerp(start.Blue, end.Blue, amount);
     result.Alpha = MyMathf.Lerp(start.Alpha, end.Alpha, amount);
 }
Example #3
0
 /// <summary>
 /// Performs a linear interpolation between two colors.
 /// </summary>
 /// <param name="start">Start color.</param>
 /// <param name="end">End color.</param>
 /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end"/>.</param>
 /// <param name="result">When the method completes, contains the linear interpolation of the two colors.</param>
 /// <remarks>
 /// Passing <paramref name="amount"/> a value of 0 will cause <paramref name="start"/> to be returned; a value of 1 will cause <paramref name="end"/> to be returned.
 /// </remarks>
 public static void Lerp(ref MyColor start, ref MyColor end, float amount, out MyColor result)
 {
     result.R = MyMathf.Lerp(start.R, end.R, amount);
     result.G = MyMathf.Lerp(start.G, end.G, amount);
     result.B = MyMathf.Lerp(start.B, end.B, amount);
     result.A = MyMathf.Lerp(start.A, end.A, amount);
 }
Example #4
0
 /// <summary>
 /// Determines whether the specified <see cref="MyRectangleF"/> is equal to this instance.
 /// </summary>
 /// <param name="other">The <see cref="MyRectangleF"/> to compare with this instance.</param>
 /// <returns>
 /// <c>true</c> if the specified <see cref="MyRectangleF"/> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 public bool Equals(ref MyRectangleF other)
 {
     return(MyMathf.NearEqual(other.Left, Left) &&
            MyMathf.NearEqual(other.Right, Right) &&
            MyMathf.NearEqual(other.Top, Top) &&
            MyMathf.NearEqual(other.Bottom, Bottom));
 }
Example #5
0
        /// <summary>
        /// Determines whether a <see cref="MyOrientedBoundingBox"/> contains an array of points>.
        /// </summary>
        /// <param name="points">The points array to test.</param>
        /// <returns>The type of containment.</returns>
        public MyContainmentType Contains(MyVector3[] points)
        {
            MyMatrix invTrans;
            MyMatrix.Invert(ref Transformation, out invTrans);

            var containsAll = true;
            var containsAny = false;

            for (int i = 0; i < points.Length; i++)
            {
                MyVector3 locPoint;
                MyVector3.TransformCoordinate(ref points[i], ref invTrans, out locPoint);

                locPoint.X = Math.Abs(locPoint.X);
                locPoint.Y = Math.Abs(locPoint.Y);
                locPoint.Z = Math.Abs(locPoint.Z);

                //Simple axes-aligned BB check
                if (MyMathf.NearEqual(locPoint.X, Extents.X) &&
                    MyMathf.NearEqual(locPoint.Y, Extents.Y) &&
                    MyMathf.NearEqual(locPoint.Z, Extents.Z))
                    containsAny = true;
                if (locPoint.X < Extents.X && locPoint.Y < Extents.Y && locPoint.Z < Extents.Z)
                    containsAny = true;
                else
                    containsAll = false;
            }

            if (containsAll)
                return MyContainmentType.Contains;
            else if (containsAny)
                return MyContainmentType.Intersects;
            else
                return MyContainmentType.Disjoint;
        }
Example #6
0
 /// <summary>
 /// Determines whether the specified <see cref="MyMatrix3x2"/> is equal to this instance.
 /// </summary>
 /// <param name="other">The <see cref="MyMatrix3x2"/> to compare with this instance.</param>
 /// <returns>
 /// <c>true</c> if the specified <see cref="MyMatrix3x2"/> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 public bool Equals(ref MyMatrix3x2 other)
 {
     return(MyMathf.NearEqual(other.M11, M11) &&
            MyMathf.NearEqual(other.M12, M12) &&
            MyMathf.NearEqual(other.M21, M21) &&
            MyMathf.NearEqual(other.M22, M22) &&
            MyMathf.NearEqual(other.M31, M31) &&
            MyMathf.NearEqual(other.M32, M32));
 }
Example #7
0
        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <param name="format">The format.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public string ToString(string format, IFormatProvider formatProvider)
        {
            if (format == null)
            {
                return(ToString(formatProvider));
            }

            return(string.Format(formatProvider, "{0}°", MyMathf.RadiansToDegrees(radians).ToString(format, CultureInfo.CurrentCulture)));
        }
Example #8
0
 /// <summary>
 /// Determines whether the specified <see cref="MyViewportF"/> is equal to this instance.
 /// </summary>
 /// <param name="other">The <see cref="MyViewportF"/> to compare with this instance.</param>
 /// <returns>
 /// <c>true</c> if the specified <see cref="MyViewportF"/> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 public bool Equals(ref MyViewportF other)
 {
     return(MyMathf.NearEqual(X, other.X) &&
            MyMathf.NearEqual(Y, other.Y) &&
            MyMathf.NearEqual(Width, other.Width) &&
            MyMathf.NearEqual(Height, other.Height) &&
            MyMathf.NearEqual(MinDepth, other.MinDepth) &&
            MyMathf.NearEqual(MaxDepth, other.MaxDepth));
 }
Example #9
0
 /// <summary>
 /// Performs a linear interpolation between two matrices.
 /// </summary>
 /// <param name="start">Start matrix.</param>
 /// <param name="end">End matrix.</param>
 /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end"/>.</param>
 /// <param name="result">When the method completes, contains the linear interpolation of the two matrices.</param>
 /// <remarks>
 /// Passing <paramref name="amount"/> a value of 0 will cause <paramref name="start"/> to be returned; a value of 1 will cause <paramref name="end"/> to be returned.
 /// </remarks>
 public static void Lerp(ref MyMatrix3x2 start, ref MyMatrix3x2 end, float amount, out MyMatrix3x2 result)
 {
     result.M11 = MyMathf.Lerp(start.M11, end.M11, amount);
     result.M12 = MyMathf.Lerp(start.M12, end.M12, amount);
     result.M21 = MyMathf.Lerp(start.M21, end.M21, amount);
     result.M22 = MyMathf.Lerp(start.M22, end.M22, amount);
     result.M31 = MyMathf.Lerp(start.M31, end.M31, amount);
     result.M32 = MyMathf.Lerp(start.M32, end.M32, amount);
 }
Example #10
0
        /// <summary>
        /// Projects a 3D vector from object space into screen space.
        /// </summary>
        /// <param name="source">The vector to project.</param>
        /// <param name="matrix">A combined WorldViewProjection matrix.</param>
        /// <param name="vector">The projected vector.</param>
        public void Project(ref MyVector3 source, ref MyMatrix matrix, out MyVector3 vector)
        {
            MyVector3.Transform(ref source, ref matrix, out vector);
            float a = (((source.X * matrix.M14) + (source.Y * matrix.M24)) + (source.Z * matrix.M34)) + matrix.M44;

            if (!MyMathf.IsOne(a))
            {
                vector = (vector / a);
            }

            vector.X = (((vector.X + 1f) * 0.5f) * Width) + X;
            vector.Y = (((-vector.Y + 1f) * 0.5f) * Height) + Y;
            vector.Z = (vector.Z * (MaxDepth - MinDepth)) + MinDepth;
        }
Example #11
0
        /// <summary>
        /// Converts a screen space point into a corresponding point in world space.
        /// </summary>
        /// <param name="source">The vector to project.</param>
        /// <param name="matrix">An inverted combined WorldViewProjection matrix.</param>
        /// <param name="vector">The unprojected vector.</param>
        public void Unproject(ref MyVector3 source, ref MyMatrix matrix, out MyVector3 vector)
        {
            vector.X = (((source.X - X) / (Width)) * 2f) - 1f;
            vector.Y = -((((source.Y - Y) / (Height)) * 2f) - 1f);
            vector.Z = (source.Z - MinDepth) / (MaxDepth - MinDepth);

            float a = (((vector.X * matrix.M14) + (vector.Y * matrix.M24)) + (vector.Z * matrix.M34)) + matrix.M44;

            MyVector3.Transform(ref vector, ref matrix, out vector);

            if (!MyMathf.IsOne(a))
            {
                vector = (vector / a);
            }
        }
Example #12
0
        /// <summary>
        /// Determines whether a <see cref="MyOrientedBoundingBox"/> contains a point. 
        /// </summary>
        /// <param name="point">The point to test.</param>
        /// <returns>The type of containment the two objects have.</returns>
        public MyContainmentType Contains(ref MyVector3 point)
        {
            // Transform the point into the obb coordinates
            MyMatrix invTrans;
            MyMatrix.Invert(ref Transformation, out invTrans);

            MyVector3 locPoint;
            MyVector3.TransformCoordinate(ref point, ref invTrans, out locPoint);

            locPoint.X = Math.Abs(locPoint.X);
            locPoint.Y = Math.Abs(locPoint.Y);
            locPoint.Z = Math.Abs(locPoint.Z);

            //Simple axes-aligned BB check
            if (MyMathf.NearEqual(locPoint.X, Extents.X) && MyMathf.NearEqual(locPoint.Y, Extents.Y) && MyMathf.NearEqual(locPoint.Z, Extents.Z))
                return MyContainmentType.Intersects;
            if (locPoint.X < Extents.X && locPoint.Y < Extents.Y && locPoint.Z < Extents.Z)
                return MyContainmentType.Contains;
            else
                return MyContainmentType.Disjoint;
        }
Example #13
0
        /// <summary>
        /// Calculates the inverse of the specified matrix.
        /// </summary>
        /// <param name="value">The matrix whose inverse is to be calculated.</param>
        /// <param name="result">When the method completes, contains the inverse of the specified matrix.</param>
        public static void Invert(ref MyMatrix3x2 value, out MyMatrix3x2 result)
        {
            float determinant = value.Determinant();

            if (MyMathf.IsZero(determinant))
            {
                result = Identity;
                return;
            }

            float invdet   = 1.0f / determinant;
            float _offsetX = value.M31;
            float _offsetY = value.M32;

            result = new MyMatrix3x2(
                value.M22 * invdet,
                -value.M12 * invdet,
                -value.M21 * invdet,
                value.M11 * invdet,
                (value.M21 * _offsetY - _offsetX * value.M22) * invdet,
                (_offsetX * value.M12 - value.M11 * _offsetY) * invdet);
        }
Example #14
0
 /// <summary>
 /// Performs a linear interpolation between two matrices.
 /// </summary>
 /// <param name="start">Start Matrix5x4.</param>
 /// <param name="end">End Matrix5x4.</param>
 /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end"/>.</param>
 /// <param name="result">When the method completes, contains the linear interpolation of the two matrices.</param>
 /// <remarks>
 /// Passing <paramref name="amount"/> a value of 0 will cause <paramref name="start"/> to be returned; a value of 1 will cause <paramref name="end"/> to be returned.
 /// </remarks>
 public static void Lerp(ref MyMatrix5x4 start, ref MyMatrix5x4 end, float amount, out MyMatrix5x4 result)
 {
     result.M11 = MyMathf.Lerp(start.M11, end.M11, amount);
     result.M12 = MyMathf.Lerp(start.M12, end.M12, amount);
     result.M13 = MyMathf.Lerp(start.M13, end.M13, amount);
     result.M14 = MyMathf.Lerp(start.M14, end.M14, amount);
     result.M21 = MyMathf.Lerp(start.M21, end.M21, amount);
     result.M22 = MyMathf.Lerp(start.M22, end.M22, amount);
     result.M23 = MyMathf.Lerp(start.M23, end.M23, amount);
     result.M24 = MyMathf.Lerp(start.M24, end.M24, amount);
     result.M31 = MyMathf.Lerp(start.M31, end.M31, amount);
     result.M32 = MyMathf.Lerp(start.M32, end.M32, amount);
     result.M33 = MyMathf.Lerp(start.M33, end.M33, amount);
     result.M34 = MyMathf.Lerp(start.M34, end.M34, amount);
     result.M41 = MyMathf.Lerp(start.M41, end.M41, amount);
     result.M42 = MyMathf.Lerp(start.M42, end.M42, amount);
     result.M43 = MyMathf.Lerp(start.M43, end.M43, amount);
     result.M44 = MyMathf.Lerp(start.M44, end.M44, amount);
     result.M51 = MyMathf.Lerp(start.M51, end.M51, amount);
     result.M52 = MyMathf.Lerp(start.M52, end.M52, amount);
     result.M53 = MyMathf.Lerp(start.M53, end.M53, amount);
     result.M54 = MyMathf.Lerp(start.M54, end.M54, amount);
 }
Example #15
0
 /// <summary>
 /// Determines whether the specified <see cref="MyMatrix5x4"/> is equal to this instance.
 /// </summary>
 /// <param name="other">The <see cref="MyMatrix5x4"/> to compare with this instance.</param>
 /// <returns>
 /// <c>true</c> if the specified <see cref="MyMatrix5x4"/> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 public bool Equals(ref MyMatrix5x4 other)
 {
     return(MyMathf.NearEqual(other.M11, M11) &&
            MyMathf.NearEqual(other.M12, M12) &&
            MyMathf.NearEqual(other.M13, M13) &&
            MyMathf.NearEqual(other.M14, M14) &&
            MyMathf.NearEqual(other.M21, M21) &&
            MyMathf.NearEqual(other.M22, M22) &&
            MyMathf.NearEqual(other.M23, M23) &&
            MyMathf.NearEqual(other.M24, M24) &&
            MyMathf.NearEqual(other.M31, M31) &&
            MyMathf.NearEqual(other.M32, M32) &&
            MyMathf.NearEqual(other.M33, M33) &&
            MyMathf.NearEqual(other.M34, M34) &&
            MyMathf.NearEqual(other.M41, M41) &&
            MyMathf.NearEqual(other.M42, M42) &&
            MyMathf.NearEqual(other.M43, M43) &&
            MyMathf.NearEqual(other.M44, M44) &&
            MyMathf.NearEqual(other.M51, M51) &&
            MyMathf.NearEqual(other.M52, M52) &&
            MyMathf.NearEqual(other.M53, M53) &&
            MyMathf.NearEqual(other.M54, M54));
 }
Example #16
0
 /// <summary>
 /// Gets random <c>float</c> number within range.
 /// </summary>
 /// <param name="random">Current <see cref="System.Random"/>.</param>
 /// <param name="min">Minimum.</param>
 /// <param name="max">Maximum.</param>
 /// <returns>Random <c>float</c> number.</returns>
 public static float NextFloat(this Random random, float min, float max)
 {
     return(MyMathf.Lerp(min, max, (float)random.NextDouble()));
 }
Example #17
0
 /// <summary>
 /// Gets random <c>double</c> number within range.
 /// </summary>
 /// <param name="random">Current <see cref="System.Random"/>.</param>
 /// <param name="min">Minimum.</param>
 /// <param name="max">Maximum.</param>
 /// <returns>Random <c>double</c> number.</returns>
 public static double NextDouble(this Random random, double min, double max)
 {
     return(MyMathf.Lerp(min, max, random.NextDouble()));
 }
Example #18
0
        /// <summary>
        /// Determines whether the specified <see cref="MyViewport"/> is equal to this instance.
        /// </summary>
        /// <param name="other">The <see cref="MyViewport"/> to compare with this instance.</param>
        /// <returns>
        /// <c>true</c> if the specified <see cref="MyViewport"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>

        public bool Equals(ref MyViewport other)
        {
            return(X == other.X && Y == other.Y && Width == other.Width && Height == other.Height && MyMathf.NearEqual(MinDepth, other.MinDepth) && MyMathf.NearEqual(MaxDepth, other.MaxDepth));
        }
Example #19
0
 /// <summary>
 /// Returns a <see cref="System.String"/> that represents this instance.
 /// </summary>
 /// <returns>
 /// A <see cref="System.String"/> that represents this instance.
 /// </returns>
 public override string ToString()
 {
     return(string.Format(CultureInfo.CurrentCulture, MyMathf.RadiansToDegrees(radians).ToString("0.##°")));
 }
Example #20
0
 /// <summary>
 /// Returns a <see cref="System.String"/> that represents this instance.
 /// </summary>
 /// <param name="formatProvider">The format provider.</param>
 /// <returns>
 /// A <see cref="System.String"/> that represents this instance.
 /// </returns>
 public string ToString(IFormatProvider formatProvider)
 {
     return(string.Format(formatProvider, MyMathf.RadiansToDegrees(radians).ToString("0.##°")));
 }
Example #21
0
 /// <summary>
 /// Performs a cubic interpolation between two colors.
 /// </summary>
 /// <param name="start">Start color.</param>
 /// <param name="end">End color.</param>
 /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end"/>.</param>
 /// <param name="result">When the method completes, contains the cubic interpolation of the two colors.</param>
 public static void SmoothStep(ref MyColor4 start, ref MyColor4 end, float amount, out MyColor4 result)
 {
     amount = MyMathf.SmoothStep(amount);
     Lerp(ref start, ref end, amount, out result);
 }
Example #22
0
 /// <summary>
 /// Performs a cubic interpolation between two matrices.
 /// </summary>
 /// <param name="start">Start matrix.</param>
 /// <param name="end">End matrix.</param>
 /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end"/>.</param>
 /// <param name="result">When the method completes, contains the cubic interpolation of the two matrices.</param>
 public static void SmoothStep(ref MyMatrix3x2 start, ref MyMatrix3x2 end, float amount, out MyMatrix3x2 result)
 {
     amount = MyMathf.SmoothStep(amount);
     Lerp(ref start, ref end, amount, out result);
 }