Ejemplo n.º 1
0
 /// <summary>
 /// Creates a matrix that uniformally scales along all three axis.
 /// </summary>
 /// <param name="scale">The uniform scale that is applied along all axis.</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;
 }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a matrix that scales along the x-axis, y-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;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Transforms a vector by this matrix.
 /// </summary>
 /// <param name="matrix">The matrix to use as a tranformation 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;
 }
Ejemplo n.º 6
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.WithinEpsilon(determinant, 0.0f))
            {
                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);
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
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="z">Z-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;
 }
Ejemplo n.º 9
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;
 }
Ejemplo n.º 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>
 /// <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;
 }
Ejemplo n.º 11
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;
 }
Ejemplo n.º 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>
 /// <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;
 }
Ejemplo n.º 13
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;
 }
Ejemplo n.º 14
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;
        }
Ejemplo n.º 15
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;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Creates a translation matrix using the specified offsets.
 /// </summary>
 /// <param name="value">The offset for all three 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);
 }
Ejemplo n.º 17
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;
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Transforms a vector by this matrix.
 /// </summary>
 /// <param name="matrix">The matrix to use as a tranformation 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;
 }
Ejemplo n.º 19
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;
 }
Ejemplo n.º 20
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;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Creates a matrix that scales along the x-axis, y-axis, and y-axis.
 /// </summary>
 /// <param name="scale">Scaling factor for all three 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);
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Determines whether the specified <see cref="SharpDX.Matrix3x2"/> is equal to this instance.
        /// </summary>
        /// <param name="other">The <see cref="SharpDX.Matrix3x2"/> to compare with this instance.</param>
        /// <returns>
        /// <c>true</c> if the specified <see cref="SharpDX.Matrix3x2"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public bool Equals(Matrix3x2 other)
        {
            return (Math.Abs(other.M11 - M11) < MathUtil.ZeroTolerance &&
                Math.Abs(other.M12 - M12) < MathUtil.ZeroTolerance &&

                Math.Abs(other.M21 - M21) < MathUtil.ZeroTolerance &&
                Math.Abs(other.M22 - M22) < MathUtil.ZeroTolerance &&

                Math.Abs(other.M31 - M31) < MathUtil.ZeroTolerance &&
                Math.Abs(other.M32 - M32) < MathUtil.ZeroTolerance);
        }
Ejemplo n.º 23
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;
 }