diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llviewertextureanim.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llviewertextureanim.cpp')
-rw-r--r-- | linden/indra/newview/llviewertextureanim.cpp | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/linden/indra/newview/llviewertextureanim.cpp b/linden/indra/newview/llviewertextureanim.cpp new file mode 100644 index 0000000..0766b83 --- /dev/null +++ b/linden/indra/newview/llviewertextureanim.cpp | |||
@@ -0,0 +1,210 @@ | |||
1 | /** | ||
2 | * @file llviewertextureanim.cpp | ||
3 | * @brief LLViewerTextureAnim class implementation | ||
4 | * | ||
5 | * Copyright (c) 2003-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "llviewerprecompiledheaders.h" | ||
29 | |||
30 | #include "llviewertextureanim.h" | ||
31 | |||
32 | #include "llmath.h" | ||
33 | #include "llerror.h" | ||
34 | |||
35 | LLViewerTextureAnim::LLViewerTextureAnim() : LLTextureAnim() | ||
36 | { | ||
37 | mLastFrame = -1.f; // Force an update initially | ||
38 | mLastTime = 0.f; | ||
39 | } | ||
40 | |||
41 | LLViewerTextureAnim::~LLViewerTextureAnim() | ||
42 | { | ||
43 | } | ||
44 | |||
45 | void LLViewerTextureAnim::reset() | ||
46 | { | ||
47 | LLTextureAnim::reset(); | ||
48 | mTimer.reset(); | ||
49 | } | ||
50 | |||
51 | |||
52 | S32 LLViewerTextureAnim::animateTextures(F32 &off_s, F32 &off_t, | ||
53 | F32 &scale_s, F32 &scale_t, | ||
54 | F32 &rot) | ||
55 | { | ||
56 | S32 result = 0; | ||
57 | if (!(mMode & ON)) | ||
58 | { | ||
59 | mLastTime = 0.f; | ||
60 | mLastFrame = -1.f; | ||
61 | return result; | ||
62 | } | ||
63 | |||
64 | |||
65 | F32 num_frames = 1.0; | ||
66 | F32 full_length = 1.0; | ||
67 | |||
68 | if (mLength) | ||
69 | { | ||
70 | num_frames = mLength; | ||
71 | } | ||
72 | else | ||
73 | { | ||
74 | num_frames = llmax(1.f, (F32)(mSizeX * mSizeY)); | ||
75 | } | ||
76 | |||
77 | if (mMode & PING_PONG) | ||
78 | { | ||
79 | if (mMode & SMOOTH) | ||
80 | { | ||
81 | full_length = 2.f*num_frames; | ||
82 | } | ||
83 | else if (mMode & LOOP) | ||
84 | { | ||
85 | full_length = 2.f*num_frames - 2.f; | ||
86 | full_length = llmax(1.f, full_length); | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | full_length = 2.f*num_frames - 1.f; | ||
91 | full_length = llmax(1.f, full_length); | ||
92 | } | ||
93 | } | ||
94 | else | ||
95 | { | ||
96 | full_length = num_frames; | ||
97 | } | ||
98 | |||
99 | |||
100 | F32 frame_counter; | ||
101 | if (mMode & SMOOTH) | ||
102 | { | ||
103 | frame_counter = mTimer.getElapsedTimeAndResetF32() * mRate + (F32)mLastTime; | ||
104 | } | ||
105 | else | ||
106 | { | ||
107 | frame_counter = mTimer.getElapsedTimeF32() * mRate; | ||
108 | } | ||
109 | mLastTime = frame_counter; | ||
110 | |||
111 | if (mMode & LOOP) | ||
112 | { | ||
113 | frame_counter = fmod(frame_counter, full_length); | ||
114 | } | ||
115 | else | ||
116 | { | ||
117 | frame_counter = llmin(full_length - 1.f, frame_counter); | ||
118 | } | ||
119 | |||
120 | if (!(mMode & SMOOTH)) | ||
121 | { | ||
122 | frame_counter = (F32)llfloor(frame_counter + 0.01f); | ||
123 | } | ||
124 | |||
125 | if (mMode & PING_PONG) | ||
126 | { | ||
127 | if (frame_counter >= num_frames) | ||
128 | { | ||
129 | if (mMode & SMOOTH) | ||
130 | { | ||
131 | frame_counter = num_frames - (frame_counter - num_frames); | ||
132 | } | ||
133 | else | ||
134 | { | ||
135 | frame_counter = (num_frames - 1.99f) - (frame_counter - num_frames); | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | |||
140 | if (mMode & REVERSE) | ||
141 | { | ||
142 | if (mMode & SMOOTH) | ||
143 | { | ||
144 | frame_counter = num_frames - frame_counter; | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | frame_counter = (num_frames - 0.99f) - frame_counter; | ||
149 | } | ||
150 | } | ||
151 | |||
152 | frame_counter += mStart; | ||
153 | |||
154 | if (!(mMode & SMOOTH)) | ||
155 | { | ||
156 | frame_counter = (F32)llround(frame_counter); | ||
157 | } | ||
158 | |||
159 | // | ||
160 | // Now that we've calculated the frame time, do an update. | ||
161 | // Will we correctly update stuff if the texture anim has | ||
162 | // changed, but not the frame counter? | ||
163 | // | ||
164 | if (mLastFrame != frame_counter) | ||
165 | { | ||
166 | mLastFrame = frame_counter; | ||
167 | if (mMode & ROTATE) | ||
168 | { | ||
169 | result |= ROTATE; | ||
170 | rot = frame_counter; | ||
171 | } | ||
172 | else if (mMode & SCALE) | ||
173 | { | ||
174 | result |= SCALE; | ||
175 | scale_s = frame_counter; | ||
176 | scale_t = frame_counter; | ||
177 | } | ||
178 | else | ||
179 | { | ||
180 | result |= TRANSLATE; | ||
181 | F32 x_frame; | ||
182 | S32 y_frame; | ||
183 | F32 x_pos; | ||
184 | F32 y_pos; | ||
185 | |||
186 | if ( (mSizeX) | ||
187 | &&(mSizeY)) | ||
188 | { | ||
189 | result |= SCALE; | ||
190 | scale_s = 1.f/mSizeX; | ||
191 | scale_t = 1.f/mSizeY; | ||
192 | x_frame = fmod(frame_counter, mSizeX); | ||
193 | y_frame = (S32)(frame_counter / mSizeX); | ||
194 | x_pos = x_frame * scale_s; | ||
195 | y_pos = y_frame * scale_t; | ||
196 | off_s = (-0.5f + 0.5f*scale_s)+ x_pos; | ||
197 | off_t = (0.5f - 0.5f*scale_t) - y_pos; | ||
198 | } | ||
199 | else | ||
200 | { | ||
201 | scale_s = 1.f; | ||
202 | scale_t = 1.f; | ||
203 | x_pos = frame_counter * scale_s; | ||
204 | off_s = (-0.5f + 0.5f*scale_s)+ x_pos; | ||
205 | off_t = 0.f; | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | return result; | ||
210 | } | ||