llwlanimator.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llwlanimator.h"
00035 #include "llsky.h"
00036 #include "pipeline.h"
00037 #include "llwlparammanager.h"
00038 
00039 LLWLAnimator::LLWLAnimator() : mStartTime(0), mDayRate(1), mDayTime(0),
00040         mIsRunning(FALSE), mUseLindenTime(false)
00041 {
00042         mDayTime = 0;
00043 }
00044 
00045 void LLWLAnimator::update(LLWLParamSet& curParams)
00046 {
00047         F64 curTime;
00048         curTime = getDayTime();
00049 
00050         // don't do anything if empty
00051         if(mTimeTrack.size() == 0) {
00052                 return;
00053         }
00054 
00055         // start it off
00056         mFirstIt = mTimeTrack.begin();
00057         mSecondIt = mTimeTrack.begin();
00058         mSecondIt++;
00059 
00060         // grab the two tween iterators
00061         while(mSecondIt != mTimeTrack.end() && curTime > mSecondIt->first) {
00062                 mFirstIt++;
00063                 mSecondIt++;
00064         }
00065 
00066         // scroll it around when you get to the end
00067         if(mSecondIt == mTimeTrack.end() || mFirstIt->first > curTime) {
00068                 mSecondIt = mTimeTrack.begin();
00069                 mFirstIt = mTimeTrack.end();
00070                 mFirstIt--;
00071         }
00072 
00073         F32 weight = 0;
00074 
00075         if(mFirstIt->first < mSecondIt->first) {
00076         
00077                 // get the delta time and the proper weight
00078                 weight = F32 (curTime - mFirstIt->first) / 
00079                         (mSecondIt->first - mFirstIt->first);
00080         
00081         // handle the ends
00082         } else if(mFirstIt->first > mSecondIt->first) {
00083                 
00084                 // right edge of time line
00085                 if(curTime >= mFirstIt->first) {
00086                         weight = F32 (curTime - mFirstIt->first) /
00087                         ((1 + mSecondIt->first) - mFirstIt->first);
00088                 
00089                 // left edge of time line
00090                 } else {
00091                         weight = F32 ((1 + curTime) - mFirstIt->first) /
00092                         ((1 + mSecondIt->first) - mFirstIt->first);
00093                 }
00094 
00095         
00096         // handle same as whatever the last one is
00097         } else {
00098                 weight = 1;
00099         }
00100 
00101         // do the interpolation and set the parameters
00102         curParams.mix(LLWLParamManager::instance()->mParamList[mFirstIt->second], 
00103                 LLWLParamManager::instance()->mParamList[mSecondIt->second], weight);
00104 }
00105 
00106 F64 LLWLAnimator::getDayTime()
00107 {
00108         if(!mIsRunning) {
00109                 return mDayTime;
00110         }
00111 
00112         if(mUseLindenTime) {
00113 
00114                 F32 phase = gSky.getSunPhase() / F_PI;
00115 
00116                 // we're not solving the non-linear equation that determines sun phase
00117                 // we're just linearly interpolating between the major points
00118                 if (phase <= 5.0 / 4.0) {
00119                         mDayTime = (1.0 / 3.0) * phase + (1.0 / 3.0);
00120                 } else {
00121                         mDayTime = phase - (1.0 / 2.0);
00122                 }
00123 
00124                 if(mDayTime > 1) {
00125                         mDayTime--;
00126                 }
00127 
00128                 return mDayTime;
00129         }
00130 
00131         // get the time;
00132         mDayTime = (LLTimer::getElapsedSeconds() - mStartTime) / mDayRate;
00133 
00134         // clamp it
00135         if(mDayTime < 0) {
00136                 mDayTime = 0;
00137         } 
00138         while(mDayTime > 1) {
00139                 mDayTime--;
00140         }
00141 
00142         return (F32)mDayTime;
00143 }
00144 
00145 void LLWLAnimator::setDayTime(F64 dayTime)
00146 {
00147         //retroactively set start time;
00148         mStartTime = LLTimer::getElapsedSeconds() - dayTime * mDayRate;
00149         mDayTime = dayTime;
00150 
00151         // clamp it
00152         if(mDayTime < 0) {
00153                 mDayTime = 0;
00154         } else if(mDayTime > 1) {
00155                 mDayTime = 1;
00156         }
00157 }
00158 
00159 
00160 void LLWLAnimator::setTrack(std::map<F32, std::string>& curTrack,
00161                                                         F32 dayRate, F64 dayTime, bool run)
00162 {
00163         mTimeTrack = curTrack;
00164         mDayRate = dayRate;
00165         setDayTime(dayTime);
00166 
00167         mIsRunning = run;
00168 }

Generated on Fri May 16 08:34:25 2008 for SecondLife by  doxygen 1.5.5