1 // sky.hxx -- ssg based sky model
3 // Written by Curtis Olson, started December 1997.
4 // SSG-ified by Curtis Olson, February 2000.
6 // Copyright (C) 1997-2000 Curtis L. Olson - curt@flightgear.org
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.
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.
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.
30 # error This library requires C++
34 #include <plib/ssg.h> // plib include
36 #include <simgear/compiler.h>
37 #include <simgear/misc/fgpath.hxx>
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;
59 // components of the sky
65 ssgSimpleState *cloud_mats[SG_MAX_CLOUD_TYPES];
66 layer_list_type cloud_layers;
68 ssgRoot *pre_root, *post_root;
70 ssgSelector *pre_selector, *post_selector;
71 ssgTransform *pre_transform, *post_transform;
77 float effective_visibility;
79 // near cloud visibility state variables
82 double puff_progression;
94 // initialize the sky and connect the components to the scene
95 // graph at the provided branch
96 void build( double sun_size, double moon_size,
97 int nplanets, sgdVec3 *planet_data, double planet_dist,
98 int nstars, sgdVec3 *star_data, double star_dist );
100 // repaint the sky components based on current value of sun_angle,
101 // sky, and fog colors.
103 // sun angle in degrees relative to verticle
104 // 0 degrees = high noon
105 // 90 degrees = sun rise/set
106 // 180 degrees = darkest midnight
107 bool repaint( sgVec4 sky_color, sgVec4 fog_color,
108 double sun_angle, double moon_angle,
109 int nplanets, sgdVec3 *planet_data,
110 int nstars, sgdVec3 *star_data );
112 // reposition the sky at the specified origin and orientation
114 // lon specifies a rotation about the Z axis
115 // lat specifies a rotation about the new Y axis
116 // spin specifies a rotation about the new Z axis (this allows
117 // additional orientation for the sunrise/set effects and is used
118 // by the skydome and perhaps clouds.
119 bool reposition( sgVec3 view_pos, sgVec3 zero_elev, sgVec3 view_up,
120 double lon, double lat, double alt, double spin,
122 double sun_ra, double sun_dec, double sun_dist,
123 double moon_ra, double moon_dec, double moon_dist );
125 // modify the given visibility based on cloud layers, thickness,
126 // transition range, and simulated "puffs".
127 void modify_vis( float alt, float time_factor );
129 // draw background portions of the sky
130 void draw_background();
132 // draw scenery elements of the sky
133 void draw_scene( float alt );
135 // specify the texture path (optional, defaults to current directory)
136 inline void texture_path( const string& path ) {
137 tex_path = FGPath( path );
141 inline void enable() {
142 pre_selector->select( 1 );
143 post_selector->select( 1 );
146 // disable the sky in the scene graph. The leaf node is still
147 // there, how ever it won't be traversed on by ssgCullandRender()
148 inline void disable() {
149 pre_selector->select( 0 );
150 post_selector->select( 0 );
153 // add a cloud layer (above sea level in meters)
154 void add_cloud_layer( double asl, double thickness, double transition,
156 void add_cloud_layer( double asl, double thickness, double transition,
157 const string &tex_path );
158 void add_cloud_layer( double asl, double thickness, double transition,
159 ssgSimpleState *state );
161 inline int get_num_layers() const { return cloud_layers.size(); }
162 inline SGCloudLayer *get_cloud_layer( int i ) const {
163 return cloud_layers[i];
166 inline float get_visibility() const { return effective_visibility; }
167 inline void set_visibility( float v ) {
168 effective_visibility = visibility = v;
173 #endif // _SG_SKY_HXX