Exemplo n.º 1
0
 public TextureConverter(uint[] data, int width, byte? alphaTolerance,
     float? hullTolerance, bool? holeDetection, bool? multipartDetection,
     bool? pixelOffsetOptimization, Matrix4x4? transform)
 {
     Initialize(data, width, alphaTolerance, hullTolerance, holeDetection,
         multipartDetection, pixelOffsetOptimization, transform);
 }
Exemplo n.º 2
0
 public static void Transform( ref Vector2 position, ref Matrix4x4 matrix, out Vector2 result )
 {
     result = new Vector2 (
         ( position.X * matrix.M11 ) + ( position.Y * matrix.M21 ) + matrix.M41,
         ( position.X * matrix.M12 ) + ( position.Y * matrix.M22 ) + matrix.M42
     );
 }
Exemplo n.º 3
0
 public static void TransformNormal( ref Vector2 normal, ref Matrix4x4 matrix, out Vector2 result )
 {
     result = new Vector2 (
         ( normal.X * matrix.M11 ) + ( normal.Y * matrix.M21 ),
         ( normal.X * matrix.M12 ) + ( normal.Y * matrix.M22 )
     );
 }
Exemplo n.º 4
0
 public static void TransformNormal( ref Vector3 normal, ref Matrix4x4 matrix, out Vector3 result )
 {
     result = new Vector3 (
         ( normal.X * matrix.M11 ) + ( normal.Y * matrix.M21 ) + ( normal.Z * matrix.M31 ),
         ( normal.X * matrix.M12 ) + ( normal.Y * matrix.M22 ) + ( normal.Z * matrix.M32 ),
         ( normal.X * matrix.M13 ) + ( normal.Y * matrix.M23 ) + ( normal.Z * matrix.M33 )
     );
 }
Exemplo n.º 5
0
 public static void Transform( ref Vector3 position, ref Matrix4x4 matrix, out Vector3 result )
 {
     result = new Vector3 (
         ( position.X * matrix.M11 ) + ( position.Y * matrix.M21 ) + ( position.Z * matrix.M31 ) + matrix.M41,
         ( position.X * matrix.M12 ) + ( position.Y * matrix.M22 ) + ( position.Z * matrix.M32 ) + matrix.M42,
         ( position.X * matrix.M13 ) + ( position.Y * matrix.M23 ) + ( position.Z * matrix.M33 ) + matrix.M43
     );
 }
Exemplo n.º 6
0
 public static void Transform( ref Vector4 position, ref Matrix4x4 matrix, out Vector4 result )
 {
     result = new Vector4 (
         ( position.X * matrix.M11 ) + ( position.Y * matrix.M21 ) + ( position.Z * matrix.M31 ) + ( position.W * matrix.M41 ),
         ( position.X * matrix.M12 ) + ( position.Y * matrix.M22 ) + ( position.Z * matrix.M32 ) + ( position.W * matrix.M42 ),
         ( position.X * matrix.M13 ) + ( position.Y * matrix.M23 ) + ( position.Z * matrix.M33 ) + ( position.W * matrix.M43 ),
         ( position.X * matrix.M14 ) + ( position.Y * matrix.M24 ) + ( position.Z * matrix.M34 ) + ( position.W * matrix.M44 )
     );
 }
Exemplo n.º 7
0
 public static void Transform( ref Vector2 position, ref Matrix4x4 matrix, out Vector4 result )
 {
     result = new Vector4 (
         ( position.X * matrix.M11 ) + ( position.Y * matrix.M21 ) + matrix.M41,
         ( position.X * matrix.M12 ) + ( position.Y * matrix.M22 ) + matrix.M42,
         ( position.X * matrix.M13 ) + ( position.Y * matrix.M23 ) + matrix.M43,
         ( position.X * matrix.M14 ) + ( position.Y * matrix.M24 ) + matrix.M44
     );
 }
Exemplo n.º 8
0
 public static void Add( ref Matrix4x4 v1, ref Matrix4x4 v2, out Matrix4x4 result )
 {
     result = new Matrix4x4 (
         v1.M11 + v2.M11, v1.M12 + v2.M12, v1.M13 + v2.M13, v1.M14 + v2.M14,
         v1.M21 + v2.M21, v1.M22 + v2.M22, v1.M23 + v2.M23, v1.M24 + v2.M24,
         v1.M31 + v2.M31, v1.M32 + v2.M32, v1.M33 + v2.M33, v1.M34 + v2.M34,
         v1.M41 + v2.M41, v1.M42 + v2.M42, v1.M43 + v2.M43, v1.M44 + v2.M44
     );
 }
Exemplo n.º 9
0
 public Quaternion( Matrix4x4 rotMatrix )
 {
     float num8 = ( rotMatrix.M11 + rotMatrix.M22 ) + rotMatrix.M33;
     if ( num8 > 0f )
     {
         float num = ( float ) Math.Sqrt ( ( double ) ( num8 + 1f ) );
         num = 0.5f / num;
         X = ( rotMatrix.M23 - rotMatrix.M32 ) * num;
         Y = ( rotMatrix.M31 - rotMatrix.M13 ) * num;
         Z = ( rotMatrix.M12 - rotMatrix.M21 ) * num;
         W = num * 0.5f;
     }
     else if ( ( rotMatrix.M11 >= rotMatrix.M22 ) && ( rotMatrix.M11 >= rotMatrix.M33 ) )
     {
         float num7 = ( float ) Math.Sqrt ( ( double ) ( ( ( 1f + rotMatrix.M11 ) - rotMatrix.M22 ) - rotMatrix.M33 ) );
         float num4 = 0.5f / num7;
         X = 0.5f * num7;
         Y = ( rotMatrix.M12 + rotMatrix.M21 ) * num4;
         Z = ( rotMatrix.M13 + rotMatrix.M31 ) * num4;
         W = ( rotMatrix.M23 - rotMatrix.M32 ) * num4;
     }
     else if ( rotMatrix.M22 > rotMatrix.M33 )
     {
         float num6 = ( float ) Math.Sqrt ( ( ( 1f + rotMatrix.M22 ) - rotMatrix.M11 ) - rotMatrix.M33 );
         float num3 = 0.5f / num6;
         X = ( rotMatrix.M21 + rotMatrix.M12 ) * num3;
         Y = 0.5f * num6;
         Z = ( rotMatrix.M32 + rotMatrix.M23 ) * num3;
         W = ( rotMatrix.M31 - rotMatrix.M13 ) * num3;
     }
     else
     {
         float num5 = ( float ) Math.Sqrt ( ( double ) ( ( ( 1f + rotMatrix.M33 ) - rotMatrix.M11 ) - rotMatrix.M22 ) );
         float num2 = 0.5f / num5;
         X = ( rotMatrix.M31 + rotMatrix.M13 ) * num2;
         Y = ( rotMatrix.M32 + rotMatrix.M23 ) * num2;
         Z = 0.5f * num5;
         W = ( rotMatrix.M12 - rotMatrix.M21 ) * num2;
     }
 }
Exemplo n.º 10
0
 public static void Multiply( ref Matrix4x4 v1, float v2, out Matrix4x4 result )
 {
     result = new Matrix4x4 (
         v1.M11 * v2, v1.M12 * v2, v1.M13 * v2, v1.M14 * v2,
         v1.M21 * v2, v1.M22 * v2, v1.M23 * v2, v1.M24 * v2,
         v1.M31 * v2, v1.M32 * v2, v1.M33 * v2, v1.M34 * v2,
         v1.M41 * v2, v1.M42 * v2, v1.M43 * v2, v1.M44 * v2
     );
 }
Exemplo n.º 11
0
 public static void Multiply( ref Matrix4x4 v1, ref Matrix4x4 v2, out Matrix4x4 result )
 {
     var m11 = ( ( ( v1.M11 * v2.M11 ) + ( v1.M12 * v2.M21 ) ) + ( v1.M13 * v2.M31 ) ) + ( v1.M14 * v2.M41 );
     var m12 = ( ( ( v1.M11 * v2.M12 ) + ( v1.M12 * v2.M22 ) ) + ( v1.M13 * v2.M32 ) ) + ( v1.M14 * v2.M42 );
     var m13 = ( ( ( v1.M11 * v2.M13 ) + ( v1.M12 * v2.M23 ) ) + ( v1.M13 * v2.M33 ) ) + ( v1.M14 * v2.M43 );
     var m14 = ( ( ( v1.M11 * v2.M14 ) + ( v1.M12 * v2.M24 ) ) + ( v1.M13 * v2.M34 ) ) + ( v1.M14 * v2.M44 );
     var m21 = ( ( ( v1.M21 * v2.M11 ) + ( v1.M22 * v2.M21 ) ) + ( v1.M23 * v2.M31 ) ) + ( v1.M24 * v2.M41 );
     var m22 = ( ( ( v1.M21 * v2.M12 ) + ( v1.M22 * v2.M22 ) ) + ( v1.M23 * v2.M32 ) ) + ( v1.M24 * v2.M42 );
     var m23 = ( ( ( v1.M21 * v2.M13 ) + ( v1.M22 * v2.M23 ) ) + ( v1.M23 * v2.M33 ) ) + ( v1.M24 * v2.M43 );
     var m24 = ( ( ( v1.M21 * v2.M14 ) + ( v1.M22 * v2.M24 ) ) + ( v1.M23 * v2.M34 ) ) + ( v1.M24 * v2.M44 );
     var m31 = ( ( ( v1.M31 * v2.M11 ) + ( v1.M32 * v2.M21 ) ) + ( v1.M33 * v2.M31 ) ) + ( v1.M34 * v2.M41 );
     var m32 = ( ( ( v1.M31 * v2.M12 ) + ( v1.M32 * v2.M22 ) ) + ( v1.M33 * v2.M32 ) ) + ( v1.M34 * v2.M42 );
     var m33 = ( ( ( v1.M31 * v2.M13 ) + ( v1.M32 * v2.M23 ) ) + ( v1.M33 * v2.M33 ) ) + ( v1.M34 * v2.M43 );
     var m34 = ( ( ( v1.M31 * v2.M14 ) + ( v1.M32 * v2.M24 ) ) + ( v1.M33 * v2.M34 ) ) + ( v1.M34 * v2.M44 );
     var m41 = ( ( ( v1.M41 * v2.M11 ) + ( v1.M42 * v2.M21 ) ) + ( v1.M43 * v2.M31 ) ) + ( v1.M44 * v2.M41 );
     var m42 = ( ( ( v1.M41 * v2.M12 ) + ( v1.M42 * v2.M22 ) ) + ( v1.M43 * v2.M32 ) ) + ( v1.M44 * v2.M42 );
     var m43 = ( ( ( v1.M41 * v2.M13 ) + ( v1.M42 * v2.M23 ) ) + ( v1.M43 * v2.M33 ) ) + ( v1.M44 * v2.M43 );
     var m44 = ( ( ( v1.M41 * v2.M14 ) + ( v1.M42 * v2.M24 ) ) + ( v1.M43 * v2.M34 ) ) + ( v1.M44 * v2.M44 );
     result = new Matrix4x4 ( m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44 );
 }
Exemplo n.º 12
0
 public static Matrix4x4 Multiply( float v1, Matrix4x4 v2 )
 {
     return v2 * v1;
 }
Exemplo n.º 13
0
 public static void Divide( ref Matrix4x4 v1, ref Matrix4x4 v2, out Matrix4x4 result )
 {
     result = new Matrix4x4 (
         v1.M11 / v2.M11, v1.M12 / v2.M12, v1.M13 / v2.M13, v1.M14 / v2.M14,
         v1.M21 / v2.M21, v1.M22 / v2.M22, v1.M23 / v2.M23, v1.M24 / v2.M24,
         v1.M31 / v2.M32, v1.M32 / v2.M32, v1.M33 / v2.M33, v1.M34 / v2.M34,
         v1.M41 / v2.M41, v1.M42 / v2.M42, v1.M43 / v2.M43, v1.M44 / v2.M44
     );
 }
Exemplo n.º 14
0
 public static void Subtract( ref Matrix4x4 v1, ref Matrix4x4 v2, out Matrix4x4 result )
 {
     result = new Matrix4x4 (
         v1.M11 - v2.M11, v1.M12 - v2.M12, v1.M13 - v2.M13, v1.M14 - v2.M14,
         v1.M21 - v2.M21, v1.M22 - v2.M22, v1.M23 - v2.M23, v1.M24 - v2.M24,
         v1.M31 - v2.M31, v1.M32 - v2.M32, v1.M33 - v2.M33, v1.M34 - v2.M34,
         v1.M41 - v2.M41, v1.M42 - v2.M42, v1.M43 - v2.M43, v1.M44 - v2.M44
     );
 }
Exemplo n.º 15
0
        private void Initialize(uint[] data, int? width, byte? alphaTolerance,
            float? hullTolerance, bool? holeDetection, bool? multipartDetection,
            bool? pixelOffsetOptimization, Matrix4x4? transform)
        {
            if (data != null && !width.HasValue)
                throw new ArgumentNullException("width", "'width' can't be null if 'data' is set.");

            if (data == null && width.HasValue)
                throw new ArgumentNullException("data", "'data' can't be null if 'width' is set.");

            if (data != null && width.HasValue)
                SetTextureData(data, width.Value);

            if (alphaTolerance.HasValue)
                AlphaTolerance = alphaTolerance.Value;
            else
                AlphaTolerance = 20;

            if (hullTolerance.HasValue)
                HullTolerance = hullTolerance.Value;
            else
                HullTolerance = 1.5f;

            if (holeDetection.HasValue)
                HoleDetection = holeDetection.Value;
            else
                HoleDetection = false;

            if (multipartDetection.HasValue)
                MultipartDetection = multipartDetection.Value;
            else
                MultipartDetection = false;

            if (pixelOffsetOptimization.HasValue)
                PixelOffsetOptimization = pixelOffsetOptimization.Value;
            else
                PixelOffsetOptimization = false;

            if (transform.HasValue)
                Transform = transform.Value;
            else
                Transform = Matrix4x4.Identity;
        }
Exemplo n.º 16
0
 public static Vector4 Transform( Vector4 position, Matrix4x4 matrix )
 {
     Vector4 result;
     Transform ( ref position, ref matrix, out result );
     return result;
 }
Exemplo n.º 17
0
 public static Vector3 TransformNormal( Vector3 normal, Matrix4x4 matrix )
 {
     Vector3 result; TransformNormal ( ref normal, ref matrix, out result ); return result;
 }
Exemplo n.º 18
0
 public static void Multiply( float v1, ref Matrix4x4 v2, out Matrix4x4 result )
 {
     Multiply ( ref v2, v1, out result );
 }
Exemplo n.º 19
0
 public static Matrix4x4 Subtract( Matrix4x4 v1, Matrix4x4 v2 )
 {
     return v1 - v2;
 }
Exemplo n.º 20
0
 public static void Transpose( ref Matrix4x4 v1, out Matrix4x4 result )
 {
     result = new Matrix4x4 (
         v1.M11, v1.M21, v1.M31, v1.M41,
         v1.M12, v1.M22, v1.M32, v1.M42,
         v1.M13, v1.M23, v1.M33, v1.M43,
         v1.M14, v1.M24, v1.M34, v1.M44
     );
 }
Exemplo n.º 21
0
 public static Matrix4x4 Transpose( Matrix4x4 v1 )
 {
     return !v1;
 }
Exemplo n.º 22
0
 public void ToMatrix4x4( out Matrix4x4 result )
 {
     result = new Matrix4x4 ( this );
 }
Exemplo n.º 23
0
 public static Matrix4x4 Add( Matrix4x4 v1, Matrix4x4 v2 )
 {
     return v1 + v2;
 }
Exemplo n.º 24
0
 public static Matrix4x4 Invert( Matrix4x4 v1 )
 {
     return ~v1;
 }
Exemplo n.º 25
0
 public static Matrix4x4 Divide( Matrix4x4 v1, float v2 )
 {
     return v1 / v2;
 }
Exemplo n.º 26
0
        public static void Invert( ref Matrix4x4 v1, out Matrix4x4 result )
        {
            float det1 = v1.M11 * v1.M22 - v1.M12 * v1.M21;
            float det2 = v1.M11 * v1.M23 - v1.M13 * v1.M21;
            float det3 = v1.M11 * v1.M24 - v1.M14 * v1.M21;
            float det4 = v1.M12 * v1.M23 - v1.M13 * v1.M22;
            float det5 = v1.M12 * v1.M24 - v1.M14 * v1.M22;
            float det6 = v1.M13 * v1.M24 - v1.M14 * v1.M23;
            float det7 = v1.M31 * v1.M42 - v1.M32 * v1.M41;
            float det8 = v1.M31 * v1.M43 - v1.M33 * v1.M41;
            float det9 = v1.M31 * v1.M44 - v1.M34 * v1.M41;
            float det10 = v1.M32 * v1.M43 - v1.M33 * v1.M42;
            float det11 = v1.M32 * v1.M44 - v1.M34 * v1.M42;
            float det12 = v1.M33 * v1.M44 - v1.M34 * v1.M43;

            float detMatrix = ( float ) ( det1 * det12 - det2 * det11 + det3 * det10 + det4 * det9 - det5 * det8 + det6 * det7 );
            float invDetMatrix = 1f / detMatrix;

            result = new Matrix4x4 ();
            result.M11 = ( v1.M22 * det12 - v1.M23 * det11 + v1.M24 * det10 ) * invDetMatrix;
            result.M12 = ( -v1.M12 * det12 + v1.M13 * det11 - v1.M14 * det10 ) * invDetMatrix;
            result.M13 = ( v1.M42 * det6 - v1.M43 * det5 + v1.M44 * det4 ) * invDetMatrix;
            result.M14 = ( -v1.M32 * det6 + v1.M33 * det5 - v1.M34 * det4 ) * invDetMatrix;
            result.M21 = ( -v1.M21 * det12 + v1.M23 * det9 - v1.M24 * det8 ) * invDetMatrix;
            result.M22 = ( v1.M11 * det12 - v1.M13 * det9 + v1.M14 * det8 ) * invDetMatrix;
            result.M23 = ( -v1.M41 * det6 + v1.M43 * det3 - v1.M44 * det2 ) * invDetMatrix;
            result.M24 = ( v1.M31 * det6 - v1.M33 * det3 + v1.M34 * det2 ) * invDetMatrix;
            result.M31 = ( v1.M21 * det11 - v1.M22 * det9 + v1.M24 * det7 ) * invDetMatrix;
            result.M32 = ( -v1.M11 * det11 + v1.M12 * det9 - v1.M14 * det7 ) * invDetMatrix;
            result.M33 = ( v1.M41 * det5 - v1.M42 * det3 + v1.M44 * det1 ) * invDetMatrix;
            result.M34 = ( -v1.M31 * det5 + v1.M32 * det3 - v1.M34 * det1 ) * invDetMatrix;
            result.M41 = ( -v1.M21 * det10 + v1.M22 * det8 - v1.M23 * det7 ) * invDetMatrix;
            result.M42 = ( v1.M11 * det10 - v1.M12 * det8 + v1.M13 * det7 ) * invDetMatrix;
            result.M43 = ( -v1.M41 * det4 + v1.M42 * det2 - v1.M43 * det1 ) * invDetMatrix;
            result.M44 = ( v1.M31 * det4 - v1.M32 * det2 + v1.M33 * det1 ) * invDetMatrix;
        }
Exemplo n.º 27
0
 public static void Divide( ref Matrix4x4 v1, float v2, out Matrix4x4 result )
 {
     result = new Matrix4x4 (
         v1.M11 / v2, v1.M12 / v2, v1.M13 / v2, v1.M14 / v2,
         v1.M21 / v2, v1.M22 / v2, v1.M23 / v2, v1.M24 / v2,
         v1.M31 / v2, v1.M32 / v2, v1.M33 / v2, v1.M34 / v2,
         v1.M41 / v2, v1.M42 / v2, v1.M43 / v2, v1.M44 / v2
     );
 }
Exemplo n.º 28
0
 public static Matrix4x4 Multiply( Matrix4x4 v1, float v2 )
 {
     return v1 * v2;
 }