public float UpdateHeading(float deltaTime, Vector3 up, ref AxisState axis)
        {
            if (deltaTime >= 0f || CinemachineCore.Instance.IsLive(base.VirtualCamera))
            {
                bool flag = false;
                flag |= axis.Update(deltaTime);
                if (flag)
                {
                    this.mLastHeadingAxisInputTime   = Time.time;
                    this.mHeadingRecenteringVelocity = 0f;
                }
            }
            float targetHeading = this.GetTargetHeading(axis.Value, base.GetReferenceOrientation(up), deltaTime);

            if (deltaTime < 0f)
            {
                this.mHeadingRecenteringVelocity = 0f;
                if (this.m_RecenterToTargetHeading.m_enabled)
                {
                    axis.Value = targetHeading;
                }
            }
            else if (this.m_BindingMode != CinemachineTransposer.BindingMode.SimpleFollowWithWorldUp && this.m_RecenterToTargetHeading.m_enabled && Time.time > this.mLastHeadingAxisInputTime + this.m_RecenterToTargetHeading.m_RecenterWaitTime)
            {
                float num = this.m_RecenterToTargetHeading.m_RecenteringTime / 3f;
                if (num <= deltaTime)
                {
                    axis.Value = targetHeading;
                }
                else
                {
                    float f    = Mathf.DeltaAngle(axis.Value, targetHeading);
                    float num2 = Mathf.Abs(f);
                    if (num2 < 0.0001f)
                    {
                        axis.Value = targetHeading;
                        this.mHeadingRecenteringVelocity = 0f;
                    }
                    else
                    {
                        float num3 = deltaTime / num;
                        float num4 = Mathf.Sign(f) * Mathf.Min(num2, num2 * num3);
                        float num5 = num4 - this.mHeadingRecenteringVelocity;
                        if ((num4 < 0f && num5 < 0f) || (num4 > 0f && num5 > 0f))
                        {
                            num4 = this.mHeadingRecenteringVelocity + num4 * num3;
                        }
                        axis.Value += num4;
                        this.mHeadingRecenteringVelocity = num4;
                    }
                }
            }
            float value = axis.Value;

            if (this.m_BindingMode == CinemachineTransposer.BindingMode.SimpleFollowWithWorldUp)
            {
                axis.Value = 0f;
            }
            return(value);
        }
        /// <summary>
        /// Update the X axis and calculate the heading.  This can be called by a delegate
        /// with a custom axis.
        /// <param name="deltaTime">Used for damping.  If less than 0, no damping is done.</param>
        /// <param name="up">World Up, set by the CinemachineBrain</param>
        /// <param name="axis"></param>
        /// <param name="recentering"></param>
        /// <param name="isLive"/>true if the vcam is live</param>
        /// <returns>Axis value</returns>
        /// </summary>
        public float UpdateHeading(
            float deltaTime, Vector3 up, ref AxisState axis,
            ref AxisState.Recentering recentering, bool isLive)
        {
            if (m_BindingMode == BindingMode.SimpleFollowWithWorldUp)
            {
                axis.m_MinValue = -180;
                axis.m_MaxValue = 180;
            }

            // Only read joystick when game is playing
            if (deltaTime < 0 || !VirtualCamera.PreviousStateIsValid || !isLive)
            {
                axis.Reset();
                recentering.CancelRecentering();
            }
            else if (axis.Update(deltaTime))
            {
                recentering.CancelRecentering();
            }

            if (m_BindingMode == BindingMode.SimpleFollowWithWorldUp)
            {
                float finalHeading = axis.Value;
                axis.Value = 0;
                return(finalHeading);
            }

            float targetHeading = GetTargetHeading(axis.Value, GetReferenceOrientation(up));

            recentering.DoRecentering(ref axis, deltaTime, targetHeading);
            return(axis.Value);
        }
Esempio n. 3
0
        /// <summary>
        /// Update the X axis and calculate the heading.  This can be called by a delegate
        /// with a custom axis.
        /// <param name="deltaTime">Used for damping.  If less than 0, no damping is done.</param>
        /// <param name="up">World Up, set by the CinemachineBrain</param>
        /// <param name="axis"></param>
        /// <returns>Axis value</returns>
        /// </summary>
        public float UpdateHeading(float deltaTime, Vector3 up, ref AxisState axis)
        {
            // Only read joystick when game is playing
            if (deltaTime < 0 || !CinemachineCore.Instance.IsLive(VirtualCamera))
            {
                axis.Reset();
                m_RecenterToTargetHeading.CancelRecentering();
            }
            else if (axis.Update(deltaTime))
            {
                m_RecenterToTargetHeading.CancelRecentering();
            }

            float targetHeading = GetTargetHeading(axis.Value, GetReferenceOrientation(up), deltaTime);

            if (m_BindingMode != BindingMode.SimpleFollowWithWorldUp)
            {
                m_RecenterToTargetHeading.DoRecentering(ref axis, deltaTime, targetHeading);
            }

            float finalHeading = axis.Value;

            if (m_BindingMode == BindingMode.SimpleFollowWithWorldUp)
            {
                axis.Value = 0;
            }
            return(finalHeading);
        }
        /// <summary>
        /// Update the X axis and calculate the heading.  This can be called by a delegate
        /// with a custom axis.
        /// <param name="deltaTime">Used for damping.  If less than 0, no damping is done.</param>
        /// <param name="up">World Up, set by the CinemachineBrain</param>
        /// <param name="axis"></param>
        /// <param name="recentering"></param>
        /// <param name="isLive"/>true if the vcam is live</param>
        /// <returns>Axis value</returns>
        /// </summary>
        public float UpdateHeading(
            float deltaTime, Vector3 up, ref AxisState axis,
            ref AxisState.Recentering recentering, bool isLive)
        {
            // Only read joystick when game is playing
            if (deltaTime < 0 || !isLive)
            {
                axis.Reset();
                recentering.CancelRecentering();
            }
            else if (axis.Update(deltaTime))
            {
                recentering.CancelRecentering();
            }

            float targetHeading = GetTargetHeading(axis.Value, GetReferenceOrientation(up), deltaTime);

            if (deltaTime >= 0 && m_BindingMode != BindingMode.SimpleFollowWithWorldUp)
            {
                recentering.DoRecentering(ref axis, deltaTime, targetHeading);
            }

            float finalHeading = axis.Value;

            if (m_BindingMode == BindingMode.SimpleFollowWithWorldUp)
            {
                axis.Value = 0;
            }
            return(finalHeading);
        }
Esempio n. 5
0
            public void DoAxisLimit(ref AxisState axis, Vector3 up, bool isYAxis = false, float fov = 0)
            {
                if (m_LimitMode == LimitMode.None)
                {
                    return;
                }

                if (!m_Enable)
                {
                    return;
                }

                if (m_RemoveLimitMode == RemoveLimitMode.Once)
                {
                    float input = Mathf.Abs(CinemachineCore.GetInputAxis("RightJoystickVertical"));
                    input += Mathf.Abs(CinemachineCore.GetInputAxis("RightJoystickHorizontal"));
                    if (input != 0)
                    {
                        m_Enable = false;
                    }
                }



                if (m_LimitMode == LimitMode.SceneLook)
                {
                    if (m_LookTarget == null || m_Camera == null)
                    {
                        return;
                    }

                    Vector3 dir = m_LookTarget.position - m_Camera.position;
                    if (!isYAxis)
                    {
                        dir.y = 0;
                    }
                    dir = dir.normalized;
                    float   angle  = Vector3.Angle(m_AxisVector, dir);
                    Vector3 normal = Vector3.Cross(m_AxisVector, dir);
                    angle *= Mathf.Sign(Vector3.Dot(normal, up));

                    if (isYAxis)
                    {
                        angle = (angle - (90 - fov)) / (fov * 2);
                    }
                    else
                    {
                        if (!axis.ValueRangeLocked)
                        {
                            axis.m_MaxValue = angle + m_LimitRange;
                            axis.m_MinValue = angle - m_LimitRange;
                        }
                    }

                    axis.Value = angle;
                }
            }
Esempio n. 6
0
        float ClampValue(ref AxisState axis, float v)
        {
            float r = axis.m_MaxValue - axis.m_MinValue;

            if (axis.m_Wrap && r > Epsilon)
            {
                v  = (v - axis.m_MinValue) % r;
                v += axis.m_MinValue + ((v < 0) ? r : 0);
            }
            return(Mathf.Clamp(v, axis.m_MinValue, axis.m_MaxValue));
        }
        /// <summary>
        /// Support for legacy AxisState struct
        /// </summary>
        /// <param name="deltaTime"></param>
        /// <param name="axis"></param>
        /// <returns></returns>
        public bool Update(float deltaTime, ref AxisState axis)
        {
            var a = new AxisBase
            {
                m_Value    = axis.Value,
                m_MinValue = axis.m_MinValue,
                m_MaxValue = axis.m_MaxValue,
                m_Wrap     = axis.m_Wrap
            };
            bool changed = Update(deltaTime, ref a);

            axis.Value = a.m_Value;
            return(changed);
        }
Esempio n. 8
0
            /// <summary>Bring the axis back to the centered state (only if enabled).</summary>
            public void DoRecentering(ref AxisState axis, float deltaTime, float recenterTarget)
            {
                if (!m_enabled && deltaTime >= 0)
                {
                    return;
                }

                recenterTarget = axis.ClampValue(recenterTarget);
                if (deltaTime < 0)
                {
                    CancelRecentering();
                    axis.Value = recenterTarget;
                    return;
                }

                float v     = axis.ClampValue(axis.Value);
                float delta = recenterTarget - v;

                if (delta == 0)
                {
                    return;
                }

                if (Time.time < (mLastAxisInputTime + m_WaitTime))
                {
                    return;
                }

                // Determine the direction
                float r = axis.m_MaxValue - axis.m_MinValue;

                if (axis.m_Wrap && Mathf.Abs(delta) > r * 0.5f)
                {
                    v += Mathf.Sign(recenterTarget - v) * r;
                }

                // Damp our way there
                if (m_RecenteringTime < 0.001f)
                {
                    v = recenterTarget;
                }
                else
                {
                    v = Mathf.SmoothDamp(
                        v, recenterTarget, ref mRecenteringVelocity,
                        m_RecenteringTime, 9999, deltaTime);
                }
                axis.Value = axis.ClampValue(v);
            }
Esempio n. 9
0
            /// <summary>Bring the axis back to the cenetered state (only if enabled).</summary>
            public void DoRecentering(ref AxisState axis, float deltaTime, float recenterTarget)
            {
                if (!m_enabled)
                {
                    return;
                }

                if (deltaTime < 0)
                {
                    CancelRecentering();
                    axis.Value = recenterTarget;
                }
                else if (Time.time > (mLastAxisInputTime + m_WaitTime))
                {
                    // Scale value determined heuristically, to account for accel/decel
                    float recenterTime = m_RecenteringTime / 3f;
                    if (recenterTime <= deltaTime)
                    {
                        axis.Value = recenterTarget;
                    }
                    else
                    {
                        float headingError    = Mathf.DeltaAngle(axis.Value, recenterTarget);
                        float absHeadingError = Mathf.Abs(headingError);
                        if (absHeadingError < UnityVectorExtensions.Epsilon)
                        {
                            axis.Value           = recenterTarget;
                            mRecenteringVelocity = 0;
                        }
                        else
                        {
                            float scale           = deltaTime / recenterTime;
                            float desiredVelocity = Mathf.Sign(headingError)
                                                    * Mathf.Min(absHeadingError, absHeadingError * scale);
                            // Accelerate to the desired velocity
                            float accel = desiredVelocity - mRecenteringVelocity;
                            if ((desiredVelocity < 0 && accel < 0) || (desiredVelocity > 0 && accel > 0))
                            {
                                desiredVelocity = mRecenteringVelocity + desiredVelocity * scale;
                            }
                            axis.Value          += desiredVelocity;
                            mRecenteringVelocity = desiredVelocity;
                        }
                    }
                }
            }
 void UpdateHeading(float deltaTime, Vector3 up)
 {
     // We let the first rig calculate the heading
     if (mOrbitals[0] != null)
     {
         mOrbitals[0].UpdateHeading(deltaTime, up);
         m_XAxis = mOrbitals[0].m_XAxis;
     }
     // Then push it to the other rigs
     for (int i = 1; i < mOrbitals.Length; ++i)
     {
         if (mOrbitals[i] != null)
         {
             mOrbitals[i].m_XAxis = m_XAxis;
         }
     }
 }
Esempio n. 11
0
        public bool Update(float deltaTime, ref AxisState axis)
        {
            if (!string.IsNullOrEmpty(name))
            {
                try { inputValue = CinemachineCore.GetInputAxis(name); }
                catch (ArgumentException) {}
                //catch (ArgumentException e) { Debug.LogError(e.ToString()); }
            }

            float input = inputValue * multiplier;

            if (deltaTime < Epsilon)
            {
                mCurrentSpeed = 0;
            }
            else
            {
                float speed    = input / deltaTime;
                float dampTime = Mathf.Abs(speed) < Mathf.Abs(mCurrentSpeed) ? decelTime : accelTime;
                speed         = mCurrentSpeed + Damper.Damp(speed - mCurrentSpeed, dampTime, deltaTime);
                mCurrentSpeed = speed;

                // Decelerate to the end points of the range if not wrapping
                float range = axis.m_MaxValue - axis.m_MinValue;
                if (!axis.m_Wrap && decelTime > Epsilon && range > Epsilon)
                {
                    float v0 = ClampValue(ref axis, axis.Value);
                    float v  = ClampValue(ref axis, v0 + speed * deltaTime);
                    float d  = (speed > 0) ? axis.m_MaxValue - v : v - axis.m_MinValue;
                    if (d < (0.1f * range) && Mathf.Abs(speed) > Epsilon)
                    {
                        speed = Damper.Damp(v - v0, decelTime, deltaTime) / deltaTime;
                    }
                }
                input = speed * deltaTime;
            }

            axis.Value = ClampValue(ref axis, axis.Value + input);
            return(Mathf.Abs(inputValue) > Epsilon);
        }
Esempio n. 12
0
        void UpdateHeading(float deltaTime, Vector3 up)
        {
            // We let the first rig calculate the heading
            if (mOrbitals[0] != null)
            {
                mOrbitals[0].UpdateHeading(deltaTime, up);
                m_XAxis = mOrbitals[0].m_XAxis;
            }
            // Then push it to the other rigs
            for (int i = 1; i < mOrbitals.Length; ++i)
            {
                if (mOrbitals[i] != null)
                {
                    mOrbitals[i].m_XAxis = m_XAxis;
                }
            }

            if (m_BindingMode == CinemachineTransposer.BindingMode.SimpleFollowWithWorldUp)
            {
                m_XAxis.Value = 0;
            }
        }
 /// <summary>
 /// Update the X axis and calculate the heading.  This can be called by a delegate
 /// with a custom axis.  Note that this method is obsolete.
 /// <param name="deltaTime">Used for damping.  If less than 0, no damping is done.</param>
 /// <param name="up">World Up, set by the CinemachineBrain</param>
 /// <param name="axis"></param>
 /// <returns>Axis value</returns>
 /// </summary>
 public float UpdateHeading(float deltaTime, Vector3 up, ref AxisState axis)
 {
     return(UpdateHeading(deltaTime, up, ref axis, ref m_RecenterToTargetHeading, true));
 }
Esempio n. 14
0
        /// <summary>
        /// Update the X axis and calculate the heading.  This can be called by a delegate
        /// with a custom axis.
        /// <param name="deltaTime">Used for damping.  If less than 0, no damping is done.</param>
        /// <param name="up">World Up, set by the CinemachineBrain</param>
        /// <param name="axis"></param>
        /// <returns>Axis value</returns>
        /// </summary>
        public float UpdateHeading(float deltaTime, Vector3 up, ref AxisState axis)
        {
            // Only read joystick when game is playing
            if (deltaTime >= 0 || CinemachineCore.Instance.IsLive(VirtualCamera))
            {
                bool xAxisInput = false;
                xAxisInput |= axis.Update(deltaTime);
                if (xAxisInput)
                {
                    mLastHeadingAxisInputTime   = Time.time;
                    mHeadingRecenteringVelocity = 0;
                }
            }
            float targetHeading = GetTargetHeading(axis.Value, GetReferenceOrientation(up), deltaTime);

            if (deltaTime < 0)
            {
                mHeadingRecenteringVelocity = 0;
                if (m_RecenterToTargetHeading.m_enabled)
                {
                    axis.Value = targetHeading;
                }
            }
            else
            {
                // Recentering
                if (m_BindingMode != BindingMode.SimpleFollowWithWorldUp &&
                    m_RecenterToTargetHeading.m_enabled &&
                    (Time.time > (mLastHeadingAxisInputTime + m_RecenterToTargetHeading.m_RecenterWaitTime)))
                {
                    // Scale value determined heuristically, to account for accel/decel
                    float recenterTime = m_RecenterToTargetHeading.m_RecenteringTime / 3f;
                    if (recenterTime <= deltaTime)
                    {
                        axis.Value = targetHeading;
                    }
                    else
                    {
                        float headingError    = Mathf.DeltaAngle(axis.Value, targetHeading);
                        float absHeadingError = Mathf.Abs(headingError);
                        if (absHeadingError < UnityVectorExtensions.Epsilon)
                        {
                            axis.Value = targetHeading;
                            mHeadingRecenteringVelocity = 0;
                        }
                        else
                        {
                            float scale           = deltaTime / recenterTime;
                            float desiredVelocity = Mathf.Sign(headingError)
                                                    * Mathf.Min(absHeadingError, absHeadingError * scale);
                            // Accelerate to the desired velocity
                            float accel = desiredVelocity - mHeadingRecenteringVelocity;
                            if ((desiredVelocity < 0 && accel < 0) || (desiredVelocity > 0 && accel > 0))
                            {
                                desiredVelocity = mHeadingRecenteringVelocity + desiredVelocity * scale;
                            }
                            axis.Value += desiredVelocity;
                            mHeadingRecenteringVelocity = desiredVelocity;
                        }
                    }
                }
            }
            float finalHeading = axis.Value;

            if (m_BindingMode == BindingMode.SimpleFollowWithWorldUp)
            {
                axis.Value = 0;
            }
            return(finalHeading);
        }
Esempio n. 15
0
 /// <summary>
 /// In Slave mode, set the heading by calling this.
 /// </summary>
 public void SetXAxisState(AxisState state)
 {
     m_XAxis = state;
 }
Esempio n. 16
0
            /// <summary>Bring the axis back to the centered state (only if enabled).</summary>
            public void DoRecentering(ref AxisState axis, float deltaTime, float recenterTarget)
            {
                if (!m_enabled && deltaTime >= 0)
                {
                    return;
                }

                recenterTarget = axis.ClampValue(recenterTarget);
                if (deltaTime < 0)
                {
                    CancelRecentering();
                    if (m_enabled)
                    {
                        axis.Value = recenterTarget;
                    }
                    return;
                }


                float v     = axis.ClampValue(axis.Value);
                float delta = recenterTarget - v;

                if (delta == 0)
                {
                    return;
                }

                float input = 0;

                if (m_NeedReTimingInputAxisName != "")
                {
                    string[] names = m_NeedReTimingInputAxisName.Split(';');
                    for (int i = 0; i < names.Length; i++)
                    {
                        if (CinemachineCore.GetInputAxis(names[i]) != 0)
                        {
                            input = 1;
                            break;
                        }
                    }
                }

                if (input != 0)
                {
                    CancelRecentering();
                }

                input = 0;
                if (m_NeedRecenterInputAxisName != "")
                {
                    string[] names = m_NeedRecenterInputAxisName.Split(';');
                    for (int i = 0; i < names.Length; i++)
                    {
                        if (CinemachineCore.GetInputAxis(names[i]) != 0)
                        {
                            input = 1;
                            break;
                        }
                    }
                }

                if (Time.time < (mLastAxisInputTime + m_WaitTime) && input == 0)
                {
                    return;
                }

                // Determine the direction
                float r = axis.m_MaxValue - axis.m_MinValue;

                if (axis.m_Wrap && Mathf.Abs(delta) > r * 0.5f)
                {
                    v += Mathf.Sign(recenterTarget - v) * r;
                }

                // Damp our way there
                float recenteringTime = input == 0? m_RecenteringTime : m_RecenterInputAxisTime;

                if (recenteringTime < 0.001f)
                {
                    v = recenterTarget;
                }
                else
                {
                    v = Mathf.SmoothDamp(
                        v, recenterTarget, ref mRecenteringVelocity,
                        recenteringTime, 9999, deltaTime);
                }
                axis.Value = axis.ClampValue(v);
            }