00001 00032 #include "linden_common.h" 00033 00034 #include "llcriticaldamp.h" 00035 00036 //----------------------------------------------------------------------------- 00037 // static members 00038 //----------------------------------------------------------------------------- 00039 LLFrameTimer LLCriticalDamp::sInternalTimer; 00040 std::map<F32, F32> LLCriticalDamp::sInterpolants; 00041 F32 LLCriticalDamp::sTimeDelta; 00042 00043 //----------------------------------------------------------------------------- 00044 // LLCriticalDamp() 00045 //----------------------------------------------------------------------------- 00046 LLCriticalDamp::LLCriticalDamp() 00047 { 00048 sTimeDelta = 0.f; 00049 } 00050 00051 // static 00052 //----------------------------------------------------------------------------- 00053 // updateInterpolants() 00054 //----------------------------------------------------------------------------- 00055 void LLCriticalDamp::updateInterpolants() 00056 { 00057 sTimeDelta = sInternalTimer.getElapsedTimeAndResetF32(); 00058 00059 F32 time_constant; 00060 00061 for (std::map<F32, F32>::iterator iter = sInterpolants.begin(); 00062 iter != sInterpolants.end(); iter++) 00063 { 00064 time_constant = iter->first; 00065 F32 new_interpolant = 1.f - pow(2.f, -sTimeDelta / time_constant); 00066 new_interpolant = llclamp(new_interpolant, 0.f, 1.f); 00067 sInterpolants[time_constant] = new_interpolant; 00068 } 00069 } 00070 00071 //----------------------------------------------------------------------------- 00072 // getInterpolant() 00073 //----------------------------------------------------------------------------- 00074 F32 LLCriticalDamp::getInterpolant(const F32 time_constant, BOOL use_cache) 00075 { 00076 if (time_constant == 0.f) 00077 { 00078 return 1.f; 00079 } 00080 00081 if (use_cache && sInterpolants.count(time_constant)) 00082 { 00083 return sInterpolants[time_constant]; 00084 } 00085 00086 F32 interpolant = 1.f - pow(2.f, -sTimeDelta / time_constant); 00087 interpolant = llclamp(interpolant, 0.f, 1.f); 00088 if (use_cache) 00089 { 00090 sInterpolants[time_constant] = interpolant; 00091 } 00092 00093 return interpolant; 00094 }