Exemple #1
0
 /// <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 Matrix3x2 result)
 {
     result = Matrix.Identity;
     result.M12 = (float) Math.Tan(angleX);
     result.M21 = (float) Math.Tan(angleY);
 }
Exemple #2
0
 /// <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 Matrix3x2 left, ref Matrix3x2 right, out Matrix3x2 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;
 }
Exemple #3
0
 /// <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 Matrix3x2 result)
 {
     result = Matrix3x2.Identity;
     result.M31 = x;
     result.M32 = y;
 }
Exemple #4
0
 /// <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 Matrix3x2 matrix, ref Vector2 point, out Vector2 result)
 {
     Vector2 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;
 }
Exemple #5
0
        /// <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 Matrix3x2 result)
        {
            float cos = (float)Math.Cos(angle);
            float sin = (float)Math.Sin(angle);

            result = Matrix3x2.Identity;
            result.M11 = cos;
            result.M12 = sin;
            result.M21 = -sin;
            result.M22 = cos;
        }
Exemple #6
0
 /// <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 Matrix3x2 result)
 {
     result = Scaling(xScale, yScale) * Rotation(angle) * Translation(xOffset, yOffset);
 }
Exemple #7
0
 /// <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 Matrix3x2 Multiply(Matrix3x2 left, Matrix3x2 right)
 {
     Matrix3x2 result;
     Multiply(ref left, ref right, out result);
     return result;
 }
Exemple #8
0
 /// <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 Matrix3x2 result)
 {
     result = Matrix3x2.Identity;
     result.M11 = result.M22 = scale;
 }
Exemple #9
0
 /// <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 Matrix3x2 left, float right, out Matrix3x2 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;
 }
Exemple #10
0
 /// <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 Matrix3x2 left, ref Matrix3x2 right, out Matrix3x2 result)
 {
     result = new Matrix3x2();
     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;
 }
Exemple #11
0
 /// <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 Matrix3x2 Subtract(Matrix3x2 left, Matrix3x2 right)
 {
     Matrix3x2 result;
     Subtract(ref left, ref right, out result);
     return result;
 }
Exemple #12
0
 /// <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 Matrix3x2 left, ref Matrix3x2 right, out Matrix3x2 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;
 }
Exemple #13
0
 /// <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 Matrix3x2 Add(Matrix3x2 left, Matrix3x2 right)
 {
     Matrix3x2 result;
     Add(ref left, ref right, out result);
     return result;
 }
Exemple #14
0
 /// <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 Vector2 scale, out Matrix3x2 result)
 {
     Scaling(scale.X, scale.Y, out result);
 }
Exemple #15
0
        /// <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 Matrix3x2 left, float right, out Matrix3x2 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;
        }
Exemple #16
0
 /// <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 Matrix3x2 result)
 {
     result = Matrix3x2.Identity;
     result.M11 = x;
     result.M22 = y;
 }
Exemple #17
0
 /// <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 Matrix3x2 left, ref Matrix3x2 right, out Matrix3x2 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;
 }
Exemple #18
0
        /// <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 Vector2 center, out Matrix3x2 result)
        {
            Matrix3x2 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;
        }
Exemple #19
0
 /// <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 Matrix3x2 value, out Matrix3x2 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;
 }
Exemple #20
0
 /// <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, Vector2 center, out Matrix3x2 result)
 {
     result = Translation(-center) * Rotation(angle) * Translation(center);
 }
Exemple #21
0
 /// <summary>
 /// Negates a matrix.
 /// </summary>
 /// <param name="value">The matrix to be negated.</param>
 /// <returns>The negated matrix.</returns>
 public static Matrix3x2 Negate(Matrix3x2 value)
 {
     Matrix3x2 result;
     Negate(ref value, out result);
     return result;
 }
Exemple #22
0
 /// <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 Vector2 value, out Matrix3x2 result)
 {
     Translation(value.X, value.Y, out result);
 }
Exemple #23
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 Matrix3x2 start, ref Matrix3x2 end, float amount, out Matrix3x2 result)
 {
     result.M11 = MathUtil.Lerp(start.M11, end.M11, amount);
     result.M12 = MathUtil.Lerp(start.M12, end.M12, amount);
     result.M21 = MathUtil.Lerp(start.M21, end.M21, amount);
     result.M22 = MathUtil.Lerp(start.M22, end.M22, amount);
     result.M31 = MathUtil.Lerp(start.M31, end.M31, amount);
     result.M32 = MathUtil.Lerp(start.M32, end.M32, amount);
 }
Exemple #24
0
 /// <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 Vector2 TransformPoint(Matrix3x2 matrix, Vector2 point)
 {
     Vector2 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;
 }
Exemple #25
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 Matrix3x2 start, ref Matrix3x2 end, float amount, out Matrix3x2 result)
 {
     amount = MathUtil.SmoothStep(amount);
     Lerp(ref start, ref end, amount, out result);
 }
Exemple #26
0
 /// <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 Matrix3x2 Invert(Matrix3x2 value)
 {
     Matrix3x2 result;
     Invert(ref value, out result);
     return result;
 }
Exemple #27
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>
 /// <returns>The cubic interpolation of the two matrices.</returns>
 public static Matrix3x2 SmoothStep(Matrix3x2 start, Matrix3x2 end, float amount)
 {
     Matrix3x2 result;
     SmoothStep(ref start, ref end, amount, out result);
     return result;
 }
Exemple #28
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 Matrix3x2 value, out Matrix3x2 result)
        {
            float determinant = value.Determinant();

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

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

            result = new Matrix3x2(
                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);
        }
Exemple #29
0
 /// <summary>
 /// Determines whether the specified <see cref="Matrix3x2"/> is equal to this instance.
 /// </summary>
 /// <param name="other">The <see cref="Matrix3x2"/> to compare with this instance.</param>
 /// <returns>
 /// <c>true</c> if the specified <see cref="Matrix3x2"/> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 public bool Equals(Matrix3x2 other)
 {
     return (MathUtil.NearEqual(other.M11, M11) &&
         MathUtil.NearEqual(other.M12, M12) &&
         MathUtil.NearEqual(other.M21, M21) &&
         MathUtil.NearEqual(other.M22, M22) &&
         MathUtil.NearEqual(other.M31, M31) &&
         MathUtil.NearEqual(other.M32, M32));
 }