OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
sky.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_MWRENDER_SKY_H
2 #define OPENMW_MWRENDER_SKY_H
3 
4 #include <string>
5 #include <memory>
6 #include <vector>
7 #include <iostream>
8 
9 #include <osg/ref_ptr>
10 #include <osg/Vec4f>
11 #include <osg/Uniform>
12 
13 namespace osg
14 {
15  class Camera;
16 }
17 
18 namespace osg
19 {
20  class Group;
21  class Node;
22  class Material;
23  class PositionAttitudeTransform;
24 }
25 
26 namespace osgParticle
27 {
28  class ParticleSystem;
29 }
30 
31 namespace Resource
32 {
33  class SceneManager;
34 }
35 
36 namespace MWRender
37 {
38  class AtmosphereUpdater;
39  class AtmosphereNightUpdater;
40  class CloudUpdater;
41  class Sun;
42  class Moon;
43  class RainShooter;
44  class RainFader;
45  class AlphaFader;
46  class UnderwaterSwitchCallback;
47 
49  {
50  std::string mCloudTexture;
51  std::string mNextCloudTexture;
53 
54  osg::Vec4f mFogColor;
55 
56  osg::Vec4f mAmbientColor;
57 
58  osg::Vec4f mSkyColor;
59 
60  // sun light color
61  osg::Vec4f mSunColor;
62 
63  // alpha is the sun transparency
64  osg::Vec4f mSunDiscColor;
65 
66  float mFogDepth;
67 
68  float mDLFogFactor;
69  float mDLFogOffset;
70 
71  float mWindSpeed;
72 
73  float mCloudSpeed;
74 
75  float mGlareView;
76 
77  bool mNight; // use night skybox
78  float mNightFade; // fading factor for night skybox
79 
80  bool mIsStorm;
81 
82  std::string mAmbientLoopSoundID;
84 
85  std::string mParticleEffect;
86  std::string mRainEffect;
87  float mEffectFade;
88 
89  float mRainSpeed;
91  };
92 
93  struct MoonState
94  {
95  enum Phase
96  {
106  };
107 
112  float mMoonAlpha;
113  };
114 
118  {
119  public:
120  SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager);
121  ~SkyManager();
122 
123  void update(float duration);
124 
125  void setEnabled(bool enabled);
126 
127  void setHour (double hour);
129 
130  void setDate (int day, int month);
132 
133  int getMasserPhase() const;
136 
137  int getSecundaPhase() const;
140 
141  void setMoonColour (bool red);
143 
144  void setWeather(const WeatherResult& weather);
145 
146  void sunEnable();
147 
148  void sunDisable();
149 
150  bool isEnabled();
151 
152  bool hasRain();
153 
154  void setRainSpeed(float speed);
155 
156  void setStormDirection(const osg::Vec3f& direction);
157 
158  void setSunDirection(const osg::Vec3f& direction);
159 
160  void setMasserState(const MoonState& state);
161  void setSecundaState(const MoonState& state);
162 
163  void setGlareTimeOfDayFade(float val);
164 
166  void setWaterEnabled(bool enabled);
167 
169  void setWaterHeight(float height);
170 
171  void listAssetsToPreload(std::vector<std::string>& models, std::vector<std::string>& textures);
172 
173  void setCamera(osg::Camera *camera);
174 
175  void setRainIntensityUniform(osg::Uniform *uniform);
176 
177  private:
178  void create();
180 
181  void createRain();
182  void destroyRain();
183  void updateRainParameters();
184 
186 
187  osg::Camera *mCamera;
188  osg::Uniform *mRainIntensityUniform;
189 
190  osg::ref_ptr<osg::Group> mRootNode;
191  osg::ref_ptr<osg::Group> mEarlyRenderBinRoot;
192 
193  osg::ref_ptr<osg::PositionAttitudeTransform> mParticleNode;
194  osg::ref_ptr<osg::Node> mParticleEffect;
195  std::vector<osg::ref_ptr<AlphaFader> > mParticleFaders;
196  osg::ref_ptr<UnderwaterSwitchCallback> mUnderwaterSwitch;
197 
198  osg::ref_ptr<osg::PositionAttitudeTransform> mCloudNode;
199 
200  osg::ref_ptr<CloudUpdater> mCloudUpdater;
201  osg::ref_ptr<CloudUpdater> mCloudUpdater2;
202  osg::ref_ptr<osg::Node> mCloudMesh;
203  osg::ref_ptr<osg::Node> mCloudMesh2;
204 
205  osg::ref_ptr<osg::Node> mAtmosphereDay;
206 
207  osg::ref_ptr<osg::PositionAttitudeTransform> mAtmosphereNightNode;
209  osg::ref_ptr<AtmosphereNightUpdater> mAtmosphereNightUpdater;
210 
211  osg::ref_ptr<AtmosphereUpdater> mAtmosphereUpdater;
212 
213  std::unique_ptr<Sun> mSun;
214  std::unique_ptr<Moon> mMasser;
215  std::unique_ptr<Moon> mSecunda;
216 
217  osg::ref_ptr<osg::Group> mRainNode;
218  osg::ref_ptr<osgParticle::ParticleSystem> mRainParticleSystem;
219  osg::ref_ptr<RainShooter> mRainShooter;
220  osg::ref_ptr<RainFader> mRainFader;
221 
222  bool mCreated;
223 
224  bool mIsStorm;
225 
226  int mDay;
227  int mMonth;
228 
230 
231  float mRainTimer;
232 
233  osg::Vec3f mStormDirection;
234 
235  // remember some settings so we don't have to apply them again if they didn't change
236  std::string mClouds;
237  std::string mNextClouds;
239  float mCloudSpeed;
241  osg::Vec4f mCloudColour;
242  osg::Vec4f mSkyColour;
243  osg::Vec4f mFogColour;
244 
246 
248 
250  std::string mRainEffect;
251  float mRainSpeed;
253  float mWindSpeed;
254 
255  bool mEnabled;
257 
259 
260  osg::Vec4f mMoonScriptColor;
261  };
262 }
263 
264 #endif // GAME_RENDER_SKY_H
int getSecundaPhase() const
Definition: sky.cpp:1544
osg::ref_ptr< osg::Node > mCloudMesh2
Definition: sky.hpp:203
void setEnabled(bool enabled)
Definition: sky.cpp:1602
bool mCreated
Definition: sky.hpp:222
float mShadowBlend
Definition: sky.hpp:111
Phase mPhase
Definition: sky.hpp:110
osg::ref_ptr< osgParticle::ParticleSystem > mRainParticleSystem
Definition: sky.hpp:218
float mAmbientSoundVolume
Definition: sky.hpp:83
void setMoonColour(bool red)
change Secunda colour to red
Definition: sky.cpp:1612
osg::ref_ptr< UnderwaterSwitchCallback > mUnderwaterSwitch
Definition: sky.hpp:196
osg::ref_ptr< osg::Node > mCloudMesh
Definition: sky.hpp:202
void setRainSpeed(float speed)
float mCloudAnimationTimer
Definition: sky.hpp:229
osg::ref_ptr< osg::Group > mEarlyRenderBinRoot
Definition: sky.hpp:191
float mRainSpeed
Definition: sky.hpp:89
float mRainFrequency
Definition: sky.hpp:252
float mRainSpeed
Definition: sky.hpp:251
Definition: sky.hpp:48
void setDate(int day, int month)
will be called even when sky is disabled.
Definition: sky.cpp:1843
Handles loading and caching of scenes, e.g. .nif files or .osg files.
Definition: scenemanager.hpp:44
float mWindSpeed
Definition: sky.hpp:253
float mNightFade
Definition: sky.hpp:78
std::string mNextClouds
Definition: sky.hpp:237
osg::ref_ptr< AtmosphereNightUpdater > mAtmosphereNightUpdater
Definition: sky.hpp:209
void update(float duration)
Definition: sky.cpp:1560
float mCloudBlendFactor
Definition: sky.hpp:52
float mRemainingTransitionTime
Definition: sky.hpp:247
std::string mNextCloudTexture
Definition: sky.hpp:51
osg::ref_ptr< CloudUpdater > mCloudUpdater2
Definition: sky.hpp:201
void sunEnable()
Definition: sky.cpp:1803
bool hasRain()
Definition: sky.cpp:1555
void setWaterHeight(float height)
Set height of water plane (used to remove underwater weather particles)
Definition: sky.cpp:1854
float mCloudSpeed
Definition: sky.hpp:73
std::string mClouds
Definition: sky.hpp:236
The SkyManager handles rendering of the sky domes, celestial bodies as well as other objects that nee...
Definition: sky.hpp:117
void setWeather(const WeatherResult &weather)
Definition: sky.cpp:1629
osg::Vec3f mStormDirection
Definition: sky.hpp:233
osg::Vec4f mFogColour
Definition: sky.hpp:243
osg::Vec4f mSunColor
Definition: sky.hpp:61
float mWindSpeed
Definition: sky.hpp:71
float mRainFrequency
Definition: sky.hpp:90
std::string mAmbientLoopSoundID
Definition: sky.hpp:82
std::string mRainEffect
Definition: sky.hpp:86
float mWeatherAlpha
Definition: sky.hpp:258
osg::Vec4f mSkyColour
Definition: sky.hpp:242
bool mNight
Definition: sky.hpp:77
osg::ref_ptr< osg::Group > mRootNode
Definition: sky.hpp:190
float mDLFogOffset
Definition: sky.hpp:69
int mDay
Definition: sky.hpp:226
float mRainTimer
Definition: sky.hpp:231
void setStormDirection(const osg::Vec3f &direction)
Definition: sky.cpp:1817
int mMonth
Definition: sky.hpp:227
std::string mCloudTexture
Definition: sky.hpp:50
Definition: sky.hpp:101
Definition: sky.hpp:93
osg::Vec4f mCloudColour
Definition: sky.hpp:241
void setCamera(osg::Camera *camera)
Definition: sky.cpp:1368
float mCloudSpeed
Definition: sky.hpp:239
float mMoonAlpha
Definition: sky.hpp:112
std::string mCurrentParticleEffect
Definition: sky.hpp:245
void updateRainParameters()
Definition: sky.cpp:1618
float mStarsOpacity
Definition: sky.hpp:240
void destroyRain()
Definition: sky.cpp:1517
bool mSunEnabled
Definition: sky.hpp:256
osg::ref_ptr< CloudUpdater > mCloudUpdater
Definition: sky.hpp:200
osg::ref_ptr< RainShooter > mRainShooter
Definition: sky.hpp:219
osg::ref_ptr< osg::PositionAttitudeTransform > mAtmosphereNightNode
Definition: sky.hpp:207
Phase
Definition: sky.hpp:95
osg::ref_ptr< osg::PositionAttitudeTransform > mParticleNode
Definition: sky.hpp:193
osg::Vec4f mAmbientColor
Definition: sky.hpp:56
std::unique_ptr< Moon > mSecunda
Definition: sky.hpp:215
float mAtmosphereNightRoll
Definition: sky.hpp:208
~SkyManager()
Definition: sky.cpp:1529
void setSunDirection(const osg::Vec3f &direction)
Definition: sky.cpp:1822
std::unique_ptr< Moon > mMasser
Definition: sky.hpp:214
SkyManager(osg::Group *parentNode, Resource::SceneManager *sceneManager)
Definition: sky.cpp:1096
float mCloudBlendFactor
Definition: sky.hpp:238
osg::Vec4f mSunDiscColor
Definition: sky.hpp:64
void setGlareTimeOfDayFade(float val)
Definition: sky.cpp:1849
void setRainIntensityUniform(osg::Uniform *uniform)
Definition: sky.cpp:1143
osg::Vec4f mSkyColor
Definition: sky.hpp:58
float mDLFogFactor
Definition: sky.hpp:68
std::vector< osg::ref_ptr< AlphaFader > > mParticleFaders
Definition: sky.hpp:195
std::string mParticleEffect
Definition: sky.hpp:85
float mFogDepth
Definition: sky.hpp:66
void listAssetsToPreload(std::vector< std::string > &models, std::vector< std::string > &textures)
Definition: sky.cpp:1859
bool mRainEnabled
Definition: sky.hpp:249
osg::ref_ptr< osg::Node > mParticleEffect
Definition: sky.hpp:194
osg::ref_ptr< AtmosphereUpdater > mAtmosphereUpdater
Definition: sky.hpp:211
osg::ref_ptr< osg::Node > mAtmosphereDay
Definition: sky.hpp:205
osg::ref_ptr< RainFader > mRainFader
Definition: sky.hpp:220
float mRotationFromNorth
Definition: sky.hpp:109
void setSecundaState(const MoonState &state)
Definition: sky.cpp:1836
Definition: sky.hpp:97
bool mIsStorm
Definition: sky.hpp:224
std::unique_ptr< Sun > mSun
Definition: sky.hpp:213
osg::Vec4f mMoonScriptColor
Definition: sky.hpp:260
osg::Camera * mCamera
Definition: sky.hpp:187
bool mEnabled
Definition: sky.hpp:255
float mGlareView
Definition: sky.hpp:75
osg::Uniform * mRainIntensityUniform
Definition: sky.hpp:188
void sunDisable()
Definition: sky.cpp:1810
osg::ref_ptr< osg::Group > mRainNode
Definition: sky.hpp:217
float mEffectFade
Definition: sky.hpp:87
void setHour(double hour)
will be called even when sky is disabled.
void setWaterEnabled(bool enabled)
Enable or disable the water plane (used to remove underwater weather particles)
Definition: sky.cpp:1899
void create()
no need to call this, automatically done on first enable()
Definition: sky.cpp:1148
bool mIsStorm
Definition: sky.hpp:80
std::string mRainEffect
Definition: sky.hpp:250
int getMasserPhase() const
Definition: sky.cpp:1538
osg::Vec4f mFogColor
Definition: sky.hpp:54
osg::ref_ptr< osg::PositionAttitudeTransform > mCloudNode
Definition: sky.hpp:198
void createRain()
Definition: sky.cpp:1449
float mRotationFromHorizon
Definition: sky.hpp:108
void setMasserState(const MoonState &state)
Definition: sky.cpp:1829
Resource::SceneManager * mSceneManager
Definition: sky.hpp:185
bool isEnabled()
Definition: sky.cpp:1550