/// <summary> /// Calculates the inverse of the specified matrix. /// </summary> /// <param name="value">The matrix whose inverse is to be calculated.</param> /// <returns>the inverse of the specified matrix.</returns> public static MyMatrix3x2 Invert(MyMatrix3x2 value) { MyMatrix3x2 result; Invert(ref value, out result); return(result); }
/// <summary> /// Negates a matrix. /// </summary> /// <param name="value">The matrix to be negated.</param> /// <returns>The negated matrix.</returns> public static MyMatrix3x2 Negate(MyMatrix3x2 value) { MyMatrix3x2 result; Negate(ref value, out result); return(result); }
/// <summary> /// Determines the product of two matrices. /// </summary> /// <param name="left">The first matrix to multiply.</param> /// <param name="right">The second matrix to multiply.</param> /// <returns>The product of the two matrices.</returns> public static MyMatrix3x2 Multiply(MyMatrix3x2 left, MyMatrix3x2 right) { MyMatrix3x2 result; Multiply(ref left, ref right, out result); return(result); }
/// <summary> /// Determines the difference between two matrices. /// </summary> /// <param name="left">The first matrix to subtract.</param> /// <param name="right">The second matrix to subtract.</param> /// <returns>The difference between the two matrices.</returns> public static MyMatrix3x2 Subtract(MyMatrix3x2 left, MyMatrix3x2 right) { MyMatrix3x2 result; Subtract(ref left, ref right, out result); return(result); }
/// <summary> /// Determines the sum of two matrices. /// </summary> /// <param name="left">The first matrix to add.</param> /// <param name="right">The second matrix to add.</param> /// <returns>The sum of the two matrices.</returns> public static MyMatrix3x2 Add(MyMatrix3x2 left, MyMatrix3x2 right) { MyMatrix3x2 result; Add(ref left, ref right, out result); return(result); }
/// <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> /// <returns>The cubic interpolation of the two matrices.</returns> public static MyMatrix3x2 SmoothStep(MyMatrix3x2 start, MyMatrix3x2 end, float amount) { MyMatrix3x2 result; SmoothStep(ref start, ref end, amount, out result); return(result); }
/// <summary> /// Transforms a vector by this matrix. /// </summary> /// <param name="matrix">The matrix to use as a transformation matrix.</param> /// <param name="point">The original vector to apply the transformation.</param> /// <param name="result">The result of the transformation for the input vector.</param> /// <returns></returns> public static void TransformPoint(ref MyMatrix3x2 matrix, ref MyVector2 point, out MyVector2 result) { MyVector2 localResult; localResult.X = (point.X * matrix.M11) + (point.Y * matrix.M21) + matrix.M31; localResult.Y = (point.X * matrix.M12) + (point.Y * matrix.M22) + matrix.M32; result = localResult; }
/// <summary> /// Transforms a vector by this matrix. /// </summary> /// <param name="matrix">The matrix to use as a transformation matrix.</param> /// <param name="point">The original vector to apply the transformation.</param> /// <returns>The result of the transformation for the input vector.</returns> public static MyVector2 TransformPoint(MyMatrix3x2 matrix, MyVector2 point) { MyVector2 result; result.X = (point.X * matrix.M11) + (point.Y * matrix.M21) + matrix.M31; result.Y = (point.X * matrix.M12) + (point.Y * matrix.M22) + matrix.M32; return(result); }
/// <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); }
/// <summary> /// Negates a matrix. /// </summary> /// <param name="value">The matrix to be negated.</param> /// <param name="result">When the method completes, contains the negated matrix.</param> public static void Negate(ref MyMatrix3x2 value, out MyMatrix3x2 result) { result.M11 = -value.M11; result.M12 = -value.M12; result.M21 = -value.M21; result.M22 = -value.M22; result.M31 = -value.M31; result.M32 = -value.M32; }
/// <summary> /// Determines the quotient of two matrices. /// </summary> /// <param name="left">The first matrix to divide.</param> /// <param name="right">The second matrix to divide.</param> /// <param name="result">When the method completes, contains the quotient of the two matrices.</param> public static void Divide(ref MyMatrix3x2 left, ref MyMatrix3x2 right, out MyMatrix3x2 result) { result.M11 = left.M11 / right.M11; result.M12 = left.M12 / right.M12; result.M21 = left.M21 / right.M21; result.M22 = left.M22 / right.M22; result.M31 = left.M31 / right.M31; result.M32 = left.M32 / right.M32; }
/// <summary> /// Scales a matrix by the given value. /// </summary> /// <param name="left">The matrix to scale.</param> /// <param name="right">The amount by which to scale.</param> /// <param name="result">When the method completes, contains the scaled matrix.</param> public static void Multiply(ref MyMatrix3x2 left, float right, out MyMatrix3x2 result) { result.M11 = left.M11 * right; result.M12 = left.M12 * right; result.M21 = left.M21 * right; result.M22 = left.M22 * right; result.M31 = left.M31 * right; result.M32 = left.M32 * right; }
/// <summary> /// Determines the difference between two matrices. /// </summary> /// <param name="left">The first matrix to subtract.</param> /// <param name="right">The second matrix to subtract.</param> /// <param name="result">When the method completes, contains the difference between the two matrices.</param> public static void Subtract(ref MyMatrix3x2 left, ref MyMatrix3x2 right, out MyMatrix3x2 result) { result.M11 = left.M11 - right.M11; result.M12 = left.M12 - right.M12; result.M21 = left.M21 - right.M21; result.M22 = left.M22 - right.M22; result.M31 = left.M31 - right.M31; result.M32 = left.M32 - right.M32; }
/// <summary> /// Determines the sum of two matrices. /// </summary> /// <param name="left">The first matrix to add.</param> /// <param name="right">The second matrix to add.</param> /// <param name="result">When the method completes, contains the sum of the two matrices.</param> public static void Add(ref MyMatrix3x2 left, ref MyMatrix3x2 right, out MyMatrix3x2 result) { result.M11 = left.M11 + right.M11; result.M12 = left.M12 + right.M12; result.M21 = left.M21 + right.M21; result.M22 = left.M22 + right.M22; result.M31 = left.M31 + right.M31; result.M32 = left.M32 + right.M32; }
/// <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)); }
/// <summary> /// Determines the product of two matrices. /// </summary> /// <param name="left">The first matrix to multiply.</param> /// <param name="right">The second matrix to multiply.</param> /// <param name="result">The product of the two matrices.</param> public static void Multiply(ref MyMatrix3x2 left, ref MyMatrix3x2 right, out MyMatrix3x2 result) { result = new MyMatrix3x2(); result.M11 = (left.M11 * right.M11) + (left.M12 * right.M21); result.M12 = (left.M11 * right.M12) + (left.M12 * right.M22); result.M21 = (left.M21 * right.M11) + (left.M22 * right.M21); result.M22 = (left.M21 * right.M12) + (left.M22 * right.M22); result.M31 = (left.M31 * right.M11) + (left.M32 * right.M21) + right.M31; result.M32 = (left.M31 * right.M12) + (left.M32 * right.M22) + right.M32; }
/// <summary> /// Scales a matrix by the given value. /// </summary> /// <param name="left">The matrix to scale.</param> /// <param name="right">The amount by which to scale.</param> /// <param name="result">When the method completes, contains the scaled matrix.</param> public static void Divide(ref MyMatrix3x2 left, float right, out MyMatrix3x2 result) { float inv = 1.0f / right; result.M11 = left.M11 * inv; result.M12 = left.M12 * inv; result.M21 = left.M21 * inv; result.M22 = left.M22 * inv; result.M31 = left.M31 * inv; result.M32 = left.M32 * inv; }
/// <summary> /// Creates a matrix that rotates. /// </summary> /// <param name="angle">Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.</param> /// <param name="result">When the method completes, contains the created rotation matrix.</param> public static void Rotation(float angle, out MyMatrix3x2 result) { float cos = (float)Math.Cos(angle); float sin = (float)Math.Sin(angle); result = MyMatrix3x2.Identity; result.M11 = cos; result.M12 = sin; result.M21 = -sin; result.M22 = cos; }
/// <summary> /// Creates a matrix that is scaling from a specified center. /// </summary> /// <param name="x">Scaling factor that is applied along the x-axis.</param> /// <param name="y">Scaling factor that is applied along the y-axis.</param> /// <param name="center">The center of the scaling.</param> /// <param name="result">The created scaling matrix.</param> public static void Scaling(float x, float y, ref MyVector2 center, out MyMatrix3x2 result) { MyMatrix3x2 localResult; localResult.M11 = x; localResult.M12 = 0.0f; localResult.M21 = 0.0f; localResult.M22 = y; localResult.M31 = center.X - (x * center.X); localResult.M32 = center.Y - (y * center.Y); result = localResult; }
/// <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); }
/// <summary> /// Creates a skew matrix. /// </summary> /// <param name="angleX">Angle of skew along the X-axis in radians.</param> /// <param name="angleY">Angle of skew along the Y-axis in radians.</param> /// <param name="result">When the method completes, contains the created skew matrix.</param> public static void Skew(float angleX, float angleY, out MyMatrix3x2 result) { result = MyMatrix.Identity; result.M12 = (float)Math.Tan(angleX); result.M21 = (float)Math.Tan(angleY); }
/// <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); }
/// <summary> /// Creates a translation matrix using the specified offsets. /// </summary> /// <param name="x">X-coordinate offset.</param> /// <param name="y">Y-coordinate offset.</param> /// <param name="result">When the method completes, contains the created translation matrix.</param> public static void Translation(float x, float y, out MyMatrix3x2 result) { result = MyMatrix3x2.Identity; result.M31 = x; result.M32 = y; }
/// <summary> /// Creates a translation matrix using the specified offsets. /// </summary> /// <param name="value">The offset for both coordinate planes.</param> /// <param name="result">When the method completes, contains the created translation matrix.</param> public static void Translation(ref MyVector2 value, out MyMatrix3x2 result) { Translation(value.X, value.Y, out result); }
/// <summary> /// Creates a transformation matrix. /// </summary> /// <param name="xScale">Scaling factor that is applied along the x-axis.</param> /// <param name="yScale">Scaling factor that is applied along the y-axis.</param> /// <param name="angle">Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.</param> /// <param name="xOffset">X-coordinate offset.</param> /// <param name="yOffset">Y-coordinate offset.</param> /// <param name="result">When the method completes, contains the created transformation matrix.</param> public static void Transformation(float xScale, float yScale, float angle, float xOffset, float yOffset, out MyMatrix3x2 result) { result = Scaling(xScale, yScale) * Rotation(angle) * Translation(xOffset, yOffset); }
/// <summary> /// Creates a matrix that rotates about a specified center. /// </summary> /// <param name="angle">Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.</param> /// <param name="center">The center of the rotation.</param> /// <param name="result">When the method completes, contains the created rotation matrix.</param> public static void Rotation(float angle, MyVector2 center, out MyMatrix3x2 result) { result = Translation(-center) * Rotation(angle) * Translation(center); }
/// <summary> /// Creates a matrix that uniformly scales along both axes. /// </summary> /// <param name="scale">The uniform scale that is applied along both axes.</param> /// <param name="result">When the method completes, contains the created scaling matrix.</param> public static void Scaling(float scale, out MyMatrix3x2 result) { result = MyMatrix3x2.Identity; result.M11 = result.M22 = scale; }
/// <summary> /// Creates a matrix that scales along the x-axis and y-axis. /// </summary> /// <param name="x">Scaling factor that is applied along the x-axis.</param> /// <param name="y">Scaling factor that is applied along the y-axis.</param> /// <param name="result">When the method completes, contains the created scaling matrix.</param> public static void Scaling(float x, float y, out MyMatrix3x2 result) { result = MyMatrix3x2.Identity; result.M11 = x; result.M22 = y; }
/// <summary> /// Creates a matrix that scales along the x-axis and y-axis. /// </summary> /// <param name="scale">Scaling factor for both axes.</param> /// <param name="result">When the method completes, contains the created scaling matrix.</param> public static void Scaling(ref MyVector2 scale, out MyMatrix3x2 result) { Scaling(scale.X, scale.Y, out result); }
/// <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(MyMatrix3x2 other) { return(Equals(ref other)); }