예제 #1
0
		/// <summary>
		/// Rotates the matrix by the given amount.
		/// </summary>
		public void Rotate(Quaternion rot)
		{
			Matrix4D res = this * rot;
			values = res.values;
		}
예제 #2
0
        /// <summary>
        /// Multiplies two quaternions together.
        /// </summary>
        public static Quaternion operator *(Quaternion q1, Quaternion q2)
        {
            // Ignore nulls
            if(q1 == null) return null;

            if(q2 == null) return null;

            // Create vectors from the values
            Vector3D v1 = new Vector3D(q1.X, q1.Y, q1.Z);
            Vector3D v2 = new Vector3D(q2.X, q2.Y, q2.Z);

            double angle = ((q1.W * q2.W) - Vector3D.Dot(v1, v2));

            Vector3D cross = Vector3D.Cross(v1, v2);

            v1 *= q2.W;
            v2 *= q1.W;

            Quaternion result = new Quaternion(angle,
                (v1.X + v2.X + cross.X),
                (v1.Y + v2.Y + cross.Y),
                (v1.Z + v2.Z + cross.Z));

            return result;
        }