Ejemplo n.º 1
0
        public Quaternion Evaluate(float curveT)
        {
            if (_keyCount == 0)
            {
                return(Quaternion.identity);
            }

            if (_keyCount == 1)
            {
                return(_curveData.keys[0].value);
            }

            curveT = WrapTime(curveT);
            int lhsIndex = 0, rhsIndex = 0;

            FindIndexForSampling(curveT, ref lhsIndex, ref rhsIndex);
            RotationKeyFrame lhsKey = _curveData.keys[lhsIndex];
            RotationKeyFrame rhsKey = _curveData.keys[rhsIndex];

            float      dx = rhsKey.time - lhsKey.time;
            Quaternion m1, m2;
            float      t;

            if (dx != 0f)
            {
                t  = (curveT - lhsKey.time) / dx;
                m1 = lhsKey.outSlope.MultyScalar(dx);
                m2 = rhsKey.inSlope.MultyScalar(dx);
            }
            else
            {
                t  = 0f;
                m1 = Quaternion.identity;
                m2 = Quaternion.identity;
            }

            Quaternion ret = CurveUtils.HermiteInterpolate(t, lhsKey.value, m1, m2, rhsKey.value);

            CurveUtils.HandleSteppedCurve(ref lhsKey, ref rhsKey, ref ret);

            return(ret);
        }
Ejemplo n.º 2
0
        public Vector3 Evaluate(float curveT)
        {
            if (_keyCount == 0)
            {
                return(Vector3.zero);
            }

            if (_keyCount == 1)
            {
                return(_curveData.keys[0].value);
            }

            curveT = WrapTime(curveT);
            int lhsIndex = 0, rhsIndex = 0;

            FindIndexForSampling(curveT, ref lhsIndex, ref rhsIndex);
            Vector3KeyFrame lhsKey = _curveData.keys[lhsIndex];
            Vector3KeyFrame rhsKey = _curveData.keys[rhsIndex];

            float   dx = rhsKey.time - lhsKey.time;
            Vector3 m1, m2;
            float   t;

            if (dx != 0f)
            {
                t  = (curveT - lhsKey.time) / dx;
                m1 = lhsKey.outSlope * dx;
                m2 = rhsKey.inSlope * dx;
            }
            else
            {
                t  = 0f;
                m1 = Vector3.zero;
                m2 = Vector3.zero;
            }

            Vector3 ret = CurveUtils.HermiteInterpolate(t, lhsKey.value, m1, m2, rhsKey.value);

            CurveUtils.HandleSteppedCurve(ref lhsKey, ref rhsKey, ref ret);

            return(ret);
        }