3 * Provides a class to model a single cloud layer
6 // Written by Curtis Olson, started June 2000.
8 // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Library General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Library General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #ifndef _SG_CLOUD_HXX_
28 #define _SG_CLOUD_HXX_
30 #include <simgear/compiler.h>
31 #include <simgear/misc/sg_path.hxx>
32 #include <simgear/math/SGMath.hxx>
33 #include <simgear/structure/SGReferenced.hxx>
38 #include <osg/ref_ptr>
42 #include <osg/MatrixTransform>
48 * A class layer to model a single cloud layer
50 class SGCloudLayer : public SGReferenced {
54 * This is the list of available cloud coverages/textures
57 SG_CLOUD_OVERCAST = 0,
63 SG_MAX_CLOUD_COVERAGES
66 static const std::string SG_CLOUD_OVERCAST_STRING; // "overcast"
67 static const std::string SG_CLOUD_BROKEN_STRING; // "broken"
68 static const std::string SG_CLOUD_SCATTERED_STRING; // "scattered"
69 static const std::string SG_CLOUD_FEW_STRING; // "few"
70 static const std::string SG_CLOUD_CIRRUS_STRING; // "cirrus"
71 static const std::string SG_CLOUD_CLEAR_STRING; // "clear"
75 * @param tex_path the path to the set of cloud textures
77 SGCloudLayer( const string &tex_path );
82 ~SGCloudLayer( void );
84 /** get the cloud span (in meters) */
85 float getSpan_m () const;
88 * @param span_m the cloud span in meters
90 void setSpan_m (float span_m);
92 /** get the layer elevation (in meters) */
93 float getElevation_m () const;
95 * set the layer elevation. Note that this specifies the bottom
96 * of the cloud layer. The elevation of the top of the layer is
97 * elevation_m + thickness_m.
98 * @param elevation_m the layer elevation in meters
99 * @param set_span defines whether it is allowed to adjust the span
101 void setElevation_m (float elevation_m, bool set_span = true);
103 /** get the layer thickness */
104 float getThickness_m () const;
106 * set the layer thickness.
107 * @param thickness_m the layer thickness in meters.
109 void setThickness_m (float thickness_m);
112 * get the transition/boundary layer depth in meters. This
113 * allows gradual entry/exit from the cloud layer via adjusting
116 float getTransition_m () const;
119 * set the transition layer size in meters
120 * @param transition_m the transition layer size in meters
122 void setTransition_m (float transition_m);
124 /** get coverage type */
125 Coverage getCoverage () const;
129 * @param coverage the coverage type
131 void setCoverage (Coverage coverage);
133 /** get coverage as string */
134 const string & getCoverageString() const;
136 /** get coverage as string */
137 static const string & getCoverageString( Coverage coverage );
139 /** get coverage type from string */
140 static Coverage getCoverageType( const std::string & coverage );
142 /** set coverage as string */
143 void setCoverageString( const string & coverage );
146 * set the cloud movement direction
147 * @param dir the cloud movement direction
149 inline void setDirection(float dir) {
150 // cout << "cloud dir = " << dir << endl;
154 /** get the cloud movement direction */
155 inline float getDirection() { return direction; }
158 * set the cloud movement speed
159 * @param sp the cloud movement speed
161 inline void setSpeed(float sp) {
162 // cout << "cloud speed = " << sp << endl;
166 /** get the cloud movement speed */
167 inline float getSpeed() { return speed; }
170 * set the alpha component of the cloud base color. Normally this
171 * should be 1.0, but you can set it anywhere in the range of 0.0
172 * to 1.0 to fade a cloud layer in or out.
173 * @param alpha cloud alpha value (0.0 to 1.0)
175 inline void setAlpha( float alpha ) {
176 if ( alpha < 0.0 ) { alpha = 0.0; }
177 if ( alpha > 1.0 ) { alpha = 1.0; }
181 /** build the cloud object */
184 /** Enable/disable 3D clouds in this layer */
185 void set_enable3dClouds(bool enable);
188 * repaint the cloud colors based on the specified fog_color
189 * @param fog_color the fog color
191 bool repaint( const SGVec3f& fog_color );
194 * reposition the cloud layer at the specified origin and
196 * @param p position vector
197 * @param up the local up vector
198 * @param lon specifies a rotation about the Z axis
199 * @param lat specifies a rotation about the new Y axis
200 * @param spin specifies a rotation about the new Z axis
201 * (and orients the sunrise/set effects)
202 * @param dt the time elapsed since the last call
204 bool reposition( const SGVec3f& p, const SGVec3f& up,
205 double lon, double lat, double alt,
208 osg::Switch* getNode() { return cloud_root.get(); }
210 static bool enable_bump_mapping;
212 /** return the 3D layer cloud associated with this 2D layer */
213 SGCloudField *get_layer3D(void) { return layer3D; }
216 void setTextureOffset(const osg::Vec2& offset);
219 osg::ref_ptr<osg::Switch> cloud_root;
220 osg::ref_ptr<osg::Switch> layer_root;
221 osg::ref_ptr<osg::Group> group_top, group_bottom;
222 osg::ref_ptr<osg::MatrixTransform> layer_transform;
223 osg::ref_ptr<osg::Geode> layer[4];
225 float cloud_alpha; // 1.0 = drawn fully, 0.0 faded out completely
227 osg::ref_ptr<osg::Vec4Array> cl[4];
228 osg::ref_ptr<osg::Vec3Array> vl[4];
229 osg::ref_ptr<osg::Vec2Array> tl[4];
230 osg::ref_ptr<osg::Vec3Array> tl2[4];
232 // height above sea level (meters)
236 float layer_thickness;
237 float layer_transition;
238 Coverage layer_coverage;
243 // for handling texture coordinates to simulate cloud movement
244 // from winds, and to simulate the clouds being tied to ground
245 // position, not view position
246 // double xoff, yoff;
252 SGCloudField *layer3D;
256 #endif // _SG_CLOUD_HXX_