Clerp() публичный статический Метод

public static Clerp ( float start, float end, float value ) : float
start float
end float
value float
Результат float
Пример #1
0
    /// <summary>
    /// Return value based on curve from Mathfx class.
    /// </summary>
    /// <returns>The value.</returns>
    /// <param name="animationCurve">Animation curve.</param>
    /// <param name="start">Start.</param>
    /// <param name="end">End.</param>
    /// <param name="t">T.</param>
    public static float CurvedValue(AnimationCurveEnum animationCurve, float start, float end, float t)
    {
        switch (animationCurve)
        {
        case AnimationCurveEnum.Hermite:
            return(Mathfx.Hermite(start, end, t));

        case AnimationCurveEnum.Sinerp:
            return(Mathfx.Sinerp(start, end, t));

        case AnimationCurveEnum.Coserp:
            return(Mathfx.Coserp(start, end, t));

        case AnimationCurveEnum.Berp:
            return(Mathfx.Berp(start, end, t));

        case AnimationCurveEnum.Bounce:
            return(start + ((end - start) * Mathfx.Bounce(t)));

        case AnimationCurveEnum.Lerp:
            return(Mathfx.Lerp(start, end, t));

        case AnimationCurveEnum.Clerp:
            return(Mathfx.Clerp(start, end, t));

        default:
            return(0);
        }
    }
Пример #2
0
        private float Roll_change  = 0.0f; // Z

        // Update Rotation Stuff (Returns Final Eulers)
        public void UpdateRotationEuler(ref Quadcopter.States State, ref Quadcopter.Settings Settings)
        {
            // Check Wind Direction
            if (WindGlobal.GetInstance() != null)
            {
                Vector3 WD = WindGlobal.GetInstance().GetWindDirection();
                float   WF = WindGlobal.GetInstance().GetWindStrength() * 0.1f;
                WF = Mathf.Pow(WF, 1.5f);


                if (WF != 0.0f)
                {
                    // If up is aiming perpendicular to wind, no effect
                    float WindEffect = Mathf.Abs(Vector3.Dot(WD, Quadcopter_Up)) * WF;

                    _Rigidbody.gameObject.transform.RotateAround(Position, Vector3.right, WD.y * WindEffect);
                    _Rigidbody.gameObject.transform.RotateAround(Position, Vector3.up, WD.x * WindEffect);
                    _Rigidbody.gameObject.transform.RotateAround(Position, Vector3.forward, WD.z * WindEffect);

                    //Vector3 TargetForward = WD;
                    //// Check if direction is closer to backwards
                    //if (Vector3.Distance(Quadcopter_Forward, WD) > Vector3.Distance(Quadcopter_Forward, -WD))
                    //{
                    //    //TargetForward = -WD;
                    //}
                    //
                    //// Slerp forward to target forward
                    //_Rigidbody.gameObject.transform.up = Vector3.Slerp(Quadcopter_Up, TargetForward, 0.02f * WindEffect).normalized;
                }
            }

            // Update movement rotation if not broken
            if (!Settings._Broken)
            {
                // Update Ideal Eulers
                Pitch_Change = State.GetEulerChanges().x *Settings._PitchSpeed *((Settings._InversePitch) ? -1.0f : 1.0f);
                Yaw_Change   = State.GetEulerChanges().y *Settings._YawSpeed *((Settings._InverseYaw) ? -1.0f : 1.0f);
                Roll_change  = State.GetEulerChanges().z *Settings._RollSpeed *((Settings._InverseRoll) ? -1.0f : 1.0f);

                // Update Rotations
                _Rigidbody.gameObject.transform.RotateAround(Position, Quadcopter_Right, Pitch_Change);
                _Rigidbody.gameObject.transform.RotateAround(Position, Quadcopter_Up, Yaw_Change);
                _Rigidbody.gameObject.transform.RotateAround(Position, Quadcopter_Forward, Roll_change);

                // If rest state, fix orientation if controls aren't being touced
                if (Pitch_Change == 0.0f && Yaw_Change == 0.0f && Roll_change == 0.0f && Settings._ThrusterRest)
                {
                    Vector3 Euler = _Rigidbody.gameObject.transform.eulerAngles;

                    float spd = 0.06f;
                    Euler.x = Mathfx.Clerp(Euler.x, 0.0f, spd);
                    //Euler.y = Mathfx.Clerp(Euler.y, 0.0f, spd);
                    Euler.z = Mathfx.Clerp(Euler.z, 0.0f, spd);

                    _Rigidbody.gameObject.transform.eulerAngles = Euler;
                }
            }
        }
    private float DoLerp()
    {
        switch (this._currentLerpType)
        {
        case LerpType.Lerp: return(Mathfx.Lerp(this.From, this.To, this.LerpZeroToOne));

        case LerpType.Hermite: return(Mathfx.Lerp(this.From, this.To, this.LerpZeroToOne));

        case LerpType.Sinerp: return(Mathfx.Sinerp(this.From, this.To, this.LerpZeroToOne));

        case LerpType.Coserp: return(Mathfx.Coserp(this.From, this.To, this.LerpZeroToOne));

        case LerpType.Berp: return(Mathfx.Berp(this.From, this.To, this.LerpZeroToOne));

        case LerpType.Smoothstep: return(Mathfx.SmoothStep(this.From, this.To, this.LerpZeroToOne));

        case LerpType.Clerp: return(Mathfx.Clerp(this.From, this.To, this.LerpZeroToOne));

        default: throw new ArgumentOutOfRangeException();
        }
    }
    void Update()
    {
        deltaTime = Time.realtimeSinceStartup - prevTime;
        prevTime  = Time.realtimeSinceStartup;

        //315 - 355
        if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
        {
            transform.Translate(new Vector3(speed * deltaTime, 0, 0), Space.World);
        }
        if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
        {
            transform.Translate(new Vector3(-speed * deltaTime, 0, 0), Space.World);
        }
        if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))
        {
            transform.Translate(new Vector3(0, -speed * deltaTime, 0), Space.World);
        }
        if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
        {
            transform.Translate(new Vector3(0, speed * deltaTime, 0), Space.World);
        }
        if (!GameMaster.GM.inputFocus && Input.GetAxis("Mouse ScrollWheel") < 0) // OUT
        {
            position           = transform.position;
            position.z        -= 5;
            position.z         = Mathf.Clamp(position.z, -maxHeigh, -minHeigh);
            transform.position = position;

            t = (position.z - (-minHeigh)) / (-maxHeigh - (-minHeigh));
            t = Mathf.Clamp01(t);
            //rotation.x = Mathfx.Sinerp(310, 350, t);
            rotation.x            = Mathfx.Clerp(minAngle, maxAngle, t);
            transform.eulerAngles = rotation;
        }
        if (!GameMaster.GM.inputFocus && Input.GetAxis("Mouse ScrollWheel") > 0) // IN
        {
            position           = transform.position;
            position.z        += 5;
            position.z         = Mathf.Clamp(position.z, -maxHeigh, -minHeigh);
            transform.position = position;

            t = (position.z - (-minHeigh)) / (-maxHeigh - (-minHeigh));
            t = Mathf.Clamp01(t);
            //rotation.x = Mathfx.Sinerp(310, 350f, t);
            rotation.x            = Mathfx.Clerp(minAngle, maxAngle, t);
            transform.eulerAngles = rotation;
        }
        //if(Input.GetMouseButton(1)){
        //    transform.Translate(new Vector3(Input.GetAxis ("Mouse X") * 2, Input.GetAxis ("Mouse Y") * 2, 0), Space.World);
        //}

        /*
         * RaycastHit hit;
         *
         * if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),out hit))
         * {
         *  gameObject.transform.position = hit.point;
         * }
         */
        if (Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2))
        {
            lastPosition = Input.mousePosition;
        }
        if (Input.GetMouseButton(1) || Input.GetMouseButton(2))
        {
            var delta = Input.mousePosition - lastPosition;
            transform.Translate(-delta.x * 0.4f, -delta.y * 0.4f, 0, Space.World);
            lastPosition = Input.mousePosition;
        }
    }