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