예제 #1
0
        /// <summary>
        /// Transforms a vector by a quaternion rotation.
        /// </summary>
        /// <param name="vec">The vector to transform.</param>
        /// <param name="quat">The quaternion to rotate the vector by.</param>
        /// <returns>The result of the operation.</returns>
        public static GVector3 Transform(GVector3 vec, GQuaternion quat)
        {
            GVector3 result;

            Transform(ref vec, ref quat, out result);
            return(result);
        }
예제 #2
0
        /// <summary>
        /// Transforms a vector by a quaternion rotation.
        /// </summary>
        /// <param name="vec">The vector to transform.</param>
        /// <param name="quat">The quaternion to rotate the vector by.</param>
        /// <param name="result">The result of the operation.</param>
        public static void Transform(ref GVector3 vec, ref GQuaternion quat, out GVector3 result)
        {
            // Since vec.W == 0, we can optimize quat * vec * quat^-1 as follows:
            // vec + 2.0 * cross(quat.xyz, cross(quat.xyz, vec) + quat.w * vec)
            GVector3 xyz = quat.Xyz, temp, temp2;

            GVector3.Cross(ref xyz, ref vec, out temp);
            GVector3.Multiply(ref vec, quat.W, out temp2);
            GVector3.Add(ref temp, ref temp2, out temp);
            GVector3.Cross(ref xyz, ref temp, out temp);
            GVector3.Multiply(ref temp, 2, out temp);
            GVector3.Add(ref vec, ref temp, out result);
        }