aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llsky.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llsky.cpp
parentREADME.txt (diff)
downloadmeta-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/llsky.cpp')
-rw-r--r--linden/indra/newview/llsky.cpp446
1 files changed, 446 insertions, 0 deletions
diff --git a/linden/indra/newview/llsky.cpp b/linden/indra/newview/llsky.cpp
new file mode 100644
index 0000000..f4e305c
--- /dev/null
+++ b/linden/indra/newview/llsky.cpp
@@ -0,0 +1,446 @@
1/**
2 * @file llsky.cpp
3 * @brief IndraWorld sky class
4 *
5 * Copyright (c) 2000-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// Ideas:
29// -haze should be controlled by global query from sims
30// -need secondary optical effects on sun (flare)
31// -stars should be brought down from sims
32// -star intensity should be driven by global ambient level from sims,
33// so that eclipses, etc can be easily done.
34//
35
36#include "llviewerprecompiledheaders.h"
37
38#include "llsky.h"
39
40// linden library includes
41#include "llerror.h"
42#include "llmath.h"
43#include "math.h"
44#include "v4color.h"
45
46#include "llviewerobjectlist.h"
47#include "llviewerobject.h"
48#include "llviewercamera.h"
49#include "pipeline.h"
50#include "llagent.h"
51#include "lldrawpool.h"
52
53#include "llvosky.h"
54#include "llvostars.h"
55#include "llcubemap.h"
56#include "llviewercontrol.h"
57
58extern LLPipeline gPipeline;
59
60F32 azimuth_from_vector(const LLVector3 &v);
61F32 elevation_from_vector(const LLVector3 &v);
62
63// ---------------- LLSky ----------------
64
65//////////////////////////////////////////////////////////////////////
66// Construction/Destruction
67//////////////////////////////////////////////////////////////////////
68
69LLSky::LLSky()
70{
71 // Set initial clear color to black
72 // Set fog color
73 mFogColor.mV[VRED] = mFogColor.mV[VGREEN] = mFogColor.mV[VBLUE] = 0.5f;
74 mFogColor.mV[VALPHA] = 0.0f;
75
76 mLightingGeneration = 0;
77 mUpdatedThisFrame = TRUE;
78 mOverrideSimSunPosition = FALSE;
79 mSunPhase = 0.f;
80}
81
82
83LLSky::~LLSky()
84{
85}
86
87void LLSky::cleanup()
88{
89 mVOSkyp = NULL;
90 mVOStarsp = NULL;
91 mVOGroundp = NULL;
92}
93
94void LLSky::destroyGL()
95{
96 if (!mVOSkyp.isNull() && mVOSkyp->getCubeMap())
97 {
98 mVOSkyp->cleanupGL();
99 }
100}
101
102void LLSky::restoreGL()
103{
104 if (mVOSkyp)
105 {
106 mVOSkyp->restoreGL();
107 }
108}
109
110void LLSky::setOverrideSun(BOOL override)
111{
112 if (!mOverrideSimSunPosition && override)
113 {
114 mLastSunDirection = getSunDirection();
115 }
116 else if (mOverrideSimSunPosition && !override)
117 {
118 setSunDirection(mLastSunDirection, LLVector3::zero);
119 }
120 mOverrideSimSunPosition = override;
121}
122
123void LLSky::setSunDirection(const LLVector3 &sun_direction, const LLVector3 &sun_ang_velocity)
124{
125 mVOSkyp->setSunDirection(sun_direction, sun_ang_velocity);
126}
127
128
129void LLSky::setSunTargetDirection(const LLVector3 &sun_direction, const LLVector3 &sun_ang_velocity)
130{
131 mSunTargDir = sun_direction;
132}
133
134
135LLVector3 LLSky::getSunDirection() const
136{
137 if (mVOSkyp)
138 {
139 return mVOSkyp->getToSun();
140 }
141 else
142 {
143 return LLVector3::z_axis;
144 }
145}
146
147
148LLVector3 LLSky::getMoonDirection() const
149{
150 if (mVOSkyp)
151 {
152 return mVOSkyp->getToMoon();
153 }
154 else
155 {
156 return LLVector3::z_axis;
157 }
158}
159
160
161LLColor4 LLSky::getSunDiffuseColor() const
162{
163 if (mVOSkyp)
164 {
165 return LLColor4(mVOSkyp->getSunDiffuseColor());
166 }
167 else
168 {
169 return LLColor4(1.f, 1.f, 1.f, 1.f);
170 }
171}
172
173
174LLColor4 LLSky::getMoonDiffuseColor() const
175{
176 if (mVOSkyp)
177 {
178 return LLColor4(mVOSkyp->getMoonDiffuseColor());
179 }
180 else
181 {
182 return LLColor4(1.f, 1.f, 1.f, 1.f);
183 }
184}
185
186
187LLColor4 LLSky::getTotalAmbientColor() const
188{
189 if (mVOSkyp)
190 {
191 return mVOSkyp->getTotalAmbientColor();
192 }
193 else
194 {
195 return LLColor4(1.f, 1.f, 1.f, 1.f);
196 }
197}
198
199
200BOOL LLSky::sunUp() const
201{
202 if (mVOSkyp)
203 {
204 return mVOSkyp->isSunUp();
205 }
206 else
207 {
208 return TRUE;
209 }
210}
211
212
213LLColor4 LLSky::calcInScatter(LLColor4& transp, const LLVector3 &point, F32 exag) const
214{
215 if (mVOSkyp)
216 {
217 return mVOSkyp->calcInScatter(transp, point, exag);
218 }
219 else
220 {
221 return LLColor4(1.f, 1.f, 1.f, 1.f);
222 }
223}
224
225
226LLColor4U LLSky::getFadeColor() const
227{
228 if (mVOSkyp)
229 {
230 return mVOSkyp->getFadeColor();
231 }
232 else
233 {
234 return LLColor4(1.f, 1.f, 1.f, 1.f);
235 }
236}
237
238
239//////////////////////////////////////////////////////////////////////
240// Public Methods
241//////////////////////////////////////////////////////////////////////
242
243
244void LLSky::init(const LLVector3 &sun_direction)
245{
246 mVOSkyp = (LLVOSky *)gObjectList.createObjectViewer(LLViewerObject::LL_VO_SKY, gAgent.getRegion());
247 mVOSkyp->initSunDirection(sun_direction, LLVector3());
248 gPipeline.addObject((LLViewerObject *)mVOSkyp);
249
250 mVOStarsp = (LLVOStars *)gObjectList.createObjectViewer(LLViewerObject::LL_VO_STARS, gAgent.getRegion());
251 gPipeline.addObject((LLViewerObject *)mVOStarsp);
252
253 mVOGroundp = (LLVOGround*)gObjectList.createObjectViewer(LLViewerObject::LL_VO_GROUND, gAgent.getRegion());
254 LLVOGround *groundp = mVOGroundp;
255 gPipeline.addObject((LLViewerObject *)groundp);
256
257 gSky.setFogRatio(gSavedSettings.getF32("RenderFogRatio"));
258
259 ////////////////////////////
260 //
261 // Legacy code, ignore
262 //
263 //
264
265 // Get the parameters.
266 mSunDefaultPosition = gSavedSettings.getVector3("SkySunDefaultPosition");
267
268
269 if (gSavedSettings.getBOOL("SkyOverrideSimSunPosition") || mOverrideSimSunPosition)
270 {
271 setSunDirection(mSunDefaultPosition, LLVector3(0.f, 0.f, 0.f));
272 }
273 else
274 {
275 setSunDirection(sun_direction, LLVector3(0.f, 0.f, 0.f));
276 }
277
278 mUpdatedThisFrame = TRUE;
279}
280
281
282void LLSky::setCloudDensityAtAgent(F32 cloud_density)
283{
284 if (mVOSkyp)
285 {
286 mVOSkyp->setCloudDensity(cloud_density);
287 }
288}
289
290
291void LLSky::setWind(const LLVector3& average_wind)
292{
293 if (mVOSkyp)
294 {
295 mVOSkyp->setWind(average_wind);
296 }
297}
298
299
300void LLSky::propagateHeavenlyBodies(F32 dt)
301{
302 if (!mOverrideSimSunPosition)
303 {
304 LLVector3 curr_dir = getSunDirection();
305 LLVector3 diff = mSunTargDir - curr_dir;
306 const F32 dist = diff.normVec();
307 if (dist > 0)
308 {
309 const F32 step = llmin (dist, 0.00005f);
310 //const F32 step = min (dist, 0.0001);
311 diff *= step;
312 curr_dir += diff;
313 curr_dir.normVec();
314 if (mVOSkyp)
315 {
316 mVOSkyp->setSunDirection(curr_dir, LLVector3());
317 }
318 }
319 }
320}
321
322F32 LLSky::getSunPhase() const
323{
324 return mSunPhase;
325}
326
327void LLSky::setSunPhase(const F32 phase)
328{
329 mSunPhase = phase;
330}
331
332//////////////////////////////////////////////////////////////////////
333// Private Methods
334//////////////////////////////////////////////////////////////////////
335
336
337LLColor4 LLSky::getFogColor() const
338{
339 if (mVOSkyp)
340 {
341 return mVOSkyp->getFogColor();
342 }
343
344 return LLColor4(1.f, 1.f, 1.f, 1.f);
345}
346
347
348void LLSky::updateFog(const F32 distance)
349{
350 if (mVOSkyp)
351 {
352 mVOSkyp->updateFog(distance);
353 }
354}
355
356void LLSky::updateCull()
357{
358 /*if (mVOSkyp.notNull() && mVOSkyp->mDrawable.notNull())
359 {
360 gPipeline.markVisible(mVOSkyp->mDrawable);
361 }
362 else
363 {
364 llinfos << "No sky drawable!" << llendl;
365 }*/
366
367 if (mVOStarsp.notNull() && mVOStarsp->mDrawable.notNull())
368 {
369 gPipeline.markVisible(mVOStarsp->mDrawable);
370 }
371 else
372 {
373 llinfos << "No stars drawable!" << llendl;
374 }
375
376 /*if (mVOGroundp.notNull() && mVOGroundp->mDrawable.notNull())
377 {
378 gPipeline.markVisible(mVOGroundp->mDrawable);
379 }*/
380}
381
382void LLSky::updateSky()
383{
384 if (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SKY))
385 {
386 return;
387 }
388 if (mVOSkyp)
389 {
390 mVOSkyp->updateSky();
391 }
392 if (mVOStarsp)
393 {
394 if (mVOStarsp->mDrawable)
395 {
396 gPipeline.markRebuild(mVOStarsp->mDrawable, LLDrawable::REBUILD_VOLUME, TRUE);
397 }
398 }
399}
400
401
402void LLSky::setFogRatio(const F32 fog_ratio)
403{
404 if (mVOSkyp)
405 {
406 mVOSkyp->setFogRatio(fog_ratio);
407 }
408}
409
410
411F32 LLSky::getFogRatio() const
412{
413 if (mVOSkyp)
414 {
415 return mVOSkyp->getFogRatio();
416 }
417 else
418 {
419 return 0.f;
420 }
421}
422
423
424// Returns angle (DEGREES) between the horizontal plane and "v",
425// where the angle is negative when v.mV[VZ] < 0.0f
426F32 elevation_from_vector(const LLVector3 &v)
427{
428 F32 elevation = 0.0f;
429 F32 xy_component = (F32) sqrt(v.mV[VX] * v.mV[VX] + v.mV[VY] * v.mV[VY]);
430 if (xy_component != 0.0f)
431 {
432 elevation = RAD_TO_DEG * (F32) atan(v.mV[VZ]/xy_component);
433 }
434 else
435 {
436 if (v.mV[VZ] > 0.f)
437 {
438 elevation = 90.f;
439 }
440 else
441 {
442 elevation = -90.f;
443 }
444 }
445 return elevation;
446}