Caelum
CaelumSystem.h
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 {
113  class CAELUM_EXPORT CaelumSystem:
114  public Ogre::FrameListener,
115  public Ogre::RenderTargetListener
116  {
117  private:
119  Ogre::Root *mOgreRoot;
120 
122  Ogre::SceneManager *mSceneMgr;
123 
125  PrivateSceneNodePtr mCaelumCameraNode;
126 
128  PrivateSceneNodePtr mCaelumGroundNode;
129 
131  bool mCleanup;
132 
134  bool mAutoMoveCameraNode;
135 
137  bool mAutoNotifyCameraChanged;
138 
140  bool mAutoAttachViewportsToComponents;
141 
143  bool mAutoViewportBackground;
144 
146  Ogre::FogMode mManageSceneFogMode;
147 
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 
161  bool mManageAmbientLight;
162 
164  Ogre::ColourValue mMinimumAmbientLight;
165 
167  bool mEnsureSingleLightSource;
168 
170  bool mEnsureSingleShadowSource;
171 
173  std::auto_ptr<Ogre::Image> mSkyGradientsImage;
174 
176  std::auto_ptr<Ogre::Image> mSunColoursImage;
177 
179  Ogre::Degree mObserverLatitude;
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:
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 
257  CaelumSystem (
258  Ogre::Root *root,
259  Ogre::SceneManager *sceneMgr,
260  CaelumComponent componentsToCreate);
261 
267  void clear ();
268 
274  void autoConfigure (
275  CaelumComponent componentsToCreate);
276 
279  ~CaelumSystem ();
280 
290  void shutdown (bool cleanup);
291 
298  void updateSubcomponents (Real timeSinceLastFrame);
299 
309  void notifyCameraChanged(Ogre::Camera* cam);
310 
314  inline Ogre::SceneManager* getSceneMgr() const { return mSceneMgr; }
315 
317  inline Ogre::SceneNode* getCaelumCameraNode(void) const { return mCaelumCameraNode.get(); }
318 
320  inline Ogre::SceneNode* getCaelumGroundNode(void) const { return mCaelumGroundNode.get(); }
321 
329  inline void setAutoNotifyCameraChanged(bool value) { mAutoNotifyCameraChanged = value; }
331  inline bool getAutoNotifyCameraChanged() const { return mAutoNotifyCameraChanged; }
332 
345  inline void setAutoAttachViewportsToComponents(bool value) { mAutoAttachViewportsToComponents = value; }
347  inline bool getAutoAttachViewportsToComponents() const { return mAutoAttachViewportsToComponents; }
348 
353  inline void setAutoMoveCameraNode(bool value) { mAutoMoveCameraNode = value; }
355  inline bool getAutoMoveCameraNode() { return mAutoMoveCameraNode; }
356 
361  inline void setAutoViewportBackground(bool value) { mAutoViewportBackground = value; }
363  inline bool getAutoViewportBackground() const { return mAutoViewportBackground; }
364 
366  inline const Ogre::Degree getObserverLongitude () const { return mObserverLongitude; }
367 
369  inline void setObserverLongitude (Ogre::Degree value) { mObserverLongitude = value; }
370 
372  inline const Ogre::Degree getObserverLatitude () const { return mObserverLatitude; }
373 
375  inline void setObserverLatitude (Ogre::Degree value) { mObserverLatitude = value; }
376 
377  inline LongReal getJulianDay () const { return mUniversalClock->getJulianDay (); }
378  inline void setJulianDay (LongReal value) { mUniversalClock->setJulianDay (value); }
379  inline Real getTimeScale () const { return mUniversalClock->getTimeScale (); }
380  inline void setTimeScale (Real value) { mUniversalClock->setTimeScale (value); }
381 
382  public:
391  void attachViewport (Ogre::Viewport* rt);
392 
398  void detachViewport (Ogre::Viewport* rt);
399 
402  bool isViewportAttached (Ogre::Viewport* vp) const;
403 
406  void detachAllViewports ();
407 
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:
418  inline UniversalClock *getUniversalClock () const { return mUniversalClock.get(); }
419 
421  inline SkyDome* getSkyDome () const { return mSkyDome.get (); }
423  void setSkyDome (SkyDome *obj);
424 
426  inline BaseSkyLight* getSun () const { return mSun.get (); }
428  void setSun (BaseSkyLight* obj);
429 
431  inline Moon* getMoon () const { return mMoon.get (); }
433  void setMoon (Moon* obj);
434 
436  inline ImageStarfield* getImageStarfield () const { return mImageStarfield.get (); }
438  void setImageStarfield (ImageStarfield* obj);
439 
441  inline PointStarfield* getPointStarfield () const { return mPointStarfield.get (); }
443  void setPointStarfield (PointStarfield* obj);
444 
446  inline GroundFog* getGroundFog () { return mGroundFog.get (); }
448  void setGroundFog (GroundFog *obj);
449 
451  inline CloudSystem* getCloudSystem () { return mCloudSystem.get (); }
453  void setCloudSystem (CloudSystem *obj);
454 
456  inline PrecipitationController* getPrecipitationController () { return mPrecipitationController.get (); }
458  void setPrecipitationController (PrecipitationController *obj);
459 
461  inline DepthComposer* getDepthComposer () { return mDepthComposer.get (); }
463  void setDepthComposer (DepthComposer *obj);
464 
477  void setManageSceneFog (Ogre::FogMode f);
478  void disableFogMangement();
479 
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 
497  void setSceneFogDensityMultiplier (Real value);
498 
501  Real getSceneFogDensityMultiplier () const;
502 
506  inline void setSceneFogColourMultiplier (const Ogre::ColourValue& value) { mSceneFogColourMultiplier = value; }
507 
509  inline const Ogre::ColourValue getSceneFogColourMultiplier () const { return mSceneFogColourMultiplier; }
510 
517  void setGroundFogDensityMultiplier (Real value);
518 
521  Real getGroundFogDensityMultiplier () const;
522 
526  inline void setGroundFogColourMultiplier (const Ogre::ColourValue& value) { mGroundFogColourMultiplier = value; }
527 
529  inline const Ogre::ColourValue getGroundFogColourMultiplier () const { return mGroundFogColourMultiplier; }
530 
537  void setGlobalFogDensityMultiplier (Real value);
538 
541  Real getGlobalFogDensityMultiplier () const;
542 
547  inline void setGlobalFogColourMultiplier (const Ogre::ColourValue& value) { mGlobalFogColourMultiplier = value; }
548 
550  inline const Ogre::ColourValue getGlobalFogColourMultiplier () const { return mGlobalFogColourMultiplier; }
551 
556  inline void setManageAmbientLight (bool value) { mManageAmbientLight = value; }
557 
559  inline bool getManageAmbientLight () const { return mManageAmbientLight; }
560 
565  inline void setMinimumAmbientLight (const Ogre::ColourValue &value) { mMinimumAmbientLight = value; }
566 
568  inline const Ogre::ColourValue getMinimumAmbientLight () const { return mMinimumAmbientLight; }
569 
576  inline void setEnsureSingleLightSource (bool value) { mEnsureSingleLightSource = value; }
577 
579  inline bool getEnsureSingleLightSource () const { return mEnsureSingleLightSource; }
580 
584  inline void setEnsureSingleShadowSource (bool value) { mEnsureSingleShadowSource = value; }
585 
587  inline bool getEnsureSingleShadowSource () const { return mEnsureSingleShadowSource; }
588 
594  Ogre::ColourValue getFogColour (Real time, const Ogre::Vector3 &sunDir);
595 
601  Real getFogDensity (Real time, const Ogre::Vector3 &sunDir);
602 
607  Ogre::ColourValue getSunSphereColour (Real time, const Ogre::Vector3 &sunDir);
608 
613  Ogre::ColourValue getSunLightColour (Real time, const Ogre::Vector3 &sunDir);
614 
616  Ogre::ColourValue getMoonBodyColour (const Ogre::Vector3 &moonDir);
617 
619  Ogre::ColourValue getMoonLightColour (const Ogre::Vector3 &moonDir);
620 
622  void setSkyGradientsImage (const Ogre::String &filename = DEFAULT_SKY_GRADIENTS_IMAGE);
623 
626  void setSunColoursImage (const Ogre::String &filename = DEFAULT_SUN_COLOURS_IMAGE);
627 
632  const Ogre::Vector3 getSunDirection (LongReal jday);
633 
637  const Ogre::Vector3 getMoonDirection (LongReal jday);
638 
643  const Ogre::Real getMoonPhase (LongReal jday);
644 
649  const Ogre::Vector3 getEclipticNorthPoleDirection (LongReal jday);
650 
651  private:
656  virtual bool frameStarted (const Ogre::FrameEvent &e);
657 
661  virtual void preViewportUpdate (const Ogre::RenderTargetViewportEvent &e);
662 
666  void destroySubcomponents (bool everything);
667 
668  public:
677  void forceSubcomponentQueryFlags (uint mask);
678 
681  void forceSubcomponentVisibilityFlags (uint mask);
682  };
683 }
684 
685 #endif // CAELUM__CAELUM_SYSTEM_H
Moon * getMoon() const
Gets the current moon, or null if disabled.
Definition: CaelumSystem.h:431
Image-based starfield class.
void setAutoAttachViewportsToComponents(bool value)
If true; automatically attach viewports to subcomponents.
Definition: CaelumSystem.h:345
void setAutoNotifyCameraChanged(bool value)
If true; listen to preViewportUpdate and automatically notifyCameraChanged();.
Definition: CaelumSystem.h:329
Compositor-based precipitation controller.
const AttachedViewportSet & _getAttachedViewportSet()
Get a reference to the set of attached viewports.
Definition: CaelumSystem.h:409
void setObserverLongitude(Ogre::Degree value)
Set the observer&#39;s longitude. East is positive, west is negative.
Definition: CaelumSystem.h:369
void setEnsureSingleShadowSource(bool value)
Ensure only one of caelum&#39;s light sources casts shadows (the brightest).
Definition: CaelumSystem.h:584
Ogre::SceneManager * getSceneMgr() const
Get the scene manager for this caelum system.
Definition: CaelumSystem.h:314
ImageStarfield * getImageStarfield() const
Gets the current image starfield, or null if disabled.
Definition: CaelumSystem.h:436
void setMinimumAmbientLight(const Ogre::ColourValue &value)
Set the minimum value for scene ambient lighting, This is only used if getManageAmbientLight() is tru...
Definition: CaelumSystem.h:565
const Ogre::ColourValue getGroundFogColourMultiplier() const
See setGroundFogColourMultiplier.
Definition: CaelumSystem.h:529
Compositor-based precipitation controller.
Definition: DepthComposer.h:35
void setAutoMoveCameraNode(bool value)
If true (default); automatically move the camera node in notifyCameraChanged.
Definition: CaelumSystem.h:353
Ogre::SceneNode * getCaelumGroundNode(void) const
Gets root scene node for ground-bound elements.
Definition: CaelumSystem.h:320
const Ogre::ColourValue getGlobalFogColourMultiplier() const
See setGlobalFogColourMultiplier.
Definition: CaelumSystem.h:550
A sky dome element.
Definition: SkyDome.h:33
BaseSkyLight * getSun() const
Gets the current sun, or null if disabled.
Definition: CaelumSystem.h:426
Base class for sky lights (sun and moon).
Definition: SkyLight.h:31
bool getManageAmbientLight() const
Check if CaelumSystem is managing ambient lighting.
Definition: CaelumSystem.h:559
void setGroundFogColourMultiplier(const Ogre::ColourValue &value)
Set an additional multiplier for ground fog colour as it comes from SkyColourModel.
Definition: CaelumSystem.h:526
PrecipitationController * getPrecipitationController()
Get precipitation controller; or null if disabled.
Definition: CaelumSystem.h:456
void setSceneFogColourMultiplier(const Ogre::ColourValue &value)
Set an additional multiplier for fog colour as it comes from SkyColourModel.
Definition: CaelumSystem.h:506
void setObserverLatitude(Ogre::Degree value)
Set the observer&#39;s latitude. North is positive, south is negative.
Definition: CaelumSystem.h:375
PointStarfield * getPointStarfield() const
Gets the current point starfield, or null if disabled.
Definition: CaelumSystem.h:441
Point starfield class.
Exponential ground fog system implementation.
Definition: GroundFog.h:47
const Ogre::Degree getObserverLatitude() const
Get the observer&#39;s latitude. North is positive, south is negative.
Definition: CaelumSystem.h:372
CloudSystem * getCloudSystem()
Get cloud system; or null if disabled.
Definition: CaelumSystem.h:451
const Ogre::ColourValue getMinimumAmbientLight() const
Definition: CaelumSystem.h:568
void setGlobalFogColourMultiplier(const Ogre::ColourValue &value)
Set an additional multiplier for fog colour.
Definition: CaelumSystem.h:547
The system&#39;s time model.
This is the "root class" of caelum.
Definition: CaelumSystem.h:113
GroundFog * getGroundFog()
Get ground fog; if enabled.
Definition: CaelumSystem.h:446
const Ogre::ColourValue getSceneFogColourMultiplier() const
See setSceneFogColourMultiplier.
Definition: CaelumSystem.h:509
SkyDome * getSkyDome() const
Get the current sky dome, or null if disabled.
Definition: CaelumSystem.h:421
void setManageAmbientLight(bool value)
Set this to true to have CaelumSystem manage the scene&#39;s ambient light.
Definition: CaelumSystem.h:556
A cloud system is implemented by a number of cloud layers.
Definition: CloudSystem.h:31
bool getAutoAttachViewportsToComponents() const
Definition: CaelumSystem.h:347
Ogre::SceneNode * getCaelumCameraNode(void) const
Gets root scene node for camera-bound elements.
Definition: CaelumSystem.h:317
UniversalClock * getUniversalClock() const
Gets the universal clock.
Definition: CaelumSystem.h:418
CaelumComponent
Flags enumeration for caelum components.
Definition: CaelumSystem.h:218
bool getEnsureSingleShadowSource() const
See setEnsureSingleShadowSource.
Definition: CaelumSystem.h:587
bool getEnsureSingleLightSource() const
See setEnsureSingleLightSource.
Definition: CaelumSystem.h:579
const Ogre::Degree getObserverLongitude() const
Get the observer&#39;s longitude. East is positive, west is negative.
Definition: CaelumSystem.h:366
DepthComposer * getDepthComposer()
Get depth composer; or null if disabled.
Definition: CaelumSystem.h:461
Class representing the moon.
Definition: Moon.h:35
bool getAutoNotifyCameraChanged() const
Definition: CaelumSystem.h:331
void setEnsureSingleLightSource(bool value)
Ensure only one of caelum&#39;s light sources is active at a time (the brightest).
Definition: CaelumSystem.h:576
Caelum namespace.
Definition: Astronomy.cpp:24
void setAutoViewportBackground(bool value)
If true; automatically set the viewport color to black.
Definition: CaelumSystem.h:361
bool getAutoViewportBackground() const
Definition: CaelumSystem.h:363