From e15ffbc85630ae3ae947812cf2ef59162cce7b6b Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 30 Jun 2000 19:45:24 +0000 Subject: [PATCH] Updates to remove unneeded dependencies on FlightGear and SimGear. --- simgear/sky/cloud.cxx | 44 +++++++++++----------------------------- simgear/sky/cloud.hxx | 21 +++++++++++++------ simgear/sky/dome.cxx | 23 ++++++++++++--------- simgear/sky/moon.cxx | 12 ++++++----- simgear/sky/oursun.cxx | 14 ++++++------- simgear/sky/sky.cxx | 46 +++++++++++++++++++++++++----------------- simgear/sky/sky.hxx | 5 +++++ simgear/sky/sphere.cxx | 7 ++++--- simgear/sky/stars.cxx | 18 ++++++++--------- 9 files changed, 99 insertions(+), 91 deletions(-) diff --git a/simgear/sky/cloud.cxx b/simgear/sky/cloud.cxx index f46db1c5..5d6ec288 100644 --- a/simgear/sky/cloud.cxx +++ b/simgear/sky/cloud.cxx @@ -23,15 +23,13 @@ #include #include +#include #include -#include #include #include #include -#include - #include "cloud.hxx" @@ -46,8 +44,8 @@ SGCloudLayer::~SGCloudLayer( void ) { // build the moon object -void SGCloudLayer::build( FGPath path, double s, double asl, double thickness, - double transition, SGCloudType type ) +void SGCloudLayer::build( double s, double asl, double thickness, + double transition, ssgSimpleState *state ) { scale = 4000.0; @@ -58,27 +56,7 @@ void SGCloudLayer::build( FGPath path, double s, double asl, double thickness, size = s; last_lon = last_lat = -999.0f; - // look up the appropriate cloud state - FGNewMat *m; - - switch ( type ) { - case SG_CLOUD_OVERCAST: - m = material_lib.find( "CloudOvercast" ); - layer_state = m->get_state(); - break; - case SG_CLOUD_MOSTLY_CLOUDY: - m = material_lib.find( "CloudMostlyCloudy" ); - layer_state = m->get_state(); - break; - case SG_CLOUD_MOSTLY_SUNNY: - m = material_lib.find( "CloudMostlySunny" ); - layer_state = m->get_state(); - break; - case SG_CLOUD_CIRRUS: - m = material_lib.find( "CloudCirrus" ); - layer_state = m->get_state(); - break; - } + layer_state = state; cl = new ssgColourArray( 4 ); vl = new ssgVertexArray( 4 ); @@ -183,15 +161,17 @@ bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat, // zero_elev.x, zero_elev.y, zero_elev.z ); // Rotate to proper orientation - // printf(" lon = %.2f lat = %.2f\n", FG_Longitude * RAD_TO_DEG, - // FG_Latitude * RAD_TO_DEG); - // xglRotatef( f->get_Longitude() * RAD_TO_DEG, 0.0, 0.0, 1.0 ); + // printf(" lon = %.2f lat = %.2f\n", + // FG_Longitude * SGD_RADIANS_TO_DEGREES, + // FG_Latitude * SGD_RADIANS_TO_DEGREES); + // xglRotatef( f->get_Longitude() * SGD_RADIANS_TO_DEGREES, 0.0, 0.0, 1.0 ); sgSetVec3( axis, 0.0, 0.0, 1.0 ); - sgMakeRotMat4( LON, lon * RAD_TO_DEG, axis ); + sgMakeRotMat4( LON, lon * SGD_RADIANS_TO_DEGREES, axis ); - // xglRotatef( 90.0 - f->get_Latitude() * RAD_TO_DEG, 0.0, 1.0, 0.0 ); + // xglRotatef( 90.0 - f->get_Latitude() * SGD_RADIANS_TO_DEGREES, + // 0.0, 1.0, 0.0 ); sgSetVec3( axis, 0.0, 1.0, 0.0 ); - sgMakeRotMat4( LAT, 90.0 - lat * RAD_TO_DEG, axis ); + sgMakeRotMat4( LAT, 90.0 - lat * SGD_RADIANS_TO_DEGREES, axis ); sgMat4 TRANSFORM; diff --git a/simgear/sky/cloud.hxx b/simgear/sky/cloud.hxx index 05961c54..cbc425a2 100644 --- a/simgear/sky/cloud.hxx +++ b/simgear/sky/cloud.hxx @@ -24,17 +24,26 @@ #ifndef _SG_CLOUD_HXX_ #define _SG_CLOUD_HXX_ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include #include -#include +#include STL_STRING +FG_USING_STD(string); + +#define SG_MAX_CLOUD_TYPES 4 // change this if we add/remove cloud + // types en the enum below enum SGCloudType { SG_CLOUD_OVERCAST = 0, - SG_CLOUD_MOSTLY_CLOUDY, - SG_CLOUD_MOSTLY_SUNNY, - SG_CLOUD_CIRRUS, + SG_CLOUD_MOSTLY_CLOUDY = 1, + SG_CLOUD_MOSTLY_SUNNY = 2, + SG_CLOUD_CIRRUS = 3, }; @@ -72,8 +81,8 @@ public: ~SGCloudLayer( void ); // build the cloud object - void build( FGPath path, double size, double asl, double thickness, - double transition, SGCloudType type ); + void build( double size, double asl, double thickness, + double transition, ssgSimpleState *state ); // repaint the cloud colors based on current value of sun_angle, // sky, and fog colors. This updates the color arrays for diff --git a/simgear/sky/dome.cxx b/simgear/sky/dome.cxx index b83f2730..3bff53cb 100644 --- a/simgear/sky/dome.cxx +++ b/simgear/sky/dome.cxx @@ -35,7 +35,8 @@ #include #include -#include +#include + #include #include @@ -139,7 +140,7 @@ ssgBranch * SGSkyDome::build( ) { sgSetVec3( center_vertex, 0.0, 0.0, CENTER_ELEV ); for ( i = 0; i < 12; i++ ) { - theta = (i * 30.0) * DEG_TO_RAD; + theta = (i * 30.0) * SGD_DEGREES_TO_RADIANS; sgSetVec3( upper_vertex[i], cos(theta) * UPPER_RADIUS, @@ -484,19 +485,21 @@ bool SGSkyDome::reposition( sgVec3 p, double lon, double lat, double spin ) { // zero_elev.x, zero_elev.y, zero_elev.z ); // Rotate to proper orientation - // printf(" lon = %.2f lat = %.2f\n", FG_Longitude * RAD_TO_DEG, - // FG_Latitude * RAD_TO_DEG); - // xglRotatef( f->get_Longitude() * RAD_TO_DEG, 0.0, 0.0, 1.0 ); + // printf(" lon = %.2f lat = %.2f\n", + // FG_Longitude * SGD_RADIANS_TO_DEGREES, + // FG_Latitude * SGD_RADIANS_TO_DEGREES); + // xglRotatef( f->get_Longitude() * SGD_RADIANS_TO_DEGREES, 0.0, 0.0, 1.0 ); sgSetVec3( axis, 0.0, 0.0, 1.0 ); - sgMakeRotMat4( LON, lon * RAD_TO_DEG, axis ); + sgMakeRotMat4( LON, lon * SGD_RADIANS_TO_DEGREES, axis ); - // xglRotatef( 90.0 - f->get_Latitude() * RAD_TO_DEG, 0.0, 1.0, 0.0 ); + // xglRotatef( 90.0 - f->get_Latitude() * SGD_RADIANS_TO_DEGREES, + // 0.0, 1.0, 0.0 ); sgSetVec3( axis, 0.0, 1.0, 0.0 ); - sgMakeRotMat4( LAT, 90.0 - lat * RAD_TO_DEG, axis ); + sgMakeRotMat4( LAT, 90.0 - lat * SGD_RADIANS_TO_DEGREES, axis ); - // xglRotatef( l->sun_rotation * RAD_TO_DEG, 0.0, 0.0, 1.0 ); + // xglRotatef( l->sun_rotation * SGD_RADIANS_TO_DEGREES, 0.0, 0.0, 1.0 ); sgSetVec3( axis, 0.0, 0.0, 1.0 ); - sgMakeRotMat4( SPIN, spin * RAD_TO_DEG, axis ); + sgMakeRotMat4( SPIN, spin * SGD_RADIANS_TO_DEGREES, axis ); sgMat4 TRANSFORM; diff --git a/simgear/sky/moon.cxx b/simgear/sky/moon.cxx index 322a7321..a2ab902f 100644 --- a/simgear/sky/moon.cxx +++ b/simgear/sky/moon.cxx @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -202,7 +203,7 @@ ssgBranch * SGMoon::build( FGPath path, double moon_size ) { // 90 degrees = moon rise/set // 180 degrees = darkest midnight bool SGMoon::repaint( double moon_angle ) { - if ( moon_angle * RAD_TO_DEG < 100 ) { + if ( moon_angle * SGD_RADIANS_TO_DEGREES < 100 ) { // else moon is well below horizon (so no point in repainting it) // x_10 = moon_angle^10 @@ -257,13 +258,14 @@ bool SGMoon::reposition( sgVec3 p, double angle, sgSetVec3( axis, 0.0, 0.0, -1.0 ); sgMakeRotMat4( GST, angle, axis ); - // xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0); + // xglRotatef( ((SGD_RADIANS_TO_DEGREES * rightAscension)- 90.0), + // 0.0, 0.0, 1.0); sgSetVec3( axis, 0.0, 0.0, 1.0 ); - sgMakeRotMat4( RA, (rightAscension * RAD_TO_DEG) - 90.0, axis ); + sgMakeRotMat4( RA, (rightAscension * SGD_RADIANS_TO_DEGREES) - 90.0, axis ); - // xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0); + // xglRotatef((SGD_RADIANS_TO_DEGREES * declination), 1.0, 0.0, 0.0); sgSetVec3( axis, 1.0, 0.0, 0.0 ); - sgMakeRotMat4( DEC, declination * RAD_TO_DEG, axis ); + sgMakeRotMat4( DEC, declination * SGD_RADIANS_TO_DEGREES, axis ); // xglTranslatef(0,moon_dist); sgSetVec3( v, 0.0, moon_dist, 0.0 ); diff --git a/simgear/sky/oursun.cxx b/simgear/sky/oursun.cxx index 6890b8b3..566bbcef 100644 --- a/simgear/sky/oursun.cxx +++ b/simgear/sky/oursun.cxx @@ -31,10 +31,9 @@ #include #include +#include #include -#include - #include "sphere.hxx" #include "oursun.hxx" @@ -294,7 +293,7 @@ ssgBranch * SGSun::build( FGPath path, double sun_size ) { // 90 degrees = sun rise/set // 180 degrees = darkest midnight bool SGSun::repaint( double sun_angle ) { - if ( sun_angle * RAD_TO_DEG < 100 ) { + if ( sun_angle * SGD_RADIANS_TO_DEGREES < 100 ) { // else sun is well below horizon (so no point in repainting it) // x_10 = sun_angle^10 @@ -348,13 +347,14 @@ bool SGSun::reposition( sgVec3 p, double angle, sgSetVec3( axis, 0.0, 0.0, -1.0 ); sgMakeRotMat4( GST, angle, axis ); - // xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0); + // xglRotatef( ((SGD_RADIANS_TO_DEGREES * rightAscension)- 90.0), + // 0.0, 0.0, 1.0); sgSetVec3( axis, 0.0, 0.0, 1.0 ); - sgMakeRotMat4( RA, (rightAscension * RAD_TO_DEG) - 90.0, axis ); + sgMakeRotMat4( RA, (rightAscension * SGD_RADIANS_TO_DEGREES) - 90.0, axis ); - // xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0); + // xglRotatef((SGD_RADIANS_TO_DEGREES * declination), 1.0, 0.0, 0.0); sgSetVec3( axis, 1.0, 0.0, 0.0 ); - sgMakeRotMat4( DEC, declination * RAD_TO_DEG, axis ); + sgMakeRotMat4( DEC, declination * SGD_RADIANS_TO_DEGREES, axis ); // xglTranslatef(0,sun_dist); sgSetVec3( v, 0.0, sun_dist, 0.0 ); diff --git a/simgear/sky/sky.cxx b/simgear/sky/sky.cxx index dc0627f1..643a5689 100644 --- a/simgear/sky/sky.cxx +++ b/simgear/sky/sky.cxx @@ -26,13 +26,11 @@ # include #endif -#include // plib include +#include +#include -#include #include -#include - #include "sky.hxx" @@ -98,27 +96,22 @@ void SGSky::build( double sun_size, double moon_size, // add the cloud ssgStates to the material lib FGPath cloud_path; - ssgSimpleState *cloud_state; cloud_path.set( tex_path.str() ); - cloud_path.append( "cirrus.rgba" ); - cloud_state = SGCloudMakeState( cloud_path.str() ); - material_lib.add_item( "CloudCirrus", cloud_state ); + cloud_path.append( "overcast.rgb" ); + cloud_mats[SG_CLOUD_OVERCAST] = SGCloudMakeState( cloud_path.str() ); cloud_path.set( tex_path.str() ); cloud_path.append( "mostlycloudy.rgba" ); - cloud_state = SGCloudMakeState( cloud_path.str() ); - material_lib.add_item( "CloudMostlyCloudy", cloud_state ); + cloud_mats[SG_CLOUD_MOSTLY_CLOUDY] = SGCloudMakeState( cloud_path.str() ); cloud_path.set( tex_path.str() ); cloud_path.append( "mostlysunny.rgba" ); - cloud_state = SGCloudMakeState( cloud_path.str() ); - material_lib.add_item( "CloudMostlySunny", cloud_state ); + cloud_mats[SG_CLOUD_MOSTLY_SUNNY] = SGCloudMakeState( cloud_path.str() ); cloud_path.set( tex_path.str() ); - cloud_path.append( "overcast.rgb" ); - cloud_state = SGCloudMakeState( cloud_path.str() ); - material_lib.add_item( "CloudOvercast", cloud_state ); + cloud_path.append( "cirrus.rgba" ); + cloud_mats[SG_CLOUD_CIRRUS] = SGCloudMakeState( cloud_path.str() ); } @@ -228,9 +221,9 @@ void SGSky::draw_scene( float alt ) { void SGSky::add_cloud_layer( double asl, double thickness, double transition, - SGCloudType type ) { + ssgSimpleState *state ) { SGCloudLayer *layer = new SGCloudLayer; - layer->build(tex_path, 40000.0f, asl, thickness, transition, type ); + layer->build( 40000.0f, asl, thickness, transition, state ); layer_list_iterator current = cloud_layers.begin(); layer_list_iterator last = cloud_layers.end(); @@ -251,6 +244,21 @@ void SGSky::add_cloud_layer( double asl, double thickness, double transition, } +void SGSky::add_cloud_layer( double asl, double thickness, double transition, + const string &tex_path ) { + ssgSimpleState *state = SGCloudMakeState( tex_path ); + add_cloud_layer( asl, thickness, transition, state ); +} + + +void SGSky::add_cloud_layer( double asl, double thickness, double transition, + SGCloudType type ) { + if ( type > 0 && type < SG_MAX_CLOUD_TYPES ) { + add_cloud_layer( asl, thickness, transition, cloud_mats[type] ); + } +} + + // modify the current visibility based on cloud layers, thickness, // transition range, and simulated "puffs". void SGSky::modify_vis( float alt, float time_factor ) { @@ -301,11 +309,11 @@ void SGSky::modify_vis( float alt, float time_factor ) { // modify actual_visibility based on puff envelope if ( puff_progression <= ramp_up ) { - double x = FG_PI_2 * puff_progression / ramp_up; + double x = 2 * SGD_PI * puff_progression / ramp_up; double factor = 1.0 - sin( x ); effvis = effvis * factor; } else if ( puff_progression >= ramp_up + puff_length ) { - double x = FG_PI_2 * + double x = 2 * SGD_PI * (puff_progression - (ramp_up + puff_length)) / ramp_down; double factor = sin( x ); diff --git a/simgear/sky/sky.hxx b/simgear/sky/sky.hxx index 778a4913..1e5ba347 100644 --- a/simgear/sky/sky.hxx +++ b/simgear/sky/sky.hxx @@ -62,6 +62,7 @@ private: SGMoon *moon; SGStars *planets; SGStars *stars; + ssgSimpleState *cloud_mats[SG_MAX_CLOUD_TYPES]; layer_list_type cloud_layers; ssgRoot *pre_root, *post_root; @@ -152,6 +153,10 @@ public: // add a cloud layer (above sea level in meters) void add_cloud_layer( double asl, double thickness, double transition, SGCloudType type ); + void add_cloud_layer( double asl, double thickness, double transition, + const string &tex_path ); + void add_cloud_layer( double asl, double thickness, double transition, + ssgSimpleState *state ); inline int get_num_layers() const { return cloud_layers.size(); } inline SGCloudLayer *get_cloud_layer( int i ) const { diff --git a/simgear/sky/sphere.cxx b/simgear/sky/sphere.cxx index 21e25be4..88cbf9b7 100644 --- a/simgear/sky/sphere.cxx +++ b/simgear/sky/sphere.cxx @@ -30,8 +30,9 @@ #include STL_IOSTREAM +#include #include -#include + // return a sphere object as an ssgBranch ssgBranch *ssgMakeSphere( ssgSimpleState *state, ssgColourArray *cl, @@ -47,8 +48,8 @@ ssgBranch *ssgMakeSphere( ssgSimpleState *state, ssgColourArray *cl, sgVec2 vec2; sgVec3 vec3; - drho = FG_PI / (float) stacks; - dtheta = 2.0 * FG_PI / (float) slices; + drho = SG_PI / (float) stacks; + dtheta = 2.0 * SG_PI / (float) slices; /* texturing: s goes from 0.0/0.25/0.5/0.75/1.0 at +y/+x/-y/-x/+y axis t goes from -1.0/+1.0 at z = -radius/+radius (linear along diff --git a/simgear/sky/stars.cxx b/simgear/sky/stars.cxx index 42a34732..598af42d 100644 --- a/simgear/sky/stars.cxx +++ b/simgear/sky/stars.cxx @@ -31,10 +31,9 @@ #include #include +#include #include -#include - #include "stars.hxx" #ifdef _MSC_VER @@ -42,6 +41,7 @@ FG_USING_STD(cout); FG_USING_STD(endl); #endif + // Set up star rendering call backs static int sgStarPreDraw( ssgEntity *e ) { /* cout << endl << "Star pre draw" << endl << "----------------" @@ -147,26 +147,26 @@ bool SGStars::repaint( double sun_angle, int num, sgdVec3 *star_data ) { float *color; // determine which star structure to draw - if ( sun_angle > (FG_PI_2 + 10.0 * DEG_TO_RAD ) ) { + if ( sun_angle > (2 * SGD_PI + 10.0 * SGD_DEGREES_TO_RADIANS ) ) { // deep night factor = 1.0; cutoff = 4.5; - } else if ( sun_angle > (FG_PI_2 + 8.8 * DEG_TO_RAD ) ) { + } else if ( sun_angle > (2 * SGD_PI + 8.8 * SGD_DEGREES_TO_RADIANS ) ) { factor = 1.0; cutoff = 3.8; - } else if ( sun_angle > (FG_PI_2 + 7.5 * DEG_TO_RAD ) ) { + } else if ( sun_angle > (2 * SGD_PI + 7.5 * SGD_DEGREES_TO_RADIANS ) ) { factor = 0.95; cutoff = 3.1; - } else if ( sun_angle > (FG_PI_2 + 7.0 * DEG_TO_RAD ) ) { + } else if ( sun_angle > (2 * SGD_PI + 7.0 * SGD_DEGREES_TO_RADIANS ) ) { factor = 0.9; cutoff = 2.4; - } else if ( sun_angle > (FG_PI_2 + 6.5 * DEG_TO_RAD ) ) { + } else if ( sun_angle > (2 * SGD_PI + 6.5 * SGD_DEGREES_TO_RADIANS ) ) { factor = 0.85; cutoff = 1.8; - } else if ( sun_angle > (FG_PI_2 + 6.0 * DEG_TO_RAD ) ) { + } else if ( sun_angle > (2 * SGD_PI + 6.0 * SGD_DEGREES_TO_RADIANS ) ) { factor = 0.8; cutoff = 1.2; - } else if ( sun_angle > (FG_PI_2 + 5.5 * DEG_TO_RAD ) ) { + } else if ( sun_angle > (2 * SGD_PI + 5.5 * SGD_DEGREES_TO_RADIANS ) ) { factor = 0.75; cutoff = 0.6; } else { -- 2.39.5