Caelum
FlatCloudLayer.h
1 /*
2 This file is part of Caelum.
3 See http://www.ogre3d.org/wiki/index.php/Caelum
4 
5 Copyright (c) 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__FLAT_CLOUD_LAYER_H
22 #define CAELUM__FLAT_CLOUD_LAYER_H
23 
24 #include "CaelumPrerequisites.h"
25 #include "InternalUtilities.h"
26 #include "PrivatePtr.h"
27 #include "FastGpuParamRef.h"
28 
29 namespace Caelum
30 {
42  class CAELUM_EXPORT FlatCloudLayer
43  {
44  public:
46  Ogre::SceneManager *sceneMgr,
47  Ogre::SceneNode *cloudRoot);
48 
49  ~FlatCloudLayer();
50 
54  void update (
55  Ogre::Real timePassed,
56  const Ogre::Vector3 &sunDirection,
57  const Ogre::ColourValue &sunLightColour,
58  const Ogre::ColourValue &fogColour,
59  const Ogre::ColourValue &sunSphereColour);
60 
62  void advanceAnimation (Ogre::Real timePassed);
63 
66  void reset ();
67 
68  private:
69  Ogre::Vector2 mCloudSpeed;
70  Ogre::Vector2 mCloudMassOffset;
71  Ogre::Vector2 mCloudDetailOffset;
72 
73  // Set texture offsets.
74  // Animated every frame.
75  void setCloudMassOffset(const Ogre::Vector2 &cloudMassOffset);
76  void setCloudDetailOffset(const Ogre::Vector2 &cloudDetailOffset);
77 
78  public:
82  void setCloudSpeed (const Ogre::Vector2 &cloudSpeed);
83 
87  const Ogre::Vector2 getCloudSpeed () const { return mCloudSpeed; }
88 
89  private:
90  Ogre::Vector3 mSunDirection;
91  Ogre::ColourValue mSunLightColour;
92  Ogre::ColourValue mSunSphereColour;
93  Ogre::ColourValue mFogColour;
94 
95  public:
96  void setSunDirection(const Ogre::Vector3 &sunDirection);
97  void setSunLightColour(const Ogre::ColourValue &sunLightColour);
98  void setSunSphereColour(const Ogre::ColourValue &sunSphereColour);
99  void setFogColour(const Ogre::ColourValue &fogColour);
100  const Ogre::Vector3 getSunDirection () const;
101  const Ogre::ColourValue getSunLightColour () const;
102  const Ogre::ColourValue getSunSphereColour () const;
103  const Ogre::ColourValue getFogColour () const;
104 
105  private:
107  Ogre::SceneManager *mSceneMgr;
108 
109  // Note: objects are destroyed in reverse order of declaration.
110  // This means that objects must be ordered by dependency.
111 
113  PrivateMaterialPtr mMaterial;
114 
115  struct Params
116  {
117  void setup(Ogre::GpuProgramParametersSharedPtr fpParams, Ogre::GpuProgramParametersSharedPtr vpParams);
118 
119  Ogre::GpuProgramParametersSharedPtr vpParams;
120  Ogre::GpuProgramParametersSharedPtr fpParams;
121 
122  FastGpuParamRef cloudCoverageThreshold;
123  FastGpuParamRef cloudMassOffset;
124  FastGpuParamRef cloudDetailOffset;
125  FastGpuParamRef cloudMassBlend;
126  FastGpuParamRef vpSunDirection;
127  FastGpuParamRef fpSunDirection;
128  FastGpuParamRef sunLightColour;
129  FastGpuParamRef sunSphereColour;
130  FastGpuParamRef fogColour;
131  FastGpuParamRef layerHeight;
132  FastGpuParamRef cloudUVFactor;
133  FastGpuParamRef heightRedFactor;
134  FastGpuParamRef nearFadeDist;
135  FastGpuParamRef farFadeDist;
136  FastGpuParamRef fadeDistMeasurementVector;
137  } mParams;
138 
139  private:
140  PrivateMeshPtr mMesh;
141  PrivateSceneNodePtr mNode;
142  PrivateEntityPtr mEntity;
143 
144  // Mesh parameters.
145  bool mMeshDirty;
146  Real mMeshWidth, mMeshHeight;
147  int mMeshWidthSegments, mMeshHeightSegments;
148 
149  public:
153  void _ensureGeometry();
154 
158  void _invalidateGeometry();
159 
162  void setMeshParameters (
163  Real meshWidth, Real meshHeight,
164  int meshWidthSegments, int meshHeightSegments);
165 
167  inline void setMeshWidth (Real value) { mMeshWidth = value; _invalidateGeometry (); }
168  inline void setMeshHeight (Real value) { mMeshHeight = value; _invalidateGeometry (); }
169  inline void setMeshWidthSegments (int value) { mMeshWidthSegments = value; _invalidateGeometry (); }
170  inline void setMeshHeightSegments (int value) { mMeshHeightSegments = value; _invalidateGeometry (); }
171  inline Real getMeshWidth () const { return mMeshWidth; }
172  inline Real getMeshHeight () const { return mMeshHeight; }
173  inline int getMeshWidthSegments () const { return mMeshWidthSegments; }
174  inline int getMeshHeightSegments () const { return mMeshHeightSegments; }
175 
176  private:
178  std::auto_ptr<Ogre::Image> mCloudCoverLookup;
179 
181  Ogre::String mCloudCoverLookupFileName;
182 
184  Ogre::Real mCloudCover;
185 
186  public:
190  void setCloudCover (const Ogre::Real cloudCover);
191 
195  inline Ogre::Real getCloudCover () const { return mCloudCover; }
196 
209  void setCloudCoverLookup (const Ogre::String& fileName);
210 
215  const Ogre::String getCloudCoverLookupFileName () const;
216 
220  void disableCloudCoverLookup ();
221 
222  private:
223  Ogre::Real mCloudCoverVisibilityThreshold;
224 
225  protected:
228  void _updateVisibilityThreshold ();
229 
230  public:
233  Ogre::Real getCloudCoverVisibilityThreshold () const { return mCloudCoverVisibilityThreshold; }
234 
241  void setCloudCoverVisibilityThreshold (const Ogre::Real value);
242 
243  private:
245  Ogre::Real mHeight;
246 
247  public:
251  void setHeight(Ogre::Real height);
252 
256  Ogre::Real getHeight() const;
257 
258  private:
260  Ogre::Real mCloudBlendPos;
261 
264  int mCurrentTextureIndex;
265 
267  Ogre::Real mCloudBlendTime;
268 
270  std::vector<String> mNoiseTextureNames;
271 
272  public:
277  void setCloudBlendTime (const Ogre::Real value);
278 
282  Ogre::Real getCloudBlendTime () const;
283 
289  void setCloudBlendPos (const Ogre::Real value);
290 
292  Ogre::Real getCloudBlendPos () const;
293 
294  private:
295  Ogre::Real mCloudUVFactor;
296 
297  public:
302  void setCloudUVFactor (const Ogre::Real value);
304  inline Ogre::Real getCloudUVFactor () const { return mCloudUVFactor; }
305 
306  private:
307  Ogre::Real mHeightRedFactor;
308 
309  public:
313  void setHeightRedFactor (const Ogre::Real value);
315  Ogre::Real getHeightRedFactor () const { return mHeightRedFactor; }
316 
317  private:
318  Ogre::Real mNearFadeDist;
319  Ogre::Real mFarFadeDist;
320  Ogre::Vector3 mFadeDistMeasurementVector;
321 
322  public:
333  void setFadeDistances (Ogre::Real nearValue, Ogre::Real farValue);
334 
336  void setNearFadeDist (const Ogre::Real value);
338  Ogre::Real getNearFadeDist () const { return mNearFadeDist; }
339 
341  void setFarFadeDist (const Ogre::Real value);
343  Ogre::Real getFarFadeDist () const { return mFarFadeDist; }
344 
354  void setFadeDistMeasurementVector (const Ogre::Vector3& value);
356  const Ogre::Vector3 getFadeDistMeasurementVector () const { return mFadeDistMeasurementVector; }
357 
358  public:
359  void setQueryFlags (uint flags) { mEntity->setQueryFlags (flags); }
360  uint getQueryFlags () const { return mEntity->getQueryFlags (); }
361  void setVisibilityFlags (uint flags) { mEntity->setVisibilityFlags (flags); }
362  uint getVisibilityFlags () const { return mEntity->getVisibilityFlags (); }
363  };
364 }
365 
366 #endif // CAELUM__FLAT_CLOUD_LAYER_H
const Ogre::Vector3 getFadeDistMeasurementVector() const
Get the value set by setFadeDistMeasurementVector.
Ogre::Real getCloudUVFactor() const
Ogre::Real getFarFadeDist() const
Get fade distance (see setFadeDistances).
const Ogre::Vector2 getCloudSpeed() const
Gets cloud movement speed.
Ogre::Real getHeightRedFactor() const
Ogre::Real getCloudCover() const
Gets the current cloud cover.
A flat cloud layer; drawn as a simple plane.
void setMeshWidth(Real value)
Ogre::Real getCloudCoverVisibilityThreshold() const
Get cloud cover visiblity threshold.
Ogre::Real getNearFadeDist() const
Get near fade distance (see setFadeDistances).
An optimized reference to a gpu shared parameter.
Caelum namespace.
Definition: Astronomy.cpp:24