Exemple #1
0
        /// <summary>
        /// Updates the motor over time. This is called by the controller
        /// every update cycle so movement can be updated.
        /// </summary>
        /// <param name="rDeltaTime">Time since the last frame (or fixed update call)</param>
        /// <param name="rUpdateIndex">Index of the update to help manage dynamic/fixed updates. [0: Invalid update, >=1: Valid update]</param>
        /// <param name="rTiltAngle">Amount of tilting the camera needs to do to match the anchor</param>
        public override CameraTransform RigLateUpdate(float rDeltaTime, int rUpdateIndex, float rTiltAngle = 0f)
        {
            UpdateToggle();

            if (mStartMotor == null || mEndMotor == null)
            {
                return(mRigTransform);
            }

            mTransitionElapsedTime += rDeltaTime;
            float lElapsedPercent = mTransitionElapsedTime / _TransitionTime;

            CameraTransform lStartResult = mStartMotor.RigLateUpdate(rDeltaTime, rUpdateIndex, rTiltAngle);
            CameraTransform lEndResult   = mEndMotor.RigLateUpdate(rDeltaTime, rUpdateIndex, rTiltAngle);

            if (_PositionBlend == 1)
            {
                mRigTransform.Position = Vector3.Lerp(mStartPosition, lEndResult.Position, lElapsedPercent);
            }
            else if (_PositionBlend == 2)
            {
                mRigTransform.Position = lStartResult.Position;
            }
            else if (_PositionBlend == 3)
            {
                mRigTransform.Position = lEndResult.Position;
            }
            else
            {
                mRigTransform.Position = Vector3.Lerp(lStartResult.Position, lEndResult.Position, lElapsedPercent);
            }

            if (_RotationBlend == 1)
            {
                mRigTransform.Rotation = Quaternion.Slerp(mStartRotation, lEndResult.Rotation, lElapsedPercent);
            }
            else if (_RotationBlend == 2)
            {
                mRigTransform.Rotation = lStartResult.Rotation;
            }
            else if (_RotationBlend == 3)
            {
                mRigTransform.Rotation = lEndResult.Rotation;
            }
            else
            {
                mRigTransform.Rotation = Quaternion.Slerp(lStartResult.Rotation, lEndResult.Rotation, lElapsedPercent);
            }

            return(mRigTransform);
        }
 /// <summary>
 /// Returns the lerped value from one transform to another
 /// </summary>
 /// <param name="rFrom"></param>
 /// <param name="rTo"></param>
 /// <param name="rTime"></param>
 public void Lerp(CameraTransform rFrom, CameraTransform rTo, float rTime)
 {
     Position = Vector3.Lerp(rFrom.Position, rTo.Position, rTime);
     Rotation = Quaternion.Slerp(rFrom.Rotation, rTo.Rotation, rTime);
 }