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/llhudicon.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 '')
-rw-r--r-- | linden/indra/newview/llhudicon.cpp | 272 |
1 files changed, 272 insertions, 0 deletions
diff --git a/linden/indra/newview/llhudicon.cpp b/linden/indra/newview/llhudicon.cpp new file mode 100644 index 0000000..169a12b --- /dev/null +++ b/linden/indra/newview/llhudicon.cpp | |||
@@ -0,0 +1,272 @@ | |||
1 | /** | ||
2 | * @file llhudicon.cpp | ||
3 | * @brief LLHUDIcon class implementation | ||
4 | * | ||
5 | * Copyright (c) 2006-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 "llhudicon.h" | ||
31 | |||
32 | #include "llgl.h" | ||
33 | |||
34 | #include "llviewerobject.h" | ||
35 | #include "lldrawable.h" | ||
36 | #include "llviewercamera.h" | ||
37 | #include "llviewerwindow.h" | ||
38 | |||
39 | //----------------------------------------------------------------------------- | ||
40 | // Local consts | ||
41 | //----------------------------------------------------------------------------- | ||
42 | const F32 ANIM_TIME = 0.4f; | ||
43 | const F32 DIST_START_FADE = 15.f; | ||
44 | const F32 DIST_END_FADE = 30.f; | ||
45 | const F32 MAX_VISIBLE_TIME = 15.f; | ||
46 | const F32 FADE_OUT_TIME = 1.f; | ||
47 | |||
48 | //----------------------------------------------------------------------------- | ||
49 | // Utility functions | ||
50 | //----------------------------------------------------------------------------- | ||
51 | static F32 calc_bouncy_animation(F32 x) | ||
52 | { | ||
53 | return -(cosf(x * F_PI * 2.5f - F_PI_BY_TWO))*(0.4f + x * -0.1f) + x * 1.3f; | ||
54 | } | ||
55 | |||
56 | |||
57 | //----------------------------------------------------------------------------- | ||
58 | // static declarations | ||
59 | //----------------------------------------------------------------------------- | ||
60 | LLHUDIcon::icon_instance_t LLHUDIcon::sIconInstances; | ||
61 | |||
62 | LLHUDIcon::LLHUDIcon(const U8 type) : | ||
63 | LLHUDObject(type), | ||
64 | mImagep(NULL), | ||
65 | mPickID(0), | ||
66 | mScale(0.1f) | ||
67 | { | ||
68 | sIconInstances.push_back(this); | ||
69 | } | ||
70 | |||
71 | LLHUDIcon::~LLHUDIcon() | ||
72 | { | ||
73 | mImagep = NULL; | ||
74 | } | ||
75 | |||
76 | void LLHUDIcon::renderIcon(BOOL for_select) | ||
77 | { | ||
78 | LLGLSUIDefault texture_state; | ||
79 | LLGLDepthTest gls_depth(GL_TRUE); | ||
80 | LLGLState no_texture(GL_TEXTURE_2D, for_select ? FALSE : TRUE); | ||
81 | |||
82 | if (mSourceObject.isNull() || mImagep.isNull()) | ||
83 | { | ||
84 | markDead(); | ||
85 | return; | ||
86 | } | ||
87 | |||
88 | LLVector3 obj_position = mSourceObject->getRenderPosition(); | ||
89 | |||
90 | // put icon above object, and in front | ||
91 | // RN: don't use drawable radius, it's fricking HUGE | ||
92 | LLVector3 icon_relative_pos = (gCamera->getUpAxis() * ~mSourceObject->getRenderRotation()); | ||
93 | icon_relative_pos.abs(); | ||
94 | |||
95 | F32 distance_scale = llmin(mSourceObject->getScale().mV[VX] / icon_relative_pos.mV[VX], | ||
96 | mSourceObject->getScale().mV[VY] / icon_relative_pos.mV[VY], | ||
97 | mSourceObject->getScale().mV[VZ] / icon_relative_pos.mV[VZ]); | ||
98 | F32 up_distance = 0.5f * distance_scale; | ||
99 | LLVector3 icon_position = obj_position + (up_distance * gCamera->getUpAxis()) * 1.2f; | ||
100 | |||
101 | LLVector3 icon_to_cam = gCamera->getOrigin() - icon_position; | ||
102 | icon_to_cam.normVec(); | ||
103 | |||
104 | icon_position += icon_to_cam * mSourceObject->mDrawable->getRadius() * 1.1f; | ||
105 | |||
106 | mDistance = dist_vec(icon_position, gCamera->getOrigin()); | ||
107 | |||
108 | F32 alpha_factor = for_select ? 1.f : clamp_rescale(mDistance, DIST_START_FADE, DIST_END_FADE, 1.f, 0.f); | ||
109 | |||
110 | LLVector3 x_pixel_vec; | ||
111 | LLVector3 y_pixel_vec; | ||
112 | |||
113 | gCamera->getPixelVectors(icon_position, y_pixel_vec, x_pixel_vec); | ||
114 | |||
115 | F32 scale_factor = 1.f; | ||
116 | if (mAnimTimer.getElapsedTimeF32() < ANIM_TIME) | ||
117 | { | ||
118 | scale_factor = llmax(0.f, calc_bouncy_animation(mAnimTimer.getElapsedTimeF32() / ANIM_TIME)); | ||
119 | } | ||
120 | |||
121 | F32 time_elapsed = mLifeTimer.getElapsedTimeF32(); | ||
122 | if (time_elapsed > MAX_VISIBLE_TIME) | ||
123 | { | ||
124 | markDead(); | ||
125 | return; | ||
126 | } | ||
127 | |||
128 | if (time_elapsed > MAX_VISIBLE_TIME - FADE_OUT_TIME) | ||
129 | { | ||
130 | alpha_factor *= clamp_rescale(time_elapsed, MAX_VISIBLE_TIME - FADE_OUT_TIME, MAX_VISIBLE_TIME, 1.f, 0.f); | ||
131 | } | ||
132 | |||
133 | F32 image_aspect = (F32)mImagep->mFullWidth / (F32)mImagep->mFullHeight; | ||
134 | LLVector3 x_scale = image_aspect * (F32)gViewerWindow->getWindowHeight() * mScale * scale_factor * x_pixel_vec; | ||
135 | LLVector3 y_scale = (F32)gViewerWindow->getWindowHeight() * mScale * scale_factor * y_pixel_vec; | ||
136 | |||
137 | LLVector3 lower_left = icon_position - (x_scale * 0.5f); | ||
138 | LLVector3 lower_right = icon_position + (x_scale * 0.5f); | ||
139 | LLVector3 upper_left = icon_position - (x_scale * 0.5f) + y_scale; | ||
140 | LLVector3 upper_right = icon_position + (x_scale * 0.5f) + y_scale; | ||
141 | |||
142 | if (for_select) | ||
143 | { | ||
144 | // set color to unique color id for picking | ||
145 | LLColor4U coloru((U8)(mPickID >> 16), (U8)(mPickID >> 8), (U8)mPickID); | ||
146 | glColor4ubv(coloru.mV); | ||
147 | } | ||
148 | else | ||
149 | { | ||
150 | LLColor4 icon_color = LLColor4::white; | ||
151 | icon_color.mV[VALPHA] = alpha_factor; | ||
152 | glColor4fv(icon_color.mV); | ||
153 | LLViewerImage::bindTexture(mImagep); | ||
154 | } | ||
155 | |||
156 | glBegin(GL_QUADS); | ||
157 | { | ||
158 | glTexCoord2f(0.f, 1.f); | ||
159 | glVertex3fv(upper_left.mV); | ||
160 | glTexCoord2f(0.f, 0.f); | ||
161 | glVertex3fv(lower_left.mV); | ||
162 | glTexCoord2f(1.f, 0.f); | ||
163 | glVertex3fv(lower_right.mV); | ||
164 | glTexCoord2f(1.f, 1.f); | ||
165 | glVertex3fv(upper_right.mV); | ||
166 | } | ||
167 | glEnd(); | ||
168 | } | ||
169 | |||
170 | void LLHUDIcon::setImage(LLViewerImage* imagep) | ||
171 | { | ||
172 | mImagep = imagep; | ||
173 | mImagep->setClamp(TRUE, TRUE); | ||
174 | } | ||
175 | |||
176 | void LLHUDIcon::setScale(F32 fraction_of_fov) | ||
177 | { | ||
178 | mScale = fraction_of_fov; | ||
179 | } | ||
180 | |||
181 | void LLHUDIcon::markDead() | ||
182 | { | ||
183 | if (mSourceObject) | ||
184 | { | ||
185 | mSourceObject->clearIcon(); | ||
186 | } | ||
187 | LLHUDObject::markDead(); | ||
188 | } | ||
189 | |||
190 | void LLHUDIcon::render() | ||
191 | { | ||
192 | renderIcon(FALSE); | ||
193 | } | ||
194 | |||
195 | void LLHUDIcon::renderForSelect() | ||
196 | { | ||
197 | renderIcon(TRUE); | ||
198 | } | ||
199 | |||
200 | |||
201 | //static | ||
202 | S32 LLHUDIcon::generatePickIDs(S32 start_id, S32 step_size) | ||
203 | { | ||
204 | S32 cur_id = start_id; | ||
205 | icon_instance_t::iterator icon_it; | ||
206 | |||
207 | for(icon_it = sIconInstances.begin(); icon_it != sIconInstances.end(); ++icon_it) | ||
208 | { | ||
209 | (*icon_it)->mPickID = cur_id; | ||
210 | cur_id += step_size; | ||
211 | } | ||
212 | |||
213 | return cur_id; | ||
214 | } | ||
215 | |||
216 | //static | ||
217 | LLHUDIcon* LLHUDIcon::handlePick(S32 pick_id) | ||
218 | { | ||
219 | icon_instance_t::iterator icon_it; | ||
220 | |||
221 | for(icon_it = sIconInstances.begin(); icon_it != sIconInstances.end(); ++icon_it) | ||
222 | { | ||
223 | if (pick_id == (*icon_it)->mPickID) | ||
224 | { | ||
225 | return *icon_it; | ||
226 | } | ||
227 | } | ||
228 | |||
229 | return NULL; | ||
230 | } | ||
231 | |||
232 | //static | ||
233 | void LLHUDIcon::updateAll() | ||
234 | { | ||
235 | cleanupDeadIcons(); | ||
236 | } | ||
237 | |||
238 | //static | ||
239 | BOOL LLHUDIcon::iconsNearby() | ||
240 | { | ||
241 | return !sIconInstances.empty(); | ||
242 | } | ||
243 | |||
244 | //static | ||
245 | void LLHUDIcon::cleanupDeadIcons() | ||
246 | { | ||
247 | icon_instance_t::iterator icon_it; | ||
248 | |||
249 | icon_instance_t icons_to_erase; | ||
250 | for(icon_it = sIconInstances.begin(); icon_it != sIconInstances.end(); ++icon_it) | ||
251 | { | ||
252 | if ((*icon_it)->mDead) | ||
253 | { | ||
254 | icons_to_erase.push_back(*icon_it); | ||
255 | } | ||
256 | } | ||
257 | |||
258 | for(icon_it = icons_to_erase.begin(); icon_it != icons_to_erase.end(); ++icon_it) | ||
259 | { | ||
260 | icon_instance_t::iterator found_it = std::find(sIconInstances.begin(), sIconInstances.end(), *icon_it); | ||
261 | if (found_it != sIconInstances.end()) | ||
262 | { | ||
263 | sIconInstances.erase(found_it); | ||
264 | } | ||
265 | } | ||
266 | } | ||
267 | |||
268 | //static | ||
269 | S32 LLHUDIcon::getNumInstances() | ||
270 | { | ||
271 | return (S32)sIconInstances.size(); | ||
272 | } | ||