| 842 | } |
| 843 | |
| 844 | static float interpolate(Slope *aStartSlope, Slope *aEndSlope, float aMidValue, int aTime, int aDuration) |
| 845 | { |
| 846 | int steadyTime = aDuration - (aStartSlope->mTime + aEndSlope->mTime); |
| 847 | |
| 848 | if (steadyTime >= 0) |
| 849 | { |
| 850 | // Interpolate to a midpoint, stay there for a while, then interpolate to end |
| 851 | |
| 852 | if (aTime < aStartSlope->mTime) |
| 853 | { |
| 854 | // interpolate to the first value |
| 855 | return lerp(aStartSlope->mValue, aMidValue, aTime, aStartSlope->mTime); |
| 856 | } |
| 857 | // reached midpoint |
| 858 | |
| 859 | aTime -= aStartSlope->mTime; |
| 860 | |
| 861 | if (aTime <= steadyTime) |
| 862 | { |
| 863 | // still at steady state |
| 864 | return aMidValue; |
| 865 | } |
| 866 | |
| 867 | // interpolate to the end |
| 868 | return lerp(aMidValue, aEndSlope->mValue, aTime - steadyTime, aEndSlope->mTime); |
| 869 | } |
| 870 | else |
| 871 | { |
| 872 | // No steady state |
| 873 | float f = 1.0f - ((float) aTime / (float) aDuration); |
| 874 | float sp = lerp(aStartSlope->mValue, aMidValue, aTime, aStartSlope->mTime); |
| 875 | float ep = lerp(aEndSlope->mValue, aMidValue, aDuration - aTime, aEndSlope->mTime); |
| 876 | return f * sp + ((float) 1.0 - f) * ep; |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | |
| 881 | |