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 Library General Public
21 // License along with this library; if not, write to the
22 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 // Boston, MA 02111-1307, USA.
28 #ifndef _SG_CLOUD_HXX_
29 #define _SG_CLOUD_HXX_
31 #include <simgear/compiler.h>
38 // #include <iostream>
39 // SG_USING_STD(cout);
40 // SG_USING_STD(endl);
45 * A class layer to model a single cloud layer
51 * This is the list of available cloud coverages/textures
54 SG_CLOUD_OVERCAST = 0,
60 SG_MAX_CLOUD_COVERAGES
65 * @param tex_path the path to the set of cloud textures
67 SGCloudLayer( const string &tex_path );
72 ~SGCloudLayer( void );
74 /** get the cloud span (in meters) */
75 float getSpan_m () const;
78 * @param span_m the cloud span in meters
80 void setSpan_m (float span_m);
82 /** get the layer elevation (in meters) */
83 float getElevation_m () const;
85 * set the layer elevation. Note that this specifies the bottom
86 * of the cloud layer. The elevation of the top of the layer is
87 * elevation_m + thickness_m.
88 * @param elevation_m the layer elevation in meters
89 * @param set_span defines whether it is allowed to adjust the span
91 void setElevation_m (float elevation_m, bool set_span = true);
93 /** get the layer thickness */
94 float getThickness_m () const;
96 * set the layer thickness.
97 * @param thickness_m the layer thickness in meters.
99 void setThickness_m (float thickness_m);
102 * get the transition/boundary layer depth in meters. This
103 * allows gradual entry/exit from the cloud layer via adjusting
106 float getTransition_m () const;
109 * set the transition layer size in meters
110 * @param transition_m the transition layer size in meters
112 void setTransition_m (float transition_m);
114 /** get coverage type */
115 Coverage getCoverage () const;
119 * @param coverage the coverage type
121 void setCoverage (Coverage coverage);
124 * set the cloud movement direction
125 * @param dir the cloud movement direction
127 inline void setDirection(float dir) {
128 // cout << "cloud dir = " << dir << endl;
132 /** get the cloud movement direction */
133 inline float getDirection() { return direction; }
136 * set the cloud movement speed
137 * @param sp the cloud movement speed
139 inline void setSpeed(float sp) {
140 // cout << "cloud speed = " << sp << endl;
144 /** get the cloud movement speed */
145 inline float getSpeed() { return speed; }
148 * set the alpha component of the cloud base color. Normally this
149 * should be 1.0, but you can set it anywhere in the range of 0.0
150 * to 1.0 to fade a cloud layer in or out.
151 * @param alpha cloud alpha value (0.0 to 1.0)
153 inline void setAlpha( float alpha ) {
154 if ( alpha < 0.0 ) { alpha = 0.0; }
155 if ( alpha > 1.0 ) { alpha = 1.0; }
159 /** build the cloud object */
163 * repaint the cloud colors based on the specified fog_color
164 * @param fog_color the fog color
166 bool repaint( sgVec3 fog_color );
169 * reposition the cloud layer at the specified origin and
171 * @param p position vector
172 * @param up the local up vector
173 * @param lon specifies a rotation about the Z axis
174 * @param lat specifies a rotation about the new Y axis
175 * @param spin specifies a rotation about the new Z axis
176 * (and orients the sunrise/set effects)
177 * @param dt the time elapsed since the last call
179 bool reposition( sgVec3 p, sgVec3 up, double lon, double lat, double alt,
182 /** draw the cloud layer */
183 void draw( bool top );
185 static bool enable_bump_mapping;
192 sgVec3 tangentSpLight;
199 CloudVertex *vertices;
200 unsigned int *indices;
203 ssgTransform *layer_transform;
205 ssgStateSelector *state_sel;
207 float cloud_alpha; // 1.0 = drawn fully, 0.0 faded out completely
209 ssgColourArray *cl[4];
210 ssgVertexArray *vl[4];
211 ssgTexCoordArray *tl[4];
213 // height above sea level (meters)
217 float layer_thickness;
218 float layer_transition;
219 Coverage layer_coverage;
224 // for handling texture coordinates to simulate cloud movement
225 // from winds, and to simulate the clouds being tied to ground
226 // position, not view position
227 // double xoff, yoff;
228 double last_lon, last_lat, last_course;
230 SGCloudField *layer3D;
234 // make an ssgSimpleState for a cloud layer given the named texture
235 ssgSimpleState *sgCloudMakeState( const string &path );
238 #endif // _SG_CLOUD_HXX_