]> git.mxchange.org Git - simgear.git/commitdiff
Updates to cloud code to add different basic cloud types. This isn't the
authorcurt <curt>
Fri, 23 Jun 2000 02:55:57 +0000 (02:55 +0000)
committercurt <curt>
Fri, 23 Jun 2000 02:55:57 +0000 (02:55 +0000)
final list of cloud types, but servers as an example / template for someone
who wants to tweak this out and do it right.

simgear/sky/cloud.cxx
simgear/sky/cloud.hxx
simgear/sky/sky.cxx
simgear/sky/sky.hxx

index e6d02c5c7c6ee72989c36a986eca7b0a3c85dc4f..f46db1c58d1c46c231f7b3de0677bd280a144759 100644 (file)
@@ -30,6 +30,8 @@
 #include <simgear/math/point3d.hxx>
 #include <simgear/math/polar3d.hxx>
 
+#include <Objects/matlib.hxx>
+
 #include "cloud.hxx"
 
 
@@ -45,7 +47,7 @@ SGCloudLayer::~SGCloudLayer( void ) {
 
 // build the moon object
 void SGCloudLayer::build( FGPath path, double s, double asl, double thickness,
-                         double transition )
+                         double transition, SGCloudType type )
 {
     scale = 4000.0;
 
@@ -56,21 +58,27 @@ void SGCloudLayer::build( FGPath path, double s, double asl, double thickness,
     size = s;
     last_lon = last_lat = -999.0f;
 
-    // set up the cloud state
-    path.append( "cloud.rgba" );
-    layer_state = new ssgSimpleState();
-    layer_state->setTexture( (char *)path.c_str() );
-    layer_state->setShadeModel( GL_SMOOTH );
-    layer_state->disable( GL_LIGHTING );
-    layer_state->disable( GL_CULL_FACE );
-    layer_state->enable( GL_TEXTURE_2D );
-    layer_state->enable( GL_COLOR_MATERIAL );
-    layer_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
-    layer_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
-    layer_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
-    layer_state->enable( GL_BLEND );
-    layer_state->enable( GL_ALPHA_TEST );
-    layer_state->setAlphaClamp( 0.01 );
+    // 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;
+    }
 
     cl = new ssgColourArray( 4 );
     vl = new ssgVertexArray( 4 );
@@ -247,3 +255,24 @@ bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat,
 void SGCloudLayer::draw() {
     ssgCullAndDraw( layer_root );
 }
+
+
+// make an ssgSimpleState for a cloud layer given the named texture
+ssgSimpleState *SGCloudMakeState( const string &path ) {
+    ssgSimpleState *state = new ssgSimpleState();
+
+    state->setTexture( (char *)path.c_str() );
+    state->setShadeModel( GL_SMOOTH );
+    state->disable( GL_LIGHTING );
+    state->disable( GL_CULL_FACE );
+    state->enable( GL_TEXTURE_2D );
+    state->enable( GL_COLOR_MATERIAL );
+    state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
+    state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
+    state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
+    state->enable( GL_BLEND );
+    state->enable( GL_ALPHA_TEST );
+    state->setAlphaClamp( 0.01 );
+
+    return state;
+}
index 1da11bb5a2246da38054490e7a6c9aa3f2e1b417..05961c54af56af73f0d14dc36c9ee5d6f1f5e00a 100644 (file)
 #include <simgear/misc/fgpath.hxx>
 
 
+enum SGCloudType {
+    SG_CLOUD_OVERCAST = 0,
+    SG_CLOUD_MOSTLY_CLOUDY,
+    SG_CLOUD_MOSTLY_SUNNY,
+    SG_CLOUD_CIRRUS,
+};
+
+
 class SGCloudLayer {
 
+private:
+
     ssgRoot *layer_root;
     ssgTransform *layer_transform;
     ssgSimpleState *layer_state;
@@ -63,7 +73,7 @@ public:
 
     // build the cloud object
     void build( FGPath path, double size, double asl, double thickness,
-               double transition );
+               double transition, SGCloudType type );
 
     // repaint the cloud colors based on current value of sun_angle,
     // sky, and fog colors.  This updates the color arrays for
@@ -91,4 +101,8 @@ public:
 };
 
 
+// make an ssgSimpleState for a cloud layer given the named texture
+ssgSimpleState *SGCloudMakeState( const string &path );
+
+
 #endif // _SG_CLOUD_HXX_
index d37cc9d88c99686cdbad9a885bb9540d843e12dc..dc0627f18722036bf7098ef54c9fd5271c68a363 100644 (file)
@@ -31,6 +31,8 @@
 #include <simgear/constants.h>
 #include <simgear/math/fg_random.h>
 
+#include <Objects/matlib.hxx>
+
 #include "sky.hxx"
 
 
@@ -93,6 +95,30 @@ void SGSky::build(  double sun_size, double moon_size,
 
     pre_root->addKid( pre_selector );
     post_root->addKid( post_selector );
+
+    // 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.set( tex_path.str() );
+    cloud_path.append( "mostlycloudy.rgba" );
+    cloud_state = SGCloudMakeState( cloud_path.str() );
+    material_lib.add_item( "CloudMostlyCloudy", cloud_state );
+
+    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_path.set( tex_path.str() );
+    cloud_path.append( "overcast.rgb" );
+    cloud_state = SGCloudMakeState( cloud_path.str() );
+    material_lib.add_item( "CloudOvercast", cloud_state );
 }
 
 
@@ -201,9 +227,10 @@ void SGSky::draw_scene( float alt ) {
 }
 
  
-void SGSky::add_cloud_layer( double asl, double thickness, double transition ) {
+void SGSky::add_cloud_layer( double asl, double thickness, double transition,
+                            SGCloudType type ) {
     SGCloudLayer *layer = new SGCloudLayer;
-    layer->build(tex_path, 40000.0f, asl, thickness, transition);
+    layer->build(tex_path, 40000.0f, asl, thickness, transition, type );
 
     layer_list_iterator current = cloud_layers.begin();
     layer_list_iterator last = cloud_layers.end();
index 058740f374f94a1ecd2aa8bb81727164a970ede7..778a4913a803021cd57e475b67504b71df50da43 100644 (file)
@@ -150,7 +150,8 @@ public:
     }
 
     // add a cloud layer (above sea level in meters)
-    void add_cloud_layer( double asl, double thickness, double transition );
+    void add_cloud_layer( double asl, double thickness, double transition,
+                         SGCloudType type );
 
     inline int get_num_layers() const { return cloud_layers.size(); }
     inline SGCloudLayer *get_cloud_layer( int i ) const {