Ejemplo n.º 1
0
 /// <summary>
 /// Fills the matrix with rows <paramref name="i"/>, <paramref name="j"/>, <paramref name="k"/>, <paramref name="l"/>.
 /// </summary>
 public Mat4(Vec4 i, Vec4 j, Vec4 k, Vec4 l)
 {
     Values = new float[16];
     for (int m = 0; m < 4; m++)
     {
         this[m, 0] = i[m];
         this[m, 1] = j[m];
         this[m, 2] = k[m];
         this[m, 3] = l[m];
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// There is no any normalization.
        /// </summary>
        public Quat ToQuat()
        {
            var  trace  = this[0, 0] + this[1, 1] + this[2, 2];
            Vec4 result = new Vec4();

            if (trace > 0)
            {
                var s    = (trace + 1).Sqrt() * 2;
                var invS = 1f / s;

                result.W = s * 0.25f;
                result.X = (this[2, 1] - this[1, 2]) * invS;
                result.Y = (this[0, 2] - this[2, 0]) * invS;
                result.Z = (this[1, 0] - this[0, 1]) * invS;
            }
            else
            {
                float m00 = this[0, 0], m11 = this[1, 1], m22 = this[2, 2];

                if (m00 > m11 && m00 > m22)
                {
                    var s    = (1 + m00 - m11 - m22).Sqrt() * 2;
                    var invS = 1f / s;

                    result.W = (this[2, 1] - this[1, 2]) * invS;
                    result.X = s * 0.25f;
                    result.Y = (this[0, 1] + this[1, 0]) * invS;
                    result.Z = (this[0, 2] + this[2, 0]) * invS;
                }
                else if (m11 > m22)
                {
                    var s    = (1 + m11 - m00 - m22).Sqrt() * 2;
                    var invS = 1f / s;

                    result.W = (this[0, 2] - this[2, 0]) * invS;
                    result.X = (this[0, 1] + this[1, 0]) * invS;
                    result.Y = s * 0.25f;
                    result.Z = (this[1, 2] + this[2, 1]) * invS;
                }
                else
                {
                    var s    = (1 + m22 - m00 - m11).Sqrt() * 2;
                    var invS = 1f / s;

                    result.W = (this[1, 0] - this[0, 1]) * invS;
                    result.X = (this[0, 2] + this[2, 0]) * invS;
                    result.Y = (this[1, 2] + this[2, 1]) * invS;
                    result.Z = s * 0.25f;
                }
            }
            return(new Quat(result));
        }
Ejemplo n.º 3
0
        public static Vec4 operator *(Vec4 a, Mat4 b)
        {
            Vec4 temp = Vec4.Zero;

            for (int j = 0; j < 4; j++)
            {
                temp[j] = a[0] * b[0, j] +
                          a[1] * b[1, j] +
                          a[2] * b[2, j] +
                          a[3] * b[3, j];
            }
            return(temp);
        }
Ejemplo n.º 4
0
 public bool Equals(Vec4 other)
 {
     return(this == other);
 }
Ejemplo n.º 5
0
 public static float Dot(Vec4 a, Vec4 b)
 {
     return(a.X * b.X + a.Y * b.Y + a.Z * b.Z + a.W * b.W);
 }
Ejemplo n.º 6
0
 public float Dot(Vec4 a)
 {
     return(Dot(this, a));
 }