1 /*
2 This file is part of Caelum.
3 See http://www.ogre3d.org/wiki/index.php/Caelum
4 
5 Copyright (c) 2006-2008 Caelum team. See Contributors.txt for details.
6 
7 Caelum is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Caelum is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License
18 along with Caelum. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef CAELUM__CAELUM_SYSTEM_H
22 #define CAELUM__CAELUM_SYSTEM_H
23 
24 #include "CaelumPrerequisites.h"
25 #include "UniversalClock.h"
26 #include "ImageStarfield.h"
27 #include "PointStarfield.h"
28 #include "SkyLight.h"
29 #include "Sun.h"
30 #include "Moon.h"
31 #include "CloudSystem.h"
32 #include "SkyDome.h"
33 #include "DepthComposer.h"
34 #include "PrecipitationController.h"
35 #include "GroundFog.h"
36 #include "PrivatePtr.h"
37 
38 namespace Caelum
39 {
40     /** This is the "root class" of caelum.
41      *
42      *  This class is created once for one SceneManager and will render the sky
43      *  for that scene. CaelumSystem will be visible in all viewports on the
44      *  scene and must be notified when those viewports are created and
45      *  destroyed.
46      *
47      *  @par Components
48      *
49      *  %Caelum is built from several classes for different sky elements (the sun,
50      *  clouds, etc). Those classes know very little about each other and are
51      *  connected through this class. This class is responsible for tracking and
52      *  updating sub-components.
53      *
54      *  This class "owns" all of the subcomponents, using std::auto_ptr members.
55      *  When you call functions like setXxx(new Xxx()) this class takes
56      *  ownership of the object's lifetime and will try to update it as
57      *  appropriate. All components are optional; disable one component should
58      *  never cause a crash. When something is broken disabling components one
59      *  by one is a very good way to find the source of the problem.
60      *
61      *  The constructor can create a bunch of components with default settings
62      *  for you; based on the CaelumSystem::CaelumComponent flags passed.
63      *
64      *  @par Updating
65      *
66      *  This class is responsible for updating subcomponents. There are two
67      *  update functions which must be get called to keep CaelumSystem
68      *  functioning properly. One is per-frame and the other is per-camera.
69      *
70      *  CaelumSystem::updateSubcomponents must be called once per frame to
71      *  advance world time and tie components together. That function will
72      *  set certain properties on the subcomponents making up CaelumSystem
73      *  If you want to force some properties beyond what CaelumSystem does by
74      *  default you can do that AFTER the call to updateSubcompoments. For
75      *  example you can override the moon's phase by calling Moon::setPhase.
76      *
77      *  CaelumSystem::notifyCameraChanged must be called for each camera
78      *  before rendering with that camera. All viewport tweaks and camera
79      *  movement must be done BEFORE calling this function. This method will
80      *  recenter Caelum's domes on the camera. Also, some subcomponents
81      *  can actually depend on field-of-view and viewport resolution (like
82      *  PointStarfield).
83      *
84      *  You can register CaelumSystem as an Ogre::FrameListener and
85      *  updateSubcomponents will be automatically called inside Ogre's
86      *  rendering loop (inside frameStarted). If you want more control you
87      *  should call updateSubcomponents in your own main loop. That way you
88      *  can avoid potential issues with the ordering of multiple FrameListeners.
89      *
90      *  You can register CaelumSystem as an Ogre::RenderTargetListener and
91      *  notifyCameraChanged will be automatically called inside
92      *  preViewportUpdate. That behaviour can be disabled with
93      *  setAutoNotifyCameraChanged(false). It is recommended that you
94      *  call notifyCameraChanged manually before updating viewports.
95      *
96      *  RenderTargetListener::preViewportUpdate does not work as expected
97      *  when compositors are involved (those inside Caelum or external).
98      *  Compositors plug into preRenderTargetUpdate and render the scene to a
99      *  texture BEFORE preViewportUpdate; this means that notifyCameraChanged
100      *  will execute before the final compositor pass but after actual scene
101      *  rendering.
102      *
103      *  If notifyCameraChanged is not called correctly the most likely result
104      *  is "flickering" when moving the camera. If you move the camera AFTER
105      *  notifyCameraChanged then the domes will not be positioned correctly
106      *  and will appear to lag slightly after the camera. Since updates are
107      *  always done every frame keeping the camera still will make problems
108      *  disappear.
109      *
110      *  If you notice z-buffer issues while the camera is still update order
111      *  is probably not the cause.
112      */
113     class CAELUM_EXPORT CaelumSystem:
114             public Ogre::FrameListener,
115             public Ogre::RenderTargetListener
116     {
117 	private:
118 		/// Root of the Ogre engine.
119 		Ogre::Root *mOgreRoot;
120 
121 		/// Scene manager.
122 		Ogre::SceneManager *mSceneMgr;
123 
124         /// Caelum scene node for camera-bound elements (most).
125 		PrivateSceneNodePtr mCaelumCameraNode;
126 
127         /// Caelum scene node for ground-bound elements (only clouds currently).
128 		PrivateSceneNodePtr mCaelumGroundNode;
129 
130 		/// Cleanup requested flag.
131 		bool mCleanup;
132 
133         /// Automatically move the camera node.
134         bool mAutoMoveCameraNode;
135 
136         /// Automatically call this->notifyCameraChanged.
137         bool mAutoNotifyCameraChanged;
138 
139         /// Automatically attach compositors to viewports
140         bool mAutoAttachViewportsToComponents;
141 
142         /// Automatically set the viewport colour to black.
143         bool mAutoViewportBackground;
144 
145         /// Fog Mode caelum should use
146 		Ogre::FogMode mManageSceneFogMode;
147 
148 		/// Distances for linear fog mode
149 		Ogre::Real    mManageSceneFogFromDistance, mManageSceneFogToDistance;
150 
151         Real mGlobalFogDensityMultiplier;
152         Ogre::ColourValue mGlobalFogColourMultiplier;
153 
154         Real mSceneFogDensityMultiplier;
155         Ogre::ColourValue mSceneFogColourMultiplier;
156 
157         Real mGroundFogDensityMultiplier;
158         Ogre::ColourValue mGroundFogColourMultiplier;
159 
160         /// Flag for managing scene ambient light.
161 		bool mManageAmbientLight;
162 
163         /// Minimum ambient light; only useful if mManageAmbientLight
164         Ogre::ColourValue mMinimumAmbientLight;
165 
166         /// If only one light source should enabled at a time.
167         bool mEnsureSingleLightSource;
168 
169         /// Ensure only one of the light sources casts shadows.
170         bool mEnsureSingleShadowSource;
171 
172 		/// The sky gradients image (for lookups).
173         std::auto_ptr<Ogre::Image> mSkyGradientsImage;
174 
175         /// The sun gradients image (for lookups).
176         std::auto_ptr<Ogre::Image> mSunColoursImage;
177 
178         /// Observer Latitude (on the earth).
179         Ogre::Degree mObserverLatitude;
180         /// Observer Longitude (on the earth).
181         Ogre::Degree mObserverLongitude;
182 
183         static const Ogre::Vector3 makeDirection (
184                 Ogre::Degree azimuth, Ogre::Degree altitude);
185 
186 		// References to sub-components
187         std::auto_ptr<UniversalClock> mUniversalClock;
188         std::auto_ptr<SkyDome> mSkyDome;
189         std::auto_ptr<BaseSkyLight> mSun;
190         std::auto_ptr<Moon> mMoon;
191         std::auto_ptr<ImageStarfield> mImageStarfield;
192         std::auto_ptr<PointStarfield> mPointStarfield;
193         std::auto_ptr<GroundFog> mGroundFog;
194         std::auto_ptr<CloudSystem> mCloudSystem;
195 		std::auto_ptr<PrecipitationController> mPrecipitationController;
196 		std::auto_ptr<DepthComposer> mDepthComposer;
197 
198     public:
199         typedef std::set<Ogre::Viewport*> AttachedViewportSet;
200 
201     private:
202         AttachedViewportSet mAttachedViewports;
203 
204 	public:
205         /** Flags enumeration for caelum components.
206          *  This is an enumeration for the components to create by default in
207          *  Caelum's constructor. You can still pass 0 and create everything
208          *  by hand.
209          *
210          *  CaelumSystem's constructor used to take a number of bools but now
211          *  there are too many components and this is nicer.
212          *
213          *  CAELUM_COMPONENT_ members are for individual components.
214          *  CAELUM_COMPONENTS_ are standard bitmasks.
215          *  CAELUM_COMPONENTS_DEFAULT picks elements that don't require
216          *  modifications to external materials (right now it excludes ground fog).
217          */
218         enum CaelumComponent
219         {
220             CAELUM_COMPONENT_SKY_DOME           = 1 << 1,
221             CAELUM_COMPONENT_MOON				= 1 << 3,
222             CAELUM_COMPONENT_SUN                = 1 << 4,
223             CAELUM_COMPONENT_IMAGE_STARFIELD    = 1 << 5,
224             CAELUM_COMPONENT_POINT_STARFIELD    = 1 << 6,
225             CAELUM_COMPONENT_CLOUDS             = 1 << 7,
226             CAELUM_COMPONENT_PRECIPITATION      = 1 << 8,
227             CAELUM_COMPONENT_SCREEN_SPACE_FOG   = 1 << 9,
228 
229             // This has nasty dependencies on materials.
230             CAELUM_COMPONENT_GROUND_FOG         = 1 << (16 + 0),
231 
232             // Groups
233             CAELUM_COMPONENTS_NONE              = 0,
234             CAELUM_COMPONENTS_DEFAULT           = 0
235                     | CAELUM_COMPONENT_SKY_DOME
236                     | CAELUM_COMPONENT_MOON
237                     | CAELUM_COMPONENT_SUN
238                     | CAELUM_COMPONENT_POINT_STARFIELD
239                     | CAELUM_COMPONENT_CLOUDS,
240             CAELUM_COMPONENTS_ALL               = 0
241                     | CAELUM_COMPONENTS_DEFAULT
242                     | CAELUM_COMPONENT_PRECIPITATION
243                     | CAELUM_COMPONENT_SCREEN_SPACE_FOG
244                     | CAELUM_COMPONENT_GROUND_FOG,
245         };
246 
247         static const String DEFAULT_SKY_GRADIENTS_IMAGE;
248         static const String DEFAULT_SUN_COLOURS_IMAGE;
249 
250 		/** Constructor.
251 		 *  Registers itself in the Ogre engine and initialises the system.
252          *
253          *  @param root The Ogre root.
254 		 *  @param scene The Ogre scene manager.
255 		 *  @param componentsToCreate Default components for @see autoConfigure.
256 		 */
257 		CaelumSystem (
258                 Ogre::Root *root,
259 				Ogre::SceneManager *sceneMgr,
260                 CaelumComponent componentsToCreate);
261 
262         /** Revert everything to defaults.
263          *
264          *  This function will delete all subcomponents and revert everything
265          *  to default values (the values which are also set on construction).
266          */
267         void clear ();
268 
269         /** Create some default component with resonable default settings.
270          *  This results in a slightly cloudy morning sky.
271          *  This will always call clear() before creating components.
272          *  autoConfigure (0); is equivalent to clear();
273          */
274         void autoConfigure (
275                 CaelumComponent componentsToCreate);
276 
277 		/** Destructor.
278 		 */
279 		~CaelumSystem ();
280 
281 		/** Shuts down the system and detaches itself from the Ogre engine.
282          *
283          *  shutdown(true) is equivalent to deleting CaelumSystem yourself.
284          *  shutdown(false) delays destruction to the next time caelum is called as
285          *  a frame listener. This makes it safe to shutdown Caelum from inside
286          *  another frame listener.
287          *
288          *  @param cleanup If this is true then detach and destroy the CaelumSystem instantly.
289 		 */
290 		void shutdown (bool cleanup);
291 
292         /** Update the whole system manually.
293          *  You have to call this yourself if you don't register CaelumSystem
294          *  as an ogre frame listener. Otherwise it's called automatically.
295          *
296          *  @param timeSinceLastFrame: Time passed since last frame.
297          */
298         void updateSubcomponents (Real timeSinceLastFrame);
299 
300         /** Notify subcomponents of camera changes.
301          *  This function must be called after camera changes but before
302          *  rendering with that camera. If multiple cameras are used it must
303          *  be called for each camera before the camera is rendered with.
304          *
305          *  This function will move caelum's camera node to the camera
306          *  position, but only if getAutoMoveCameraNode.
307          *  It will also call CameraBoundElement::notifyCameraChanged
308          */
309         void notifyCameraChanged(Ogre::Camera* cam);
310 
311         /** Get the scene manager for this caelum system.
312          *  This is set in the constructor. CaelumSystem can't exist without a valid scene manager.
313          */
getSceneMgr()314         inline Ogre::SceneManager* getSceneMgr() const { return mSceneMgr; }
315 
316 		/// Gets root scene node for camera-bound elements
getCaelumCameraNode(void)317         inline Ogre::SceneNode* getCaelumCameraNode(void) const { return mCaelumCameraNode.get(); }
318 
319 		/// Gets root scene node for ground-bound elements.
getCaelumGroundNode(void)320         inline Ogre::SceneNode* getCaelumGroundNode(void) const { return mCaelumGroundNode.get(); }
321 
322         /** If true; listen to preViewportUpdate and automatically notifyCameraChanged();
323          *
324          *  This is on by default; but does not work with compositors.
325          *
326          *  You must attach CaelumSystem as a RenderTargetListener manually for
327          *  this to work; as in version 0.3.
328          */
setAutoNotifyCameraChanged(bool value)329         inline void setAutoNotifyCameraChanged(bool value) { mAutoNotifyCameraChanged = value; }
330         /// @see setAutoNotifyCameraChanged
getAutoNotifyCameraChanged()331         inline bool getAutoNotifyCameraChanged() const { return mAutoNotifyCameraChanged; }
332 
333         /** If true; automatically attach viewports to subcomponents.
334          *
335          *  Some subcomponents use compositors and those compositors need to
336          *  be attached to individual viewports. By default CaelumSystem will
337          *  try take to take care of that automatically.
338          *
339          *  This property allows you to disable that behaviour. If set to false
340          *  you must call functions like
341          *  PrecipitationController::createViewportInstance manually.
342          *
343          *  @see attachViewport detachViewport
344          */
setAutoAttachViewportsToComponents(bool value)345         inline void setAutoAttachViewportsToComponents(bool value) { mAutoAttachViewportsToComponents = value; }
346         /// @see setAutoAttachViewportsToComponents.
getAutoAttachViewportsToComponents()347         inline bool getAutoAttachViewportsToComponents() const { return mAutoAttachViewportsToComponents; }
348 
349         /** If true (default); automatically move the camera node in notifyCameraChanged.
350          *  If disable you get full control of the camera node; and in theory
351          *  you can attach it to the scene graph however you please.
352          */
setAutoMoveCameraNode(bool value)353         inline void setAutoMoveCameraNode(bool value) { mAutoMoveCameraNode = value; }
354         /// @see setAutoMoveCameraNode
getAutoMoveCameraNode()355         inline bool getAutoMoveCameraNode() { return mAutoMoveCameraNode; }
356 
357         /** If true; automatically set the viewport color to black.
358          *  Caelum's domes relies on the viewport background being black.
359          *  There's generally no reason to disable this and it's on by default.
360          */
setAutoViewportBackground(bool value)361         inline void setAutoViewportBackground(bool value) { mAutoViewportBackground = value; }
362         /// @see setAutoViewportBackground
getAutoViewportBackground()363         inline bool getAutoViewportBackground() const { return mAutoViewportBackground; }
364 
365         /// Get the observer's longitude. East is positive, west is negative.
getObserverLongitude()366         inline const Ogre::Degree getObserverLongitude () const { return mObserverLongitude; }
367 
368         /// Set the observer's longitude. East is positive, west is negative.
setObserverLongitude(Ogre::Degree value)369         inline void setObserverLongitude (Ogre::Degree value) { mObserverLongitude = value; }
370 
371         /// Get the observer's latitude. North is positive, south is negative.
getObserverLatitude()372         inline const Ogre::Degree getObserverLatitude () const { return mObserverLatitude; }
373 
374         /// Set the observer's latitude. North is positive, south is negative.
setObserverLatitude(Ogre::Degree value)375         inline void setObserverLatitude (Ogre::Degree value) { mObserverLatitude = value; }
376 
getJulianDay()377         inline LongReal getJulianDay () const { return mUniversalClock->getJulianDay (); }
setJulianDay(LongReal value)378         inline void setJulianDay (LongReal value) { mUniversalClock->setJulianDay (value); }
getTimeScale()379         inline Real getTimeScale () const { return mUniversalClock->getTimeScale (); }
setTimeScale(Real value)380         inline void setTimeScale (Real value) { mUniversalClock->setTimeScale (value); }
381 
382     public:
383         /** Attach CaelumSystem to a viewport.
384          *  You should call this for every new viewport looking at the scene
385          *  where CaelumSystem is created.
386          *
387          *  If the viewport is already attached then nothing happens.
388          *
389          *  If getAutoAttachViewportsToComponents() this will add Caelum's compositors.
390          */
391 		void attachViewport (Ogre::Viewport* rt);
392 
393         /** Reverse of @see attachViewport.
394          *  You need to call this when you destroy a viewport.
395          *
396          *  If the viewport is not already attached nothing happens.
397          */
398 		void detachViewport (Ogre::Viewport* rt);
399 
400         /** Check if one particular viewport is attached.
401          */
402         bool isViewportAttached (Ogre::Viewport* vp) const;
403 
404         /** Detach from all viewports.
405          */
406         void detachAllViewports ();
407 
408         /// Get a reference to the set of attached viewports.
_getAttachedViewportSet()409         const AttachedViewportSet& _getAttachedViewportSet () { return mAttachedViewports; }
410 
411     protected:
412         // Do the work behind attach/detach viewport.
413 		void attachViewportImpl (Ogre::Viewport* rt);
414 		void detachViewportImpl (Ogre::Viewport* rt);
415 
416     public:
417 		/// Gets the universal clock.
getUniversalClock()418         inline UniversalClock *getUniversalClock () const { return mUniversalClock.get(); }
419 
420 		/// Get the current sky dome, or null if disabled.
getSkyDome()421         inline SkyDome* getSkyDome () const { return mSkyDome.get (); }
422 		/// Set the skydome, or null to disable.
423         void setSkyDome (SkyDome *obj);
424 
425 		/// Gets the current sun, or null if disabled.
getSun()426         inline BaseSkyLight* getSun () const { return mSun.get (); }
427 		/// Set the sun, or null to disable.
428 		void setSun (BaseSkyLight* obj);
429 
430 		/// Gets the current moon, or null if disabled.
getMoon()431         inline Moon* getMoon () const { return mMoon.get (); }
432 		/// Set the moon, or null to disable.
433 		void setMoon (Moon* obj);
434 
435 		/// Gets the current image starfield, or null if disabled.
getImageStarfield()436         inline ImageStarfield* getImageStarfield () const { return mImageStarfield.get (); }
437 		/// Set image starfield, or null to disable.
438         void setImageStarfield (ImageStarfield* obj);
439 
440 		/// Gets the current point starfield, or null if disabled.
getPointStarfield()441         inline PointStarfield* getPointStarfield () const { return mPointStarfield.get (); }
442 		/// Set image starfield, or null to disable.
443         void setPointStarfield (PointStarfield* obj);
444 
445 		/// Get ground fog; if enabled.
getGroundFog()446         inline GroundFog* getGroundFog () { return mGroundFog.get (); }
447 		/// Sets ground fog system, or null to disable.
448         void setGroundFog (GroundFog *obj);
449 
450         /// Get cloud system; or null if disabled.
getCloudSystem()451         inline CloudSystem* getCloudSystem () { return mCloudSystem.get (); }
452         /// Set cloud system; or null to disable.
453         void setCloudSystem (CloudSystem *obj);
454 
455         /// Get precipitation controller; or null if disabled.
getPrecipitationController()456 		inline PrecipitationController* getPrecipitationController () { return mPrecipitationController.get (); }
457         /// Set precipitation controller; or null to disable.
458 		void setPrecipitationController (PrecipitationController *obj);
459 
460         /// Get depth composer; or null if disabled.
getDepthComposer()461 		inline DepthComposer* getDepthComposer () { return mDepthComposer.get (); }
462         /// Set depth composer; or null to disable.
463 		void setDepthComposer (DepthComposer *obj);
464 
465 		/** Enables/disables Caelum managing standard Ogre::Scene fog.
466             This makes CaelumSystem control standard Ogre::Scene fogging. It
467             will use EXP2 fog with density from SkyColourModel.
468 
469             Fog density multipliers are used; final scene fog density is:
470             SceneMultiplier * GlobalMultiplier * SkyColourModel.GetFogDensity
471 
472             When this is set to false it also disables all scene fog (but you
473             control it afterwards).
474 
475             @param value New value
476 		 */
477 		void setManageSceneFog (Ogre::FogMode f);
478 		void disableFogMangement();
479 
480 		/** Tells if Caelum is managing the fog or not.
481 			@return The value set in setManageSceneFog.
482 		 */
483 		Ogre::FogMode getManageSceneFog () const;
484 
485 		void setManageSceneFogStart (Ogre::Real from);
486 		void setManageSceneFogEnd (Ogre::Real to);
487 		Ogre::Real getManageSceneFogStart() const;
488 		Ogre::Real getManageSceneFogEnd() const;
489 
490         /** Multiplier for scene fog density (default 1).
491             This is an additional multiplier for Ogre::Scene fog density.
492             This has no effect if getManageSceneFog is false.
493 
494             Final scene fog density is:
495             SceneMultiplier * GlobalMultiplier * SkyColourModel.GetFogDensity
496          */
497         void setSceneFogDensityMultiplier (Real value);
498 
499         /** Get the value set by setSceneFogDensityMultiplier.
500          */
501         Real getSceneFogDensityMultiplier () const;
502 
503         /** Set an additional multiplier for fog colour as it comes from SkyColourModel.
504          *  This is 0.7 by default; to be compatible with previous versions.
505          */
setSceneFogColourMultiplier(const Ogre::ColourValue & value)506         inline void setSceneFogColourMultiplier (const Ogre::ColourValue& value) { mSceneFogColourMultiplier = value; }
507 
508         /// See setSceneFogColourMultiplier.
getSceneFogColourMultiplier()509         inline const Ogre::ColourValue getSceneFogColourMultiplier () const { return mSceneFogColourMultiplier; }
510 
511         /** Multiplier for ground fog density (default 1).
512          *  This is an additional multiplier for Caelum::GroundFog DepthComposer ground fog density.
513          *
514          *  Final ground fog density is:
515          *  GroundFogMultipler * GlobalMultiplier * SkyColourModel.GetFogDensity
516          */
517         void setGroundFogDensityMultiplier (Real value);
518 
519         /** Get the value set by setGroundFogDensityMultiplier.
520          */
521         Real getGroundFogDensityMultiplier () const;
522 
523         /** Set an additional multiplier for ground fog colour as it comes from SkyColourModel.
524          *  This is OgreColour::White by default; which has no effect.
525          */
setGroundFogColourMultiplier(const Ogre::ColourValue & value)526         inline void setGroundFogColourMultiplier (const Ogre::ColourValue& value) { mGroundFogColourMultiplier = value; }
527 
528         /// See setGroundFogColourMultiplier.
getGroundFogColourMultiplier()529         inline const Ogre::ColourValue getGroundFogColourMultiplier () const { return mGroundFogColourMultiplier; }
530 
531         /** Multiplier for global fog density (default 1).
532          *  This is an additional multiplier for fog density as received from
533          *  SkyColourModel. There are other multipliers you can tweak for
534          *  individual kinds of fog; but this is what you should change from
535          *  whatever "game logic" you might have.
536          */
537         void setGlobalFogDensityMultiplier (Real value);
538 
539         /** Get the value set by setSceneFogDensityMultiplier.
540          */
541         Real getGlobalFogDensityMultiplier () const;
542 
543         /** Set an additional multiplier for fog colour.
544          *  This will also affect stuff like clouds or precipitation. Careful!
545          *  This is OgreColour::White by default; which has no effect.
546          */
setGlobalFogColourMultiplier(const Ogre::ColourValue & value)547         inline void setGlobalFogColourMultiplier (const Ogre::ColourValue& value) { mGlobalFogColourMultiplier = value; }
548 
549         /// See setGlobalFogColourMultiplier.
getGlobalFogColourMultiplier()550         inline const Ogre::ColourValue getGlobalFogColourMultiplier () const { return mGlobalFogColourMultiplier; }
551 
552         /** Set this to true to have CaelumSystem manage the scene's ambient light.
553          *  The colour and AmbientMultiplier of the sun and moon are used.
554          *  This is false by default.
555          */
setManageAmbientLight(bool value)556         inline void setManageAmbientLight (bool value) { mManageAmbientLight = value; }
557 
558         /// Check if CaelumSystem is managing ambient lighting.
getManageAmbientLight()559         inline bool getManageAmbientLight () const { return mManageAmbientLight; }
560 
561         /** Set the minimum value for scene ambient lighting,
562          *  This is only used if getManageAmbientLight() is true.
563          *  By default this value is Ogre::ColourValue::Black, so it has no effect.
564          */
setMinimumAmbientLight(const Ogre::ColourValue & value)565         inline void setMinimumAmbientLight (const Ogre::ColourValue &value) { mMinimumAmbientLight = value; }
566 
567         /// @see setMinimumAmbientLight
getMinimumAmbientLight()568         inline const Ogre::ColourValue getMinimumAmbientLight () const { return mMinimumAmbientLight; }
569 
570         /** Ensure only one of caelum's light sources is active at a time (the brightest).
571          *  This uses SkyLight::setForceDisable to disable low-intensity lightsources.
572          *  Their contribution to ambient lighting is not affected.
573          *  This implies a single shadow caster.
574          *  This is disabled by default; and you can tweak light disabling by yourself.
575          */
setEnsureSingleLightSource(bool value)576         inline void setEnsureSingleLightSource (bool value) { mEnsureSingleLightSource = value; }
577 
578         /// See setEnsureSingleLightSource
getEnsureSingleLightSource()579         inline bool getEnsureSingleLightSource () const { return mEnsureSingleLightSource; }
580 
581         /** Ensure only one of caelum's light sources casts shadows (the brightest).
582          *  Disabled by default.
583          */
setEnsureSingleShadowSource(bool value)584         inline void setEnsureSingleShadowSource (bool value) { mEnsureSingleShadowSource = value; }
585 
586         /// See setEnsureSingleShadowSource
getEnsureSingleShadowSource()587         inline bool getEnsureSingleShadowSource () const { return mEnsureSingleShadowSource; }
588 
589 		/** Gets the fog colour for a certain daytime.
590 			@param time The current time.
591 			@param sunDir The sun direction.
592 			@return The fog colour.
593 		 */
594 		Ogre::ColourValue getFogColour (Real time, const Ogre::Vector3 &sunDir);
595 
596 		/** Gets the fog density for a certain daytime.
597 			@param time The current time.
598 			@param sunDir The sun direction.
599 			@return The fog density.
600 		 */
601 		Real getFogDensity (Real time, const Ogre::Vector3 &sunDir);
602 
603 		/** Get the colour of the sun sphere.
604          *  This colour is used to draw the sun sphere in the sky.
605 		 *  @return The colour of the sun.
606 		 */
607 		Ogre::ColourValue getSunSphereColour (Real time, const Ogre::Vector3 &sunDir);
608 
609 		/** Gets the colour of sun light.
610          *  This color is used to illuminate the scene.
611          *  @return The colour of the sun's light
612 		 */
613 		Ogre::ColourValue getSunLightColour (Real time, const Ogre::Vector3 &sunDir);
614 
615 		/// Gets the colour of moon's body.
616 		Ogre::ColourValue getMoonBodyColour (const Ogre::Vector3 &moonDir);
617 
618 		/// Gets the colour of moon's light.
619 		Ogre::ColourValue getMoonLightColour (const Ogre::Vector3 &moonDir);
620 
621 		/// Set the sun gradients image.
622 		void setSkyGradientsImage (const Ogre::String &filename = DEFAULT_SKY_GRADIENTS_IMAGE);
623 
624 		/// Set the sun colours image.
625 		/// Sun colour is taken from this image.
626 		void setSunColoursImage (const Ogre::String &filename = DEFAULT_SUN_COLOURS_IMAGE);
627 
628 		/** Get the sun's direction at a certain time.
629          *  @param jday astronomical julian day.
630          *  @see UniversalClock for julian day calculations.
631 		 */
632 		const Ogre::Vector3 getSunDirection (LongReal jday);
633 
634 		/** Get the moon's direction at a certain time.
635          *  @param jday astronomical julian day.
636 		 */
637 		const Ogre::Vector3 getMoonDirection (LongReal jday);
638 
639         /** Function to get the phase of the moon
640          *  @param jday Julian day
641          *  @return the phase of the moon; ranging from 0(full moon) to 1(again full moon).
642          */
643 		const Ogre::Real getMoonPhase (LongReal jday);
644 
645 		/** Get the ecliptic's north pole direction at a certain time.
646 		 *  Useful as Moon's north polar axis points within 1.5 degrees of the north ecliptic pole.
647          *  @param jday astronomical julian day.
648 		 */
649 		const Ogre::Vector3 getEclipticNorthPoleDirection (LongReal jday);
650 
651     private:
652 		/** Handle FrameListener::frameStarted to call updateSubcomponents every frame.
653          *  If you don't register CaelumSystem as a an ogre frame listener you have to
654          *  call updateSubcomponents yourself.
655 		 */
656 		virtual bool frameStarted (const Ogre::FrameEvent &e);
657 
658 		/** Event trigger called just before rendering a viewport in a render target Caelum is attached to.
659 			Useful to make objects follow every camera that renders a viewport in a certain render target.
660 		 */
661 		virtual void preViewportUpdate (const Ogre::RenderTargetViewportEvent &e);
662 
663         /** Free all subcomponents, but not CaelumSystem itself. Can be called multiple times.
664          *  @param everything To destroy things that can't be rebuilt.
665          */
666         void destroySubcomponents (bool everything);
667 
668     public:
669         /** Call setQueryFlags for all subcomponents now.
670          *
671          *  This is not persistent; you can adjust the query masks of
672          *  individual objects afterwards. This also means you should call
673          *  this only after you created all other objects.
674          *
675          *  Has no effect on compositor-based stuff (precipitation will still show up).
676          */
677         void forceSubcomponentQueryFlags (uint mask);
678 
679         /** Same as @see forceSubcomponentQueryMask; but for visibility
680          */
681         void forceSubcomponentVisibilityFlags (uint mask);
682     };
683 }
684 
685 #endif // CAELUM__CAELUM_SYSTEM_H
686