Moving cloud functionality to sky section.

This commit is contained in:
curt 2000-06-20 00:30:30 +00:00
parent 487bee35ab
commit c2b84db5a2
3 changed files with 98 additions and 24 deletions

View File

@ -1,6 +1,7 @@
noinst_LIBRARIES = libSky.a noinst_LIBRARIES = libSky.a
libSky_a_SOURCES = \ libSky_a_SOURCES = \
cloud.cxx cloud.hxx \
dome.cxx dome.hxx \ dome.cxx dome.hxx \
moon.cxx moon.hxx \ moon.cxx moon.hxx \
oursun.cxx oursun.hxx \ oursun.cxx oursun.hxx \

View File

@ -43,35 +43,45 @@ SGSky::~SGSky( void ) {
// initialize the sky and connect the components to the scene graph at // initialize the sky and connect the components to the scene graph at
// the provided branch // the provided branch
ssgBranch * SGSky::build( double sun_size, double moon_size, void SGSky::build( double sun_size, double moon_size,
int nplanets, sgdVec3 *planet_data, int nplanets, sgdVec3 *planet_data,
double planet_dist, double planet_dist,
int nstars, sgdVec3 *star_data, double star_dist ) int nstars, sgdVec3 *star_data, double star_dist )
{ {
sky_selector = new ssgSelector; pre_root = new ssgRoot;
sky_transform = new ssgTransform; post_root = new ssgRoot;
pre_selector = new ssgSelector;
post_selector = new ssgSelector;
pre_transform = new ssgTransform;
post_transform = new ssgTransform;
dome = new SGSkyDome; dome = new SGSkyDome;
sky_transform -> addKid( dome->build() ); pre_transform -> addKid( dome->build() );
planets = new SGStars; planets = new SGStars;
sky_transform -> addKid( planets->build(nplanets, planet_data, pre_transform -> addKid( planets->build(nplanets, planet_data,
planet_dist) planet_dist)
); );
stars = new SGStars; stars = new SGStars;
sky_transform -> addKid( stars->build(nstars, star_data, star_dist) ); pre_transform -> addKid( stars->build(nstars, star_data, star_dist) );
moon = new SGMoon; moon = new SGMoon;
sky_transform -> addKid( moon->build(tex_path, moon_size) ); pre_transform -> addKid( moon->build(tex_path, moon_size) );
oursun = new SGSun; oursun = new SGSun;
sky_transform -> addKid( oursun->build(tex_path, sun_size) ); pre_transform -> addKid( oursun->build(tex_path, sun_size) );
sky_selector->addKid( sky_transform ); pre_selector->addKid( pre_transform );
sky_selector->clrTraversalMaskBits( SSGTRAV_HOT ); pre_selector->clrTraversalMaskBits( SSGTRAV_HOT );
return sky_selector; post_selector->addKid( post_transform );
post_selector->clrTraversalMaskBits( SSGTRAV_HOT );
pre_root->addKid( pre_selector );
post_root->addKid( post_selector );
} }
@ -93,6 +103,10 @@ bool SGSky::repaint( sgVec4 sky_color, sgVec4 fog_color,
planets->repaint( sun_angle, nplanets, planet_data ); planets->repaint( sun_angle, nplanets, planet_data );
stars->repaint( sun_angle, nstars, star_data ); stars->repaint( sun_angle, nstars, star_data );
for ( int i = 0; i < (int)cloud_layers.size(); ++i ) {
cloud_layers[i]->repaint( fog_color );
}
return true; return true;
} }
@ -104,7 +118,7 @@ bool SGSky::repaint( sgVec4 sky_color, sgVec4 fog_color,
// spin specifies a rotation about the new Z axis (this allows // spin specifies a rotation about the new Z axis (this allows
// additional orientation for the sunrise/set effects and is used by // additional orientation for the sunrise/set effects and is used by
// the skydome and perhaps clouds. // the skydome and perhaps clouds.
bool SGSky::reposition( sgVec3 view_pos, sgVec3 zero_elev, bool SGSky::reposition( sgVec3 view_pos, sgVec3 zero_elev, sgVec3 view_up,
double lon, double lat, double spin, double lon, double lat, double spin,
double gst, double gst,
double sun_ra, double sun_dec, double sun_dist, double sun_ra, double sun_dec, double sun_dist,
@ -117,5 +131,28 @@ bool SGSky::reposition( sgVec3 view_pos, sgVec3 zero_elev,
planets->reposition( view_pos, angle ); planets->reposition( view_pos, angle );
stars->reposition( view_pos, angle ); stars->reposition( view_pos, angle );
for ( int i = 0; i < (int)cloud_layers.size(); ++i ) {
cloud_layers[i]->reposition( zero_elev, view_up, lon, lat );
}
return true; return true;
} }
// draw background portions of the sky
void SGSky::draw_background() {
ssgCullAndDraw( pre_root );
}
// draw scenery elements of the sky
void SGSky::draw_scene() {
ssgCullAndDraw( post_root );
}
void SGSky::add_cloud_layer( double asl ) {
SGCloudLayer *layer = new SGCloudLayer;
post_transform -> addKid( layer->build(tex_path, 20000.0f, asl) );
cloud_layers.push_back( layer );
}

View File

@ -33,25 +33,41 @@
#include <plib/ssg.h> // plib include #include <plib/ssg.h> // plib include
#include <simgear/compiler.h>
#include <simgear/misc/fgpath.hxx> #include <simgear/misc/fgpath.hxx>
#include <vector>
#include "cloud.hxx"
#include "dome.hxx" #include "dome.hxx"
#include "moon.hxx" #include "moon.hxx"
#include "oursun.hxx" #include "oursun.hxx"
#include "stars.hxx" #include "stars.hxx"
FG_USING_STD(vector);
typedef vector < SGCloudLayer* > layer_list_type;
typedef layer_list_type::iterator layer_list_iterator;
typedef layer_list_type::const_iterator layer_list_const_iterator;
class SGSky { class SGSky {
private:
// components of the sky // components of the sky
SGSkyDome *dome; SGSkyDome *dome;
SGSun *oursun; SGSun *oursun;
SGMoon *moon; SGMoon *moon;
SGStars *planets; SGStars *planets;
SGStars *stars; SGStars *stars;
layer_list_type cloud_layers;
ssgSelector *sky_selector; ssgRoot *pre_root, *post_root;
ssgTransform *sky_transform;
ssgSelector *pre_selector, *post_selector;
ssgTransform *pre_transform, *post_transform;
FGPath tex_path; FGPath tex_path;
@ -65,9 +81,9 @@ public:
// initialize the sky and connect the components to the scene // initialize the sky and connect the components to the scene
// graph at the provided branch // graph at the provided branch
ssgBranch *build( double sun_size, double moon_size, void build( double sun_size, double moon_size,
int nplanets, sgdVec3 *planet_data, double planet_dist, int nplanets, sgdVec3 *planet_data, double planet_dist,
int nstars, sgdVec3 *star_data, double star_dist ); int nstars, sgdVec3 *star_data, double star_dist );
// repaint the sky components based on current value of sun_angle, // repaint the sky components based on current value of sun_angle,
// sky, and fog colors. // sky, and fog colors.
@ -88,23 +104,43 @@ public:
// spin specifies a rotation about the new Z axis (this allows // spin specifies a rotation about the new Z axis (this allows
// additional orientation for the sunrise/set effects and is used // additional orientation for the sunrise/set effects and is used
// by the skydome and perhaps clouds. // by the skydome and perhaps clouds.
bool reposition( sgVec3 view_pos, sgVec3 zero_elev, bool reposition( sgVec3 view_pos, sgVec3 zero_elev, sgVec3 view_up,
double lon, double lat, double spin, double lon, double lat, double spin,
double gst, double gst,
double sun_ra, double sun_dec, double sun_dist, double sun_ra, double sun_dec, double sun_dist,
double moon_ra, double moon_dec, double moon_dist ); double moon_ra, double moon_dec, double moon_dist );
// draw background portions of the sky
void draw_background();
// draw scenery elements of the sky
void draw_scene();
// specify the texture path (optional, defaults to current directory) // specify the texture path (optional, defaults to current directory)
inline void texture_path( const string& path ) { inline void texture_path( const string& path ) {
tex_path = FGPath( path ); tex_path = FGPath( path );
} }
// enable the sky in the scene graph (default) // enable the sky
inline void enable() { sky_selector->select( 1 ); } inline void enable() {
pre_selector->select( 1 );
post_selector->select( 1 );
}
// disable the sky in the scene graph. The leaf node is still // disable the sky in the scene graph. The leaf node is still
// there, how ever it won't be traversed on by ssgCullandRender() // there, how ever it won't be traversed on by ssgCullandRender()
inline void disable() { sky_selector->select( 0 ); } inline void disable() {
pre_selector->select( 0 );
post_selector->select( 0 );
}
// add a cloud layer (above see level in meters)
void add_cloud_layer( double asl );
inline int get_num_layers() const { return cloud_layers.size(); }
inline SGCloudLayer *get_cloud_layer( int i ) const {
return cloud_layers[i];
}
}; };