aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llwlanimator.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/newview/llwlanimator.cpp
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llwlanimator.cpp168
1 files changed, 168 insertions, 0 deletions
diff --git a/linden/indra/newview/llwlanimator.cpp b/linden/indra/newview/llwlanimator.cpp
new file mode 100644
index 0000000..d87c379
--- /dev/null
+++ b/linden/indra/newview/llwlanimator.cpp
@@ -0,0 +1,168 @@
1/**
2 * @file llwlanimator.cpp
3 * @brief Implementation for the LLWLAnimator class.
4 *
5 * $LicenseInfo:firstyear=2007&license=viewergpl$
6 *
7 * Copyright (c) 2007-2008, Linden Research, Inc.
8 *
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 http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#include "llviewerprecompiledheaders.h"
33
34#include "llwlanimator.h"
35#include "llsky.h"
36#include "pipeline.h"
37#include "llwlparammanager.h"
38
39LLWLAnimator::LLWLAnimator() : mStartTime(0), mDayRate(1), mDayTime(0),
40 mIsRunning(FALSE), mUseLindenTime(false)
41{
42 mDayTime = 0;
43}
44
45void LLWLAnimator::update(LLWLParamSet& curParams)
46{
47 F64 curTime;
48 curTime = getDayTime();
49
50 // don't do anything if empty
51 if(mTimeTrack.size() == 0) {
52 return;
53 }
54
55 // start it off
56 mFirstIt = mTimeTrack.begin();
57 mSecondIt = mTimeTrack.begin();
58 mSecondIt++;
59
60 // grab the two tween iterators
61 while(mSecondIt != mTimeTrack.end() && curTime > mSecondIt->first) {
62 mFirstIt++;
63 mSecondIt++;
64 }
65
66 // scroll it around when you get to the end
67 if(mSecondIt == mTimeTrack.end() || mFirstIt->first > curTime) {
68 mSecondIt = mTimeTrack.begin();
69 mFirstIt = mTimeTrack.end();
70 mFirstIt--;
71 }
72
73 F32 weight = 0;
74
75 if(mFirstIt->first < mSecondIt->first) {
76
77 // get the delta time and the proper weight
78 weight = F32 (curTime - mFirstIt->first) /
79 (mSecondIt->first - mFirstIt->first);
80
81 // handle the ends
82 } else if(mFirstIt->first > mSecondIt->first) {
83
84 // right edge of time line
85 if(curTime >= mFirstIt->first) {
86 weight = F32 (curTime - mFirstIt->first) /
87 ((1 + mSecondIt->first) - mFirstIt->first);
88
89 // left edge of time line
90 } else {
91 weight = F32 ((1 + curTime) - mFirstIt->first) /
92 ((1 + mSecondIt->first) - mFirstIt->first);
93 }
94
95
96 // handle same as whatever the last one is
97 } else {
98 weight = 1;
99 }
100
101 // do the interpolation and set the parameters
102 curParams.mix(LLWLParamManager::instance()->mParamList[mFirstIt->second],
103 LLWLParamManager::instance()->mParamList[mSecondIt->second], weight);
104}
105
106F64 LLWLAnimator::getDayTime()
107{
108 if(!mIsRunning) {
109 return mDayTime;
110 }
111
112 if(mUseLindenTime) {
113
114 F32 phase = gSky.getSunPhase() / F_PI;
115
116 // we're not solving the non-linear equation that determines sun phase
117 // we're just linearly interpolating between the major points
118 if (phase <= 5.0 / 4.0) {
119 mDayTime = (1.0 / 3.0) * phase + (1.0 / 3.0);
120 } else {
121 mDayTime = phase - (1.0 / 2.0);
122 }
123
124 if(mDayTime > 1) {
125 mDayTime--;
126 }
127
128 return mDayTime;
129 }
130
131 // get the time;
132 mDayTime = (LLTimer::getElapsedSeconds() - mStartTime) / mDayRate;
133
134 // clamp it
135 if(mDayTime < 0) {
136 mDayTime = 0;
137 }
138 while(mDayTime > 1) {
139 mDayTime--;
140 }
141
142 return (F32)mDayTime;
143}
144
145void LLWLAnimator::setDayTime(F64 dayTime)
146{
147 //retroactively set start time;
148 mStartTime = LLTimer::getElapsedSeconds() - dayTime * mDayRate;
149 mDayTime = dayTime;
150
151 // clamp it
152 if(mDayTime < 0) {
153 mDayTime = 0;
154 } else if(mDayTime > 1) {
155 mDayTime = 1;
156 }
157}
158
159
160void LLWLAnimator::setTrack(std::map<F32, std::string>& curTrack,
161 F32 dayRate, F64 dayTime, bool run)
162{
163 mTimeTrack = curTrack;
164 mDayRate = dayRate;
165 setDayTime(dayTime);
166
167 mIsRunning = run;
168}