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