]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/cloud.hxx
Harald JOHNSEN:
[simgear.git] / simgear / scene / sky / cloud.hxx
1 /**
2  * \file cloud.hxx
3  * Provides a class to model a single cloud layer
4  */
5
6 // Written by Curtis Olson, started June 2000.
7 //
8 // Copyright (C) 2000  Curtis L. Olson  - http://www.flightgear.org/~curt
9 //
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.
14 //
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.
19 //
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.
24 //
25 // $Id$
26
27
28 #ifndef _SG_CLOUD_HXX_
29 #define _SG_CLOUD_HXX_
30
31 #include <simgear/compiler.h>
32
33 #include <plib/ssg.h>
34
35 #include STL_STRING
36 SG_USING_STD(string);
37
38 // #include <iostream>
39 // SG_USING_STD(cout);
40 // SG_USING_STD(endl);
41
42 class SGCloudField;
43
44 /**
45  * A class layer to model a single cloud layer
46  */
47 class SGCloudLayer {
48 public:
49
50     /**
51      * This is the list of available cloud coverages/textures
52      */
53     enum Coverage {
54         SG_CLOUD_OVERCAST = 0,
55         SG_CLOUD_BROKEN,
56         SG_CLOUD_SCATTERED,
57         SG_CLOUD_FEW,
58         SG_CLOUD_CIRRUS,
59         SG_CLOUD_CLEAR,
60         SG_MAX_CLOUD_COVERAGES
61     };
62
63     /**
64      * Constructor
65      * @param tex_path the path to the set of cloud textures
66      */
67     SGCloudLayer( const string &tex_path );
68
69     /**
70      * Destructor
71      */
72     ~SGCloudLayer( void );
73
74     /** get the cloud span (in meters) */
75     float getSpan_m () const;
76     /**
77      * set the cloud span
78      * @param span_m the cloud span in meters
79      */
80     void setSpan_m (float span_m);
81
82     /** get the layer elevation (in meters) */
83     float getElevation_m () const;
84     /**
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
90      */
91     void setElevation_m (float elevation_m, bool set_span = true);
92
93     /** get the layer thickness */
94     float getThickness_m () const;
95     /**
96      * set the layer thickness.
97      * @param thickness_m the layer thickness in meters.
98      */
99     void setThickness_m (float thickness_m);
100
101     /**
102      * get the transition/boundary layer depth in meters.  This
103      * allows gradual entry/exit from the cloud layer via adjusting
104      * visibility.
105      */
106     float getTransition_m () const;
107
108     /**
109      * set the transition layer size in meters
110      * @param transition_m the transition layer size in meters
111      */
112     void setTransition_m (float transition_m);
113
114     /** get coverage type */
115     Coverage getCoverage () const;
116
117     /**
118      * set coverage type
119      * @param coverage the coverage type
120      */
121     void setCoverage (Coverage coverage);
122
123     /**
124      * set the cloud movement direction
125      * @param dir the cloud movement direction
126      */
127     inline void setDirection(float dir) { 
128         // cout << "cloud dir = " << dir << endl;
129         direction = dir;
130     }
131
132     /** get the cloud movement direction */
133     inline float getDirection() { return direction; }
134
135     /**
136      * set the cloud movement speed 
137      * @param sp the cloud movement speed
138      */
139     inline void setSpeed(float sp) {
140         // cout << "cloud speed = " << sp << endl;
141         speed = sp;
142     }
143
144     /** get the cloud movement speed */
145     inline float getSpeed() { return speed; }
146
147     /**
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)
152      */
153     inline void setAlpha( float alpha ) {
154         if ( alpha < 0.0 ) { alpha = 0.0; }
155         if ( alpha > 1.0 ) { alpha = 1.0; }
156         cloud_alpha = alpha;
157     }
158
159     /** build the cloud object */
160     void rebuild();
161
162     /**
163      * repaint the cloud colors based on the specified fog_color
164      * @param fog_color the fog color
165      */
166     bool repaint( sgVec3 fog_color );
167
168     /**
169      * reposition the cloud layer at the specified origin and
170      * orientation.
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
178      */
179     bool reposition( sgVec3 p, sgVec3 up, double lon, double lat, double alt,
180                      double dt = 0.0 );
181
182     /** draw the cloud layer */
183     void draw( bool top );
184
185     static bool enable_bump_mapping;
186
187         /** return the 3D layer cloud associated with this 2D layer */
188         SGCloudField *get_layer3D(void) { return layer3D; }
189
190 private:
191
192     struct CloudVertex {
193         sgVec3 position;
194         sgVec2 texCoord;
195         sgVec3 tangentSpLight;
196         sgVec3 sTangent;
197         sgVec3 tTangent;
198         sgVec3 normal;
199         sgVec4 color;
200     };
201
202     CloudVertex *vertices;
203     unsigned int *indices;
204
205     ssgRoot *layer_root;
206     ssgTransform *layer_transform;
207     ssgLeaf *layer[4];
208     ssgStateSelector *state_sel;
209
210     float cloud_alpha;          // 1.0 = drawn fully, 0.0 faded out completely
211
212     ssgColourArray *cl[4]; 
213     ssgVertexArray *vl[4];
214     ssgTexCoordArray *tl[4];
215
216     // height above sea level (meters)
217     SGPath texture_path;
218     float layer_span;
219     float layer_asl;
220     float layer_thickness;
221     float layer_transition;
222     Coverage layer_coverage;
223     float scale;
224     float speed;
225     float direction;
226
227     // for handling texture coordinates to simulate cloud movement
228     // from winds, and to simulate the clouds being tied to ground
229     // position, not view position
230     // double xoff, yoff;
231     double last_lon, last_lat, last_course;
232
233         SGCloudField *layer3D;
234 };
235
236
237 // make an ssgSimpleState for a cloud layer given the named texture
238 ssgSimpleState *sgCloudMakeState( const string &path );
239
240
241 #endif // _SG_CLOUD_HXX_