00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef CAELUM__CAELUM_SYSTEM_H
00022 #define CAELUM__CAELUM_SYSTEM_H
00023
00024 #include "CaelumPrerequisites.h"
00025 #include "UniversalClock.h"
00026 #include "ImageStarfield.h"
00027 #include "PointStarfield.h"
00028 #include "SkyLight.h"
00029 #include "Sun.h"
00030 #include "Moon.h"
00031 #include "CloudSystem.h"
00032 #include "SkyDome.h"
00033 #include "DepthComposer.h"
00034 #include "PrecipitationController.h"
00035 #include "GroundFog.h"
00036 #include "PrivatePtr.h"
00037
00038 namespace Caelum
00039 {
00113 class CAELUM_EXPORT CaelumSystem:
00114 public Ogre::FrameListener,
00115 public Ogre::RenderTargetListener
00116 {
00117 private:
00119 Ogre::Root *mOgreRoot;
00120
00122 Ogre::SceneManager *mSceneMgr;
00123
00125 PrivateSceneNodePtr mCaelumCameraNode;
00126
00128 PrivateSceneNodePtr mCaelumGroundNode;
00129
00131 bool mCleanup;
00132
00134 bool mAutoMoveCameraNode;
00135
00137 bool mAutoNotifyCameraChanged;
00138
00140 bool mAutoAttachViewportsToComponents;
00141
00143 bool mAutoViewportBackground;
00144
00146 bool mManageSceneFog;
00147
00148 Real mGlobalFogDensityMultiplier;
00149 Ogre::ColourValue mGlobalFogColourMultiplier;
00150
00151 Real mSceneFogDensityMultiplier;
00152 Ogre::ColourValue mSceneFogColourMultiplier;
00153
00154 Real mGroundFogDensityMultiplier;
00155 Ogre::ColourValue mGroundFogColourMultiplier;
00156
00158 bool mManageAmbientLight;
00159
00161 Ogre::ColourValue mMinimumAmbientLight;
00162
00164 bool mEnsureSingleLightSource;
00165
00167 bool mEnsureSingleShadowSource;
00168
00170 std::auto_ptr<Ogre::Image> mSkyGradientsImage;
00171
00173 std::auto_ptr<Ogre::Image> mSunColoursImage;
00174
00176 Ogre::Degree mObserverLatitude;
00178 Ogre::Degree mObserverLongitude;
00179
00180 static const Ogre::Vector3 makeDirection (
00181 Ogre::Degree azimuth, Ogre::Degree altitude);
00182
00183
00184 std::auto_ptr<UniversalClock> mUniversalClock;
00185 std::auto_ptr<SkyDome> mSkyDome;
00186 std::auto_ptr<BaseSkyLight> mSun;
00187 std::auto_ptr<Moon> mMoon;
00188 std::auto_ptr<ImageStarfield> mImageStarfield;
00189 std::auto_ptr<PointStarfield> mPointStarfield;
00190 std::auto_ptr<GroundFog> mGroundFog;
00191 std::auto_ptr<CloudSystem> mCloudSystem;
00192 std::auto_ptr<PrecipitationController> mPrecipitationController;
00193 std::auto_ptr<DepthComposer> mDepthComposer;
00194
00195 public:
00196 typedef std::set<Ogre::Viewport*> AttachedViewportSet;
00197
00198 private:
00199 AttachedViewportSet mAttachedViewports;
00200
00201 public:
00215 enum CaelumComponent
00216 {
00217 CAELUM_COMPONENT_SKY_DOME = 1 << 1,
00218 CAELUM_COMPONENT_MOON = 1 << 3,
00219 CAELUM_COMPONENT_SUN = 1 << 4,
00220 CAELUM_COMPONENT_IMAGE_STARFIELD = 1 << 5,
00221 CAELUM_COMPONENT_POINT_STARFIELD = 1 << 6,
00222 CAELUM_COMPONENT_CLOUDS = 1 << 7,
00223 CAELUM_COMPONENT_PRECIPITATION = 1 << 8,
00224 CAELUM_COMPONENT_SCREEN_SPACE_FOG = 1 << 9,
00225
00226
00227 CAELUM_COMPONENT_GROUND_FOG = 1 << (16 + 0),
00228
00229
00230 CAELUM_COMPONENTS_NONE = 0,
00231 CAELUM_COMPONENTS_DEFAULT = 0
00232 | CAELUM_COMPONENT_SKY_DOME
00233 | CAELUM_COMPONENT_MOON
00234 | CAELUM_COMPONENT_SUN
00235 | CAELUM_COMPONENT_POINT_STARFIELD
00236 | CAELUM_COMPONENT_CLOUDS,
00237 CAELUM_COMPONENTS_ALL = 0
00238 | CAELUM_COMPONENTS_DEFAULT
00239 | CAELUM_COMPONENT_PRECIPITATION
00240 | CAELUM_COMPONENT_SCREEN_SPACE_FOG
00241 | CAELUM_COMPONENT_GROUND_FOG,
00242 };
00243
00244 static const String DEFAULT_SKY_GRADIENTS_IMAGE;
00245 static const String DEFAULT_SUN_COLOURS_IMAGE;
00246
00254 CaelumSystem (
00255 Ogre::Root *root,
00256 Ogre::SceneManager *sceneMgr,
00257 CaelumComponent componentsToCreate);
00258
00264 void clear ();
00265
00271 void autoConfigure (
00272 CaelumComponent componentsToCreate);
00273
00276 ~CaelumSystem ();
00277
00287 void shutdown (bool cleanup);
00288
00295 void updateSubcomponents (Real timeSinceLastFrame);
00296
00306 void notifyCameraChanged(Ogre::Camera* cam);
00307
00311 inline Ogre::SceneManager* getSceneMgr() const { return mSceneMgr; }
00312
00314 inline Ogre::SceneNode* getCaelumCameraNode(void) const { return mCaelumCameraNode.get(); }
00315
00317 inline Ogre::SceneNode* getCaelumGroundNode(void) const { return mCaelumGroundNode.get(); }
00318
00326 inline void setAutoNotifyCameraChanged(bool value) { mAutoNotifyCameraChanged = value; }
00328 inline bool getAutoNotifyCameraChanged() const { return mAutoNotifyCameraChanged; }
00329
00342 inline void setAutoAttachViewportsToComponents(bool value) { mAutoAttachViewportsToComponents = value; }
00344 inline bool getAutoAttachViewportsToComponents() const { return mAutoAttachViewportsToComponents; }
00345
00350 inline void setAutoMoveCameraNode(bool value) { mAutoMoveCameraNode = value; }
00352 inline bool getAutoMoveCameraNode() { return mAutoMoveCameraNode; }
00353
00358 inline void setAutoViewportBackground(bool value) { mAutoViewportBackground = value; }
00360 inline bool getAutoViewportBackground() const { return mAutoViewportBackground; }
00361
00363 inline const Ogre::Degree getObserverLongitude () const { return mObserverLongitude; }
00364
00366 inline void setObserverLongitude (Ogre::Degree value) { mObserverLongitude = value; }
00367
00369 inline const Ogre::Degree getObserverLatitude () const { return mObserverLatitude; }
00370
00372 inline void setObserverLatitude (Ogre::Degree value) { mObserverLatitude = value; }
00373
00374 inline LongReal getJulianDay () const { return mUniversalClock->getJulianDay (); }
00375 inline void setJulianDay (LongReal value) { mUniversalClock->setJulianDay (value); }
00376 inline Real getTimeScale () const { return mUniversalClock->getTimeScale (); }
00377 inline void setTimeScale (Real value) { mUniversalClock->setTimeScale (value); }
00378
00379 public:
00388 void attachViewport (Ogre::Viewport* rt);
00389
00395 void detachViewport (Ogre::Viewport* rt);
00396
00399 bool isViewportAttached (Ogre::Viewport* vp) const;
00400
00403 void detachAllViewports ();
00404
00406 const AttachedViewportSet& _getAttachedViewportSet () { return mAttachedViewports; }
00407
00408 protected:
00409
00410 void attachViewportImpl (Ogre::Viewport* rt);
00411 void detachViewportImpl (Ogre::Viewport* rt);
00412
00413 public:
00415 inline UniversalClock *getUniversalClock () const { return mUniversalClock.get(); }
00416
00418 inline SkyDome* getSkyDome () const { return mSkyDome.get (); }
00420 void setSkyDome (SkyDome *obj);
00421
00423 inline BaseSkyLight* getSun () const { return mSun.get (); }
00425 void setSun (BaseSkyLight* obj);
00426
00428 inline Moon* getMoon () const { return mMoon.get (); }
00430 void setMoon (Moon* obj);
00431
00433 inline ImageStarfield* getImageStarfield () const { return mImageStarfield.get (); }
00435 void setImageStarfield (ImageStarfield* obj);
00436
00438 inline PointStarfield* getPointStarfield () const { return mPointStarfield.get (); }
00440 void setPointStarfield (PointStarfield* obj);
00441
00443 inline GroundFog* getGroundFog () { return mGroundFog.get (); }
00445 void setGroundFog (GroundFog *obj);
00446
00448 inline CloudSystem* getCloudSystem () { return mCloudSystem.get (); }
00450 void setCloudSystem (CloudSystem *obj);
00451
00453 inline PrecipitationController* getPrecipitationController () { return mPrecipitationController.get (); }
00455 void setPrecipitationController (PrecipitationController *obj);
00456
00458 inline DepthComposer* getDepthComposer () { return mDepthComposer.get (); }
00460 void setDepthComposer (DepthComposer *obj);
00461
00474 void setManageSceneFog (bool value);
00475
00479 bool getManageSceneFog () const;
00480
00488 void setSceneFogDensityMultiplier (Real value);
00489
00492 Real getSceneFogDensityMultiplier () const;
00493
00497 inline void setSceneFogColourMultiplier (const Ogre::ColourValue& value) { mSceneFogColourMultiplier = value; }
00498
00500 inline const Ogre::ColourValue getSceneFogColourMultiplier () const { return mSceneFogColourMultiplier; }
00501
00508 void setGroundFogDensityMultiplier (Real value);
00509
00512 Real getGroundFogDensityMultiplier () const;
00513
00517 inline void setGroundFogColourMultiplier (const Ogre::ColourValue& value) { mGroundFogColourMultiplier = value; }
00518
00520 inline const Ogre::ColourValue getGroundFogColourMultiplier () const { return mGroundFogColourMultiplier; }
00521
00528 void setGlobalFogDensityMultiplier (Real value);
00529
00532 Real getGlobalFogDensityMultiplier () const;
00533
00538 inline void setGlobalFogColourMultiplier (const Ogre::ColourValue& value) { mGlobalFogColourMultiplier = value; }
00539
00541 inline const Ogre::ColourValue getGlobalFogColourMultiplier () const { return mGlobalFogColourMultiplier; }
00542
00547 inline void setManageAmbientLight (bool value) { mManageAmbientLight = value; }
00548
00550 inline bool getManageAmbientLight () const { return mManageAmbientLight; }
00551
00556 inline void setMinimumAmbientLight (const Ogre::ColourValue &value) { mMinimumAmbientLight = value; }
00557
00559 inline const Ogre::ColourValue getMinimumAmbientLight () const { return mMinimumAmbientLight; }
00560
00567 inline void setEnsureSingleLightSource (bool value) { mEnsureSingleLightSource = value; }
00568
00570 inline bool getEnsureSingleLightSource () const { return mEnsureSingleLightSource; }
00571
00575 inline void setEnsureSingleShadowSource (bool value) { mEnsureSingleShadowSource = value; }
00576
00578 inline bool getEnsureSingleShadowSource () const { return mEnsureSingleShadowSource; }
00579
00585 Ogre::ColourValue getFogColour (Real time, const Ogre::Vector3 &sunDir);
00586
00592 Real getFogDensity (Real time, const Ogre::Vector3 &sunDir);
00593
00598 Ogre::ColourValue getSunSphereColour (Real time, const Ogre::Vector3 &sunDir);
00599
00604 Ogre::ColourValue getSunLightColour (Real time, const Ogre::Vector3 &sunDir);
00605
00607 Ogre::ColourValue getMoonBodyColour (const Ogre::Vector3 &moonDir);
00608
00610 Ogre::ColourValue getMoonLightColour (const Ogre::Vector3 &moonDir);
00611
00613 void setSkyGradientsImage (const Ogre::String &filename = DEFAULT_SKY_GRADIENTS_IMAGE);
00614
00617 void setSunColoursImage (const Ogre::String &filename = DEFAULT_SUN_COLOURS_IMAGE);
00618
00623 const Ogre::Vector3 getSunDirection (LongReal jday);
00624
00628 const Ogre::Vector3 getMoonDirection (LongReal jday);
00629
00636 const Ogre::Real getMoonPhase (LongReal jday);
00637
00638 private:
00643 virtual bool frameStarted (const Ogre::FrameEvent &e);
00644
00648 virtual void preViewportUpdate (const Ogre::RenderTargetViewportEvent &e);
00649
00653 void destroySubcomponents (bool everything);
00654
00655 public:
00664 void forceSubcomponentQueryFlags (uint mask);
00665
00668 void forceSubcomponentVisibilityFlags (uint mask);
00669 };
00670 }
00671
00672 #endif // CAELUM__CAELUM_SYSTEM_H