示例#1
0
        /// <summary>
        /// Sets the matrix to the rotation specified by the given quaternion</summary>
        /// <param name="q">Quaternion representation of rotation</param>
        public void Set(QuatF q)
        {
            M11 = (float)(1.0 - 2.0 * q.Y * q.Y - 2.0 * q.Z * q.Z);
            M21 = (float)(2.0 * (q.X * q.Y + q.W * q.Z));
            M31 = (float)(2.0 * (q.X * q.Z - q.W * q.Y));

            M12 = (float)(2.0 * (q.X * q.Y - q.W * q.Z));
            M22 = (float)(1.0 - 2.0 * q.X * q.X - 2.0 * q.Z * q.Z);
            M32 = (float)(2.0 * (q.Y * q.Z + q.W * q.X));

            M13 = (float)(2.0 * (q.X * q.Z + q.W * q.Y));
            M23 = (float)(2.0 * (q.Y * q.Z - q.W * q.X));
            M33 = (float)(1.0 - 2.0 * q.X * q.X - 2.0 * q.Y * q.Y);
        }
示例#2
0
        /// <summary>
        /// Sets the matrix to the rotation specified by the given quaternion</summary>
        /// <param name="q">Quaternion representation of rotation</param>
        public void Set(QuatF q)
        {
            M11 = (float)(1.0 - 2.0 * q.Y * q.Y - 2.0 * q.Z * q.Z);
            M21 = (float)(2.0 * (q.X * q.Y + q.W * q.Z));
            M31 = (float)(2.0 * (q.X * q.Z - q.W * q.Y));

            M12 = (float)(2.0 * (q.X * q.Y - q.W * q.Z));
            M22 = (float)(1.0 - 2.0 * q.X * q.X - 2.0 * q.Z * q.Z);
            M32 = (float)(2.0 * (q.Y * q.Z + q.W * q.X));

            M13 = (float)(2.0 * (q.X * q.Z + q.W * q.Y));
            M23 = (float)(2.0 * (q.Y * q.Z - q.W * q.X));
            M33 = (float)(1.0 - 2.0 * q.X * q.X - 2.0 * q.Y * q.Y);

            M14 = M24 = M34 = M41 = M42 = M43 = 0;
            M44 = 1;
        }
示例#3
0
        /// <summary>
        /// Sets this angle axis from a quaternion</summary>
        /// <param name="q">Quaternion</param>
        public void Set(QuatF q)
        {
            double mag = q.X * q.X + q.Y * q.Y + q.Z * q.Z;

            if (mag > EPS)
            {
                mag = Math.Sqrt(mag);
                double ooMag = 1.0 / mag;

                Axis.X = (float)(q.X * ooMag);
                Axis.Y = (float)(q.Y * ooMag);
                Axis.Z = (float)(q.Z * ooMag);
                Angle  = (float)(2.0 * Math.Atan2(mag, q.W));
            }
            else
            {
                Axis.X = 0;
                Axis.Y = 1;
                Axis.Z = 0;
                Angle  = 0;
            }
        }
示例#4
0
 /// <summary>
 /// Constructs a matrix with the same rotation as the given quaternion</summary>
 /// <param name="q">Quaternion representing rotation</param>
 public Matrix4F(QuatF q)
 {
     Set(q);
 }