Annotation of /trunk/indra/newview/llwlanimator.cpp
Parent Directory
|
Revision Log
Revision 137 - (view) (download)
| 1 : | mjm | 135 | /** |
| 2 : | * @file llwlanimator.cpp | ||
| 3 : | * @brief Implementation for the LLWLAnimator class. | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2007&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | mjm | 137 | * Copyright (c) 2007-2010, Linden Research, Inc. |
| 8 : | mjm | 135 | * |
| 9 : | * Second Life Viewer Source Code | ||
| 10 : | * The source code in this file ("Source Code") is provided by Linden Lab | ||
| 11 : | * to you under the terms of the GNU General Public License, version 2.0 | ||
| 12 : | * ("GPL"), unless you have obtained a separate licensing agreement | ||
| 13 : | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
| 14 : | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
| 15 : | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
| 16 : | * | ||
| 17 : | * There are special exceptions to the terms and conditions of the GPL as | ||
| 18 : | * it is applied to this Source Code. View the full text of the exception | ||
| 19 : | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
| 20 : | * online at | ||
| 21 : | * http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 22 : | * | ||
| 23 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 24 : | * that you have read and understood your obligations described above, | ||
| 25 : | * and agree to abide by those obligations. | ||
| 26 : | * | ||
| 27 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 28 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 29 : | * COMPLETENESS OR PERFORMANCE. | ||
| 30 : | * $/LicenseInfo$ | ||
| 31 : | */ | ||
| 32 : | |||
| 33 : | #include "llviewerprecompiledheaders.h" | ||
| 34 : | |||
| 35 : | #include "llwlanimator.h" | ||
| 36 : | #include "llsky.h" | ||
| 37 : | #include "pipeline.h" | ||
| 38 : | #include "llwlparammanager.h" | ||
| 39 : | |||
| 40 : | LLWLAnimator::LLWLAnimator() : mStartTime(0), mDayRate(1), mDayTime(0), | ||
| 41 : | mIsRunning(FALSE), mUseLindenTime(false) | ||
| 42 : | { | ||
| 43 : | mDayTime = 0; | ||
| 44 : | } | ||
| 45 : | |||
| 46 : | void LLWLAnimator::update(LLWLParamSet& curParams) | ||
| 47 : | { | ||
| 48 : | F64 curTime; | ||
| 49 : | curTime = getDayTime(); | ||
| 50 : | |||
| 51 : | // don't do anything if empty | ||
| 52 : | if(mTimeTrack.size() == 0) { | ||
| 53 : | return; | ||
| 54 : | } | ||
| 55 : | |||
| 56 : | // start it off | ||
| 57 : | mFirstIt = mTimeTrack.begin(); | ||
| 58 : | mSecondIt = mTimeTrack.begin(); | ||
| 59 : | mSecondIt++; | ||
| 60 : | |||
| 61 : | // grab the two tween iterators | ||
| 62 : | while(mSecondIt != mTimeTrack.end() && curTime > mSecondIt->first) { | ||
| 63 : | mFirstIt++; | ||
| 64 : | mSecondIt++; | ||
| 65 : | } | ||
| 66 : | |||
| 67 : | // scroll it around when you get to the end | ||
| 68 : | if(mSecondIt == mTimeTrack.end() || mFirstIt->first > curTime) { | ||
| 69 : | mSecondIt = mTimeTrack.begin(); | ||
| 70 : | mFirstIt = mTimeTrack.end(); | ||
| 71 : | mFirstIt--; | ||
| 72 : | } | ||
| 73 : | |||
| 74 : | F32 weight = 0; | ||
| 75 : | |||
| 76 : | if(mFirstIt->first < mSecondIt->first) { | ||
| 77 : | |||
| 78 : | // get the delta time and the proper weight | ||
| 79 : | weight = F32 (curTime - mFirstIt->first) / | ||
| 80 : | (mSecondIt->first - mFirstIt->first); | ||
| 81 : | |||
| 82 : | // handle the ends | ||
| 83 : | } else if(mFirstIt->first > mSecondIt->first) { | ||
| 84 : | |||
| 85 : | // right edge of time line | ||
| 86 : | if(curTime >= mFirstIt->first) { | ||
| 87 : | weight = F32 (curTime - mFirstIt->first) / | ||
| 88 : | ((1 + mSecondIt->first) - mFirstIt->first); | ||
| 89 : | |||
| 90 : | // left edge of time line | ||
| 91 : | } else { | ||
| 92 : | weight = F32 ((1 + curTime) - mFirstIt->first) / | ||
| 93 : | ((1 + mSecondIt->first) - mFirstIt->first); | ||
| 94 : | } | ||
| 95 : | |||
| 96 : | |||
| 97 : | // handle same as whatever the last one is | ||
| 98 : | } else { | ||
| 99 : | weight = 1; | ||
| 100 : | } | ||
| 101 : | |||
| 102 : | // do the interpolation and set the parameters | ||
| 103 : | curParams.mix(LLWLParamManager::instance()->mParamList[mFirstIt->second], | ||
| 104 : | LLWLParamManager::instance()->mParamList[mSecondIt->second], weight); | ||
| 105 : | } | ||
| 106 : | |||
| 107 : | F64 LLWLAnimator::getDayTime() | ||
| 108 : | { | ||
| 109 : | if(!mIsRunning) { | ||
| 110 : | return mDayTime; | ||
| 111 : | } | ||
| 112 : | |||
| 113 : | if(mUseLindenTime) { | ||
| 114 : | |||
| 115 : | F32 phase = gSky.getSunPhase() / F_PI; | ||
| 116 : | |||
| 117 : | // we're not solving the non-linear equation that determines sun phase | ||
| 118 : | // we're just linearly interpolating between the major points | ||
| 119 : | if (phase <= 5.0 / 4.0) { | ||
| 120 : | mDayTime = (1.0 / 3.0) * phase + (1.0 / 3.0); | ||
| 121 : | } else { | ||
| 122 : | mDayTime = phase - (1.0 / 2.0); | ||
| 123 : | } | ||
| 124 : | |||
| 125 : | if(mDayTime > 1) { | ||
| 126 : | mDayTime--; | ||
| 127 : | } | ||
| 128 : | |||
| 129 : | return mDayTime; | ||
| 130 : | } | ||
| 131 : | |||
| 132 : | // get the time; | ||
| 133 : | mDayTime = (LLTimer::getElapsedSeconds() - mStartTime) / mDayRate; | ||
| 134 : | |||
| 135 : | // clamp it | ||
| 136 : | if(mDayTime < 0) { | ||
| 137 : | mDayTime = 0; | ||
| 138 : | } | ||
| 139 : | while(mDayTime > 1) { | ||
| 140 : | mDayTime--; | ||
| 141 : | } | ||
| 142 : | |||
| 143 : | return (F32)mDayTime; | ||
| 144 : | } | ||
| 145 : | |||
| 146 : | void LLWLAnimator::setDayTime(F64 dayTime) | ||
| 147 : | { | ||
| 148 : | //retroactively set start time; | ||
| 149 : | mStartTime = LLTimer::getElapsedSeconds() - dayTime * mDayRate; | ||
| 150 : | mDayTime = dayTime; | ||
| 151 : | |||
| 152 : | // clamp it | ||
| 153 : | if(mDayTime < 0) { | ||
| 154 : | mDayTime = 0; | ||
| 155 : | } else if(mDayTime > 1) { | ||
| 156 : | mDayTime = 1; | ||
| 157 : | } | ||
| 158 : | } | ||
| 159 : | |||
| 160 : | |||
| 161 : | void LLWLAnimator::setTrack(std::map<F32, std::string>& curTrack, | ||
| 162 : | F32 dayRate, F64 dayTime, bool run) | ||
| 163 : | { | ||
| 164 : | mTimeTrack = curTrack; | ||
| 165 : | mDayRate = dayRate; | ||
| 166 : | setDayTime(dayTime); | ||
| 167 : | |||
| 168 : | mIsRunning = run; | ||
| 169 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

