Beispiel #1
0
        /// <summary>
        /// rotation is the rotation we want but with x = right, y = up and z = forward.
        /// We want to rotate it from Vector3.up to our new identity up vector.
        /// We also need difference in y axis from Quaternion.identity to our new identity, because the rotation is applied using z as forward
        /// </summary>
        public static Quaternion RotationWithNewIdentity(Vector3 rotation, Vector3 upVector, Quaternion differenceYAxis)
        {
            //calculate the rotation with new quaternion.identity (so if our Up vector is not Vector3.up, it works anyway)
            Quaternion newRotation = TransformRot.TransformRotation(rotation, upVector);

            //there is a problem: Vector3.up has Z as forward, but rotation can have forward rotated, so we must add Y axis (MouseX)
            return(Quat.AddQuaternion(differenceYAxis, newRotation));
        }
Beispiel #2
0
        /// <summary>
        /// NEVER TESTED
        /// Reverse RotationWithNewIdentity, so we get the rotation but rotated with x = right, y = up and z = forward
        /// </summary>
        public static Quaternion InverseRotationWithNewIdentity(Quaternion rotation, Quaternion differenceYAxis)
        {
            //calculate the rotation in world space (so with up vector == Vector3.up)
            Quaternion newRotation = TransformRot.InverseTransformRotation(rotation);

            //there is a problem: Vector3.up has Z as forward, but rotation can have forward rotated, so we must subtract Y axis (MouseX)
            return(Quat.SubtractQuaternion(newRotation, differenceYAxis));
        }
Beispiel #3
0
        /// <summary>
        /// Rotate the quaternion.identity to a newUp. Than return new quaternion.identity
        /// and difference on y axis (MouseX) from default quaternion.identity and the new identity (for RotationWithNewIdentity)
        /// </summary>
        public static void RotateQuaternionIdentity(Quaternion currentIdentity, Vector3 newUp, out Quaternion newIdentity, out Quaternion differenceYAxisFromDefaultIdentity)
        {
            //to walk on a planet your newUp is player.position - planet.position, or normal using raycast

            //get default quaternion.identity rotated to the new up
            Quaternion defaultIdentityRotated = TransformRot.TransformRotation(Quaternion.identity, newUp);

            //return new Quaternion.identity
            newIdentity = TransformRot.TransformToTransformRotation(currentIdentity, newUp);

            //return difference of rotation on Y axis (MouseX), from Quaternion.identity to new identity
            differenceYAxisFromDefaultIdentity = Quat.SubtractQuaternion(newIdentity, defaultIdentityRotated);
        }