]> git.mxchange.org Git - simgear.git/blob - simgear/sky/sky.hxx
Tweaks to follow flightgear STL standard coding procedure.
[simgear.git] / simgear / sky / sky.hxx
1 // sky.hxx -- ssg based sky model
2 //
3 // Written by Curtis Olson, started December 1997.
4 // SSG-ified by Curtis Olson, February 2000.
5 //
6 // Copyright (C) 1997-2000  Curtis L. Olson  - curt@flightgear.org
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // Library General Public License for more details.
17 //
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the
20 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 // Boston, MA  02111-1307, USA.
22 //
23 // $Id$
24
25
26 #ifndef _SG_SKY_HXX
27 #define _SG_SKY_HXX
28
29
30 #ifndef __cplusplus                                                          
31 # error This library requires C++
32 #endif                                   
33
34
35 #include <plib/ssg.h>           // plib include
36
37 #include <simgear/compiler.h>
38 #include <simgear/misc/fgpath.hxx>
39
40 #include <vector>
41
42 #include <simgear/sky/cloud.hxx>
43 #include <simgear/sky/dome.hxx>
44 #include <simgear/sky/moon.hxx>
45 #include <simgear/sky/oursun.hxx>
46 #include <simgear/sky/stars.hxx>
47
48 FG_USING_STD(vector);
49
50
51 typedef vector < SGCloudLayer* > layer_list_type;
52 typedef layer_list_type::iterator layer_list_iterator;
53 typedef layer_list_type::const_iterator layer_list_const_iterator;
54
55
56 class SGSky {
57
58 private:
59
60     // components of the sky
61     SGSkyDome *dome;
62     SGSun *oursun;
63     SGMoon *moon;
64     SGStars *planets;
65     SGStars *stars;
66     ssgSimpleState *cloud_mats[SG_MAX_CLOUD_TYPES];
67     layer_list_type cloud_layers;
68
69     ssgRoot *pre_root, *post_root;
70
71     ssgSelector *pre_selector, *post_selector;
72     ssgTransform *pre_transform, *post_transform;
73
74     FGPath tex_path;
75
76     // visibility
77     float visibility;
78     float effective_visibility;
79
80     // near cloud visibility state variables
81     bool in_puff;
82     double puff_length;         // in seconds
83     double puff_progression;    // in seconds
84     double ramp_up;             // in seconds
85     double ramp_down;           // in seconds
86
87 public:
88
89     // Constructor
90     SGSky( void );
91
92     // Destructor
93     ~SGSky( void );
94
95     // initialize the sky and connect the components to the scene
96     // graph at the provided branch
97     void build( double sun_size, double moon_size,
98                 int nplanets, sgdVec3 *planet_data, double planet_dist,
99                 int nstars, sgdVec3 *star_data, double star_dist );
100
101     // repaint the sky components based on current value of sun_angle,
102     // sky, and fog colors.
103     //
104     // sun angle in degrees relative to verticle
105     // 0 degrees = high noon
106     // 90 degrees = sun rise/set
107     // 180 degrees = darkest midnight
108     bool repaint( sgVec4 sky_color, sgVec4 fog_color,
109                   double sun_angle, double moon_angle,
110                   int nplanets, sgdVec3 *planet_data,
111                   int nstars, sgdVec3 *star_data );
112
113     // reposition the sky at the specified origin and orientation
114     //
115     // lon specifies a rotation about the Z axis
116     // lat specifies a rotation about the new Y axis
117     // spin specifies a rotation about the new Z axis (this allows
118     // additional orientation for the sunrise/set effects and is used
119     // by the skydome and perhaps clouds.
120     bool reposition( sgVec3 view_pos, sgVec3 zero_elev, sgVec3 view_up,
121                      double lon, double lat, double alt, double spin,
122                      double gst, 
123                      double sun_ra, double sun_dec, double sun_dist,
124                      double moon_ra, double moon_dec, double moon_dist );
125
126     // modify the given visibility based on cloud layers, thickness,
127     // transition range, and simulated "puffs".
128     void modify_vis( float alt, float time_factor );
129
130     // draw background portions of the sky ... do this before you draw
131     // the rest of your scene.
132     void preDraw();
133
134     // draw translucent clouds ... do this after you've drawn all the
135     // oapaque elements of your scene.
136     void postDraw( float alt );
137
138     // specify the texture path (optional, defaults to current directory)
139     inline void texture_path( const string& path ) {
140         tex_path = FGPath( path );
141     }
142
143     // enable the sky
144     inline void enable() {
145         pre_selector->select( 1 );
146         post_selector->select( 1 );
147     }
148
149     // disable the sky in the scene graph.  The leaf node is still
150     // there, how ever it won't be traversed on by ssgCullandRender()
151     inline void disable() {
152         pre_selector->select( 0 );
153         post_selector->select( 0 );
154     }
155
156     // add a cloud layer (above sea level in meters)
157     void add_cloud_layer( double asl, double thickness,
158                           double transition, double span,
159                           SGCloudType type );
160     void add_cloud_layer( double asl, double thickness,
161                           double transition, double span,
162                           const string &tex_path );
163     void add_cloud_layer( double asl, double thickness,
164                           double transition, double span,
165                           ssgSimpleState *state );
166
167     inline int get_num_layers() const { return cloud_layers.size(); }
168     inline SGCloudLayer *get_cloud_layer( int i ) const {
169         return cloud_layers[i];
170     }
171
172     inline float get_visibility() const { return effective_visibility; }
173     inline void set_visibility( float v ) {
174         effective_visibility = visibility = v;
175     }
176 };
177
178
179 #endif // _SG_SKY_HXX
180
181