#include <stdio.h>
#include <iostream>
+#include <plib/sg.h>
#include <plib/ssg.h>
-#include <simgear/constants.h>
#include <simgear/math/fg_random.h>
#include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx>
-#include <Objects/matlib.hxx>
-
#include "cloud.hxx"
// 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;
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 );
// 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;
#ifndef _SG_CLOUD_HXX_
#define _SG_CLOUD_HXX_
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <simgear/compiler.h>
#include <plib/ssg.h>
-#include <simgear/misc/fgpath.hxx>
+#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,
};
~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
#include <GL/glut.h>
#include <simgear/xgl/xgl.h>
-#include <simgear/constants.h>
+#include <plib/sg.h>
+
#include <simgear/debug/logstream.hxx>
#include <simgear/math/fg_random.h>
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,
// 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;
#include <stdio.h>
#include <iostream>
+#include <plib/sg.h>
#include <plib/ssg.h>
#include <simgear/constants.h>
// 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
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 );
#include <stdio.h>
#include <iostream>
+#include <plib/sg.h>
#include <plib/ssg.h>
-#include <simgear/constants.h>
-
#include "sphere.hxx"
#include "oursun.hxx"
// 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
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 );
# include <config.h>
#endif
-#include <plib/ssg.h> // plib include
+#include <plib/sg.h>
+#include <plib/ssg.h>
-#include <simgear/constants.h>
#include <simgear/math/fg_random.h>
-#include <Objects/matlib.hxx>
-
#include "sky.hxx"
// 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() );
}
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();
}
+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 ) {
// 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 );
SGMoon *moon;
SGStars *planets;
SGStars *stars;
+ ssgSimpleState *cloud_mats[SG_MAX_CLOUD_TYPES];
layer_list_type cloud_layers;
ssgRoot *pre_root, *post_root;
// 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 {
#include STL_IOSTREAM
+#include <plib/sg.h>
#include <plib/ssg.h>
-#include <simgear/constants.h>
+
// return a sphere object as an ssgBranch
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
#include <stdio.h>
#include <iostream>
+#include <plib/sg.h>
#include <plib/ssg.h>
-#include <simgear/constants.h>
-
#include "stars.hxx"
#ifdef _MSC_VER
FG_USING_STD(endl);
#endif
+
// Set up star rendering call backs
static int sgStarPreDraw( ssgEntity *e ) {
/* cout << endl << "Star pre draw" << endl << "----------------"
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 {