Example #1
0
        public static FPQuaternion LerpUnclamped(FPQuaternion a, FPQuaternion b, FP t)
        {
            FPQuaternion result = FPQuaternion.Multiply(a, (1 - t)) + FPQuaternion.Multiply(b, t);

            result.Normalize();

            return(result);
        }
Example #2
0
        public static FPQuaternion FromToRotation(FPVector fromVector, FPVector toVector)
        {
            FPVector     w = FPVector.Cross(fromVector, toVector);
            FPQuaternion q = new FPQuaternion(w.x, w.y, w.z, FPVector.Dot(fromVector, toVector));

            q.w += FP.Sqrt(fromVector.sqrMagnitude * toVector.sqrMagnitude);
            q.Normalize();

            return(q);
        }
        /**
         *  @brief Rotates game object based on provided axis angles and relative space.
         *
         *  If relative space is SELF then the game object will rotate based on its forward vector.
         **/
        public void Rotate(FPVector eulerAngles, Space relativeTo)
        {
            FPQuaternion result = FPQuaternion.identity;

            if (relativeTo == Space.Self)
            {
                result = this.rotation * FPQuaternion.Euler(eulerAngles);
            }
            else
            {
                result = FPQuaternion.Euler(eulerAngles) * this.rotation;
            }

            result.Normalize();
            this.rotation = result;
        }
        /**
         *  @brief Rotates game object based on provided axis, angle of rotation and relative space.
         *
         *  If relative space is SELF then the game object will rotate based on its forward vector.
         **/
        public void Rotate(FPVector axis, FP angle, Space relativeTo)
        {
            FPQuaternion result = FPQuaternion.identity;

            if (relativeTo == Space.Self)
            {
                result = this.rotation * FPQuaternion.AngleAxis(angle, axis);
            }
            else
            {
                result = FPQuaternion.AngleAxis(angle, axis) * this.rotation;
            }

            result.Normalize();
            this.rotation = result;
        }