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 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.
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.
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.
31 # error This library requires C++
35 #include <plib/ssg.h> // plib include
37 #include <simgear/compiler.h>
38 #include <simgear/misc/fgpath.hxx>
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>
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;
60 // components of the sky
66 ssgSimpleState *cloud_mats[SG_MAX_CLOUD_TYPES];
67 layer_list_type cloud_layers;
69 ssgRoot *pre_root, *post_root;
71 ssgSelector *pre_selector, *post_selector;
72 ssgTransform *pre_transform, *post_transform;
78 float effective_visibility;
80 // near cloud visibility state variables
82 double puff_length; // in seconds
83 double puff_progression; // in seconds
84 double ramp_up; // in seconds
85 double ramp_down; // in seconds
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 );
101 // repaint the sky components based on current value of sun_angle,
102 // sky, and fog colors.
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 );
113 // reposition the sky at the specified origin and orientation
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,
123 double sun_ra, double sun_dec, double sun_dist,
124 double moon_ra, double moon_dec, double moon_dist );
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 );
130 // draw background portions of the sky ... do this before you draw
131 // the rest of your scene.
134 // draw translucent clouds ... do this after you've drawn all the
135 // oapaque elements of your scene.
136 void postDraw( float alt );
138 // specify the texture path (optional, defaults to current directory)
139 inline void texture_path( const string& path ) {
140 tex_path = FGPath( path );
144 inline void enable() {
145 pre_selector->select( 1 );
146 post_selector->select( 1 );
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 );
156 // add a cloud layer (above sea level in meters)
157 void add_cloud_layer( double asl, double thickness,
158 double transition, double span,
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 );
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];
172 inline float get_visibility() const { return effective_visibility; }
173 inline void set_visibility( float v ) {
174 effective_visibility = visibility = v;
179 #endif // _SG_SKY_HXX