]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/cloud.hxx
My old email address is no longer valid ... point to my web page.
[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
43 /**
44  * A class layer to model a single cloud layer
45  */
46 class SGCloudLayer {
47 public:
48
49     /**
50      * This is the list of available cloud coverages/textures
51      */
52     enum Coverage {
53         SG_CLOUD_OVERCAST = 0,
54         SG_CLOUD_BROKEN,
55         SG_CLOUD_SCATTERED,
56         SG_CLOUD_FEW,
57         SG_CLOUD_CIRRUS,
58         SG_CLOUD_CLEAR,
59         SG_MAX_CLOUD_COVERAGES
60     };
61
62     /**
63      * Constructor
64      * @param tex_path the path to the set of cloud textures
65      */
66     SGCloudLayer( const string &tex_path );
67
68     /**
69      * Destructor
70      */
71     ~SGCloudLayer( void );
72
73     /** get the cloud span (in meters) */
74     float getSpan_m () const;
75     /**
76      * set the cloud span
77      * @param span_m the cloud span in meters
78      */
79     void setSpan_m (float span_m);
80
81     /** get the layer elevation (in meters) */
82     float getElevation_m () const;
83     /**
84      * set the layer elevation.  Note that this specifies the bottom
85      * of the cloud layer.  The elevation of the top of the layer is
86      * elevation_m + thickness_m.
87      * @param elevation_m the layer elevation in meters
88      * @param set_span defines whether it is allowed to adjust the span
89      */
90     void setElevation_m (float elevation_m, bool set_span = true);
91
92     /** get the layer thickness */
93     float getThickness_m () const;
94     /**
95      * set the layer thickness.
96      * @param thickness_m the layer thickness in meters.
97      */
98     void setThickness_m (float thickness_m);
99
100     /**
101      * get the transition/boundary layer depth in meters.  This
102      * allows gradual entry/exit from the cloud layer via adjusting
103      * visibility.
104      */
105     float getTransition_m () const;
106
107     /**
108      * set the transition layer size in meters
109      * @param transition_m the transition layer size in meters
110      */
111     void setTransition_m (float transition_m);
112
113     /** get coverage type */
114     Coverage getCoverage () const;
115
116     /**
117      * set coverage type
118      * @param coverage the coverage type
119      */
120     void setCoverage (Coverage coverage);
121
122     /**
123      * set the cloud movement direction
124      * @param dir the cloud movement direction
125      */
126     inline void setDirection(float dir) { 
127         // cout << "cloud dir = " << dir << endl;
128         direction = dir;
129     }
130
131     /** get the cloud movement direction */
132     inline float getDirection() { return direction; }
133
134     /**
135      * set the cloud movement speed 
136      * @param sp the cloud movement speed
137      */
138     inline void setSpeed(float sp) {
139         // cout << "cloud speed = " << sp << endl;
140         speed = sp;
141     }
142
143     /** get the cloud movement speed */
144     inline float getSpeed() { return speed; }
145
146     /** build the cloud object */
147     void rebuild();
148
149     /**
150      * repaint the cloud colors based on the specified fog_color
151      * @param fog_color the fog color
152      */
153     bool repaint( sgVec3 fog_color );
154
155     /**
156      * reposition the cloud layer at the specified origin and
157      * orientation.
158      * @param p position vector
159      * @param up the local up vector
160      * @param lon specifies a rotation about the Z axis
161      * @param lat specifies a rotation about the new Y axis
162      * @param spin specifies a rotation about the new Z axis
163      *        (and orients the sunrise/set effects)
164      * @param dt the time elapsed since the last call
165      */
166     bool reposition( sgVec3 p, sgVec3 up, double lon, double lat, double alt,
167                      double dt = 0.0 );
168
169     /** draw the cloud layer */
170     void draw( bool top );
171
172     static bool enable_bump_mapping;
173
174 private:
175
176     struct CloudVertex {
177         sgVec3 position;
178         sgVec2 texCoord;
179         sgVec3 tangentSpLight;
180         sgVec3 sTangent;
181         sgVec3 tTangent;
182         sgVec3 normal;
183         sgVec4 color;
184     };
185
186     CloudVertex *vertices;
187     unsigned int *indices;
188
189     ssgRoot *layer_root;
190     ssgTransform *layer_transform;
191     ssgLeaf *layer[4];
192     ssgStateSelector *state_sel;
193
194     ssgColourArray *cl[4]; 
195     ssgVertexArray *vl[4];
196     ssgTexCoordArray *tl[4];
197
198     // height above sea level (meters)
199     SGPath texture_path;
200     float layer_span;
201     float layer_asl;
202     float layer_thickness;
203     float layer_transition;
204     Coverage layer_coverage;
205     float scale;
206     float speed;
207     float direction;
208
209     // for handling texture coordinates to simulate cloud movement
210     // from winds, and to simulate the clouds being tied to ground
211     // position, not view position
212     // double xoff, yoff;
213     double last_lon, last_lat, last_course;
214 };
215
216
217 // make an ssgSimpleState for a cloud layer given the named texture
218 ssgSimpleState *sgCloudMakeState( const string &path );
219
220
221 #endif // _SG_CLOUD_HXX_