~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/environment/caelum/include/LayeredClouds.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
This file is part of Caelum.
 
3
See http://www.ogre3d.org/wiki/index.php/Caelum 
 
4
 
 
5
Copyright (c) 2006-2007 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 LAYEREDCLOUDS_H
 
22
#define LAYEREDCLOUDS_H
 
23
 
 
24
#include "CaelumPrerequisites.h"
 
25
#include "CameraBoundElement.h"
 
26
 
 
27
namespace caelum {
 
28
 
 
29
/** Class for layered clouds.
 
30
 *  @note This is tighly integrated with LayeredCloud.cg and LayeredClouds.material.
 
31
 *  There are two "cloud mass" layers blended to create animating clouds and an extra
 
32
 *  detailLayer.
 
33
 *  Most of the parameters in this class are direct wrappers from GPU shader params.
 
34
 *
 
35
 *  Cloud offsets and speeds are not in any meaningful world units. Maybe they should
 
36
 *  be in radians or something?
 
37
 */
 
38
class CAELUM_EXPORT LayeredClouds: public CameraBoundElement {
 
39
        public:
 
40
                /** Standard constructor.
 
41
                 *  @param scene: Scene to add cloud dome to. This class takes control
 
42
                 *              of the scene's skydome.
 
43
                 *  @param material: Name of the material to load. It would be a lot
 
44
                 *              more consistent to generate the material in code.
 
45
                 */
 
46
                LayeredClouds (
 
47
                Ogre::SceneManager* scene,
 
48
                                Ogre::SceneNode *caelumRootNode,
 
49
                                const Ogre::String &resourceGroupName="Caelum",
 
50
                                const Ogre::String &materialName="CaelumLayeredClouds",
 
51
                                const Ogre::String &meshName="CaelumLayeredClouds",
 
52
                                const Ogre::String &entityName="CaelumLayeredClouds");
 
53
 
 
54
                ~LayeredClouds ();
 
55
 
 
56
                /** Update cloud material.
 
57
                 *  @param timePassed Time passed since last update.
 
58
                 *  @param sunDirection Vector towards the sun.
 
59
                 *  @param sunColour Colour of the sun.
 
60
                 */
 
61
                void update (
 
62
                Ogre::Real timePassed,
 
63
                                const Ogre::Vector3& sunDirection,
 
64
                                const Ogre::ColourValue& sunColour,
 
65
                                const Ogre::ColourValue& fogColour);
 
66
 
 
67
                /** Sets cloud cover, between 0 (completely clear) and 1 (completely covered)
 
68
                 *  @param cloudCover Cloud cover between 0 and 1
 
69
                 */
 
70
                void setCloudCover (const Ogre::Real cloudCover);
 
71
 
 
72
                /** Gets the current cloud cover.
 
73
                 *  @return Cloud cover, between 0 and 1
 
74
                 */
 
75
                Ogre::Real getCloudCover () const;
 
76
 
 
77
        /** Set the image used to lookup the cloud coverage threshold.
 
78
         *  This image is used to calculate the cloud coverage threshold
 
79
         *  based on the desired cloud cover.
 
80
         *
 
81
         *  The cloud coverage threshold is substracted from cloud intensity
 
82
         *  at any point; to generate fewer or more clouds. That threshold is
 
83
         *  not linear, a lookup is required to ensure that setCloudCover(0.1)
 
84
         *  will actually have 10% the clouds at setCloudCover(1).
 
85
         *
 
86
         *  The lookup is the inverse of the sum on the histogram, and was
 
87
         *  calculated with a small hacky tool.
 
88
         */
 
89
        void setCloudCoverLookup (const Ogre::String& fileName);
 
90
 
 
91
        /** Disable any cloud cover lookup.
 
92
         *  @see setCloudCoverLookup.
 
93
         */
 
94
        void disableCloudCoverLookup ();
 
95
 
 
96
 
 
97
                /** Sets blending factor between the two cloud mass layers.
 
98
                 */
 
99
                void setCloudMassBlend (const Ogre::Real cloudCover);
 
100
 
 
101
                /** Gets the current blending factor between the two cloud mass layers
 
102
                 */
 
103
                Ogre::Real getCloudMassBlend () const;
 
104
 
 
105
                /** Sets current offset(translation) of the cloud mass on the sky.
 
106
                 */
 
107
                void setCloudMassOffset (const Ogre::Vector2 &cloudMassOffset);
 
108
 
 
109
                /** Gets current offset(translation) of the cloud mass on the sky.
 
110
                 */
 
111
                Ogre::Vector2 getCloudMassOffset () const;
 
112
 
 
113
                /** Sets current offset(translation) of cloud details on the sky.
 
114
                 */
 
115
                void setCloudDetailOffset (const Ogre::Vector2 &cloudMassOffset);
 
116
 
 
117
                /** Gets current offset(translation) of cloud details on the sky.
 
118
                 */
 
119
                Ogre::Vector2 getCloudDetailOffset () const;
 
120
 
 
121
 
 
122
                /** If the cloud layer is animating itself.
 
123
                 *  @note If this is true then parameters like cloudMassBlend and offsets
 
124
                 *  are set every update().
 
125
                 */
 
126
                bool isAnimating () const;
 
127
 
 
128
                /** Switch internal animation on/off
 
129
                 */
 
130
                void setAnimating (bool animating);
 
131
 
 
132
                /** Sets cloud movement speed.
 
133
                 *  @param cloudSpeed Cloud movement speed.
 
134
                 */
 
135
                void setCloudSpeed (const Ogre::Vector2 &cloudSpeed);
 
136
 
 
137
                /** Gets cloud movement speed.
 
138
                 *  @param cloudSpeed Cloud movement speed.
 
139
                 */
 
140
                Ogre::Vector2 getCloudSpeed () const;
 
141
 
 
142
                /** Sets the time it takes to blend two cloud shaped together, in seconds.
 
143
                 *  @param cloudCover Cloud shape blend time in seconds
 
144
                 */
 
145
                void setCloudBlendTime (const Ogre::Real cloudBlendTime);
 
146
 
 
147
                /** Gets the time it takes to blend two cloud shaped together, in seconds.
 
148
                 *  @return Cloud shape blend time in seconds
 
149
                 */
 
150
                Ogre::Real getCloudBlendTime () const;
 
151
 
 
152
        private:
 
153
                /// Shortcut function for fragment program parameters
 
154
                Ogre::GpuProgramParametersSharedPtr getFpParams();
 
155
 
 
156
                /// Shortcut function for fragment program parameters
 
157
                Ogre::GpuProgramParametersSharedPtr getVpParams();
 
158
 
 
159
                /// Shortcut function for texture unit state parameters
 
160
                Ogre::TextureUnitState* getTUS(unsigned short num);
 
161
                
 
162
                /// Set the sunDirection parameter in the shaders.
 
163
                void setSunDirection(const Ogre::Vector3 &sunDirection);
 
164
 
 
165
                /// Set the sunColour parameter in the shaders.
 
166
                void setSunColour(const Ogre::ColourValue &sunColour);
 
167
 
 
168
                /// Set the fogColour parameter in the shaders.
 
169
                void setFogColour(const Ogre::ColourValue &fogColour);
 
170
 
 
171
                /// Sets inverse Haze height.
 
172
                void setInvHazeHeight (const Ogre::Real invHazeHeight);
 
173
 
 
174
                /// Current cloud coverage
 
175
                Ogre::Real mCloudCover;
 
176
 
 
177
                /// Current cloud blend factor
 
178
                Ogre::Real mCloudMassBlend;
 
179
 
 
180
                /// Current cloud layer offset.
 
181
                Ogre::Vector2 mCloudMassOffset;
 
182
 
 
183
                /// Current cloud detail layer offset.
 
184
                Ogre::Vector2 mCloudDetailOffset;
 
185
 
 
186
        /// Lookup used for cloud coverage.
 
187
        /// see setCloudCoverLookup.
 
188
        std::auto_ptr<Ogre::Image> mCloudCoverLookup;
 
189
 
 
190
 
 
191
                /// If this class controls animation for itself.
 
192
                bool mAnimating;
 
193
 
 
194
                /// Current cloud blend time.
 
195
                Ogre::Real mCloudBlendTime;
 
196
 
 
197
                /** If true then CloudMassBlend is increased in animation; otherwise it's
 
198
                 *  decreased. This is changed each time it reaches the end.
 
199
                 */
 
200
                bool mCloudBlendAnimationDirection;
 
201
 
 
202
                /// Current cloud speed
 
203
                Ogre::Vector2 mCloudSpeed;
 
204
 
 
205
 
 
206
                /// Cloud material
 
207
                Ogre::MaterialPtr mMaterial;
 
208
 
 
209
                /// True if selected technique has shaders.
 
210
                bool mShadersEnabled;
 
211
 
 
212
                /// Cloud plane mesh
 
213
                Ogre::SceneNode *mNode;
 
214
 
 
215
                /// Cloud plane entity
 
216
                Ogre::Entity *mEntity;
 
217
 
 
218
                /// Reference to scene manager.
 
219
                Ogre::SceneManager *mSceneMgr;
 
220
 
 
221
    public:
 
222
                /// Handle camera change.
 
223
                virtual void notifyCameraChanged (Ogre::Camera *cam);
 
224
 
 
225
    protected:
 
226
        /// Handle far radius.
 
227
            virtual void setFarRadius (Ogre::Real radius);
 
228
};
 
229
}  // namespace caelum
 
230
 
 
231
#endif // LAYEREDCLOUDS_H