]> git.mxchange.org Git - simgear.git/commitdiff
Frederic Bouvier:
authorehofman <ehofman>
Sun, 4 Apr 2004 13:41:53 +0000 (13:41 +0000)
committerehofman <ehofman>
Sun, 4 Apr 2004 13:41:53 +0000 (13:41 +0000)
This is a new patch that allow to define a different
texture for top and bottom of clouds. It uses the
overcast_top.rgb you made for me last time.

What the patch do is to install a ssgStateSelector
instead of a ssgSimpleState for each layer.
The SGCloudLayer::draw method is modified to accept
a boolean that will select the proper state: 0/false
for bottom, 1/true for top.

Then, in SGSky::drawUpperClouds and SGSky::drawLowerClouds,
SGCloudLayer::draw is called with false and true because
we see the bottom of upper clouds and the top of
lower clouds.

Only overcast has 2 textures, the other types share the
same state for top and bottom, but that could be modified
in SGCloudLayer::rebuild.

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

index 309572314c4b4d0717277766b10d39bb347f32cc..1bd5dceed7b7fd9e41a0d8e670e123500f475572 100644 (file)
@@ -42,7 +42,7 @@
 #include "cloud.hxx"
 
 
-static ssgSimpleState *layer_states[SGCloudLayer::SG_MAX_CLOUD_COVERAGES];
+static ssgStateSelector *layer_states[SGCloudLayer::SG_MAX_CLOUD_COVERAGES];
 static bool state_initialized = false;
 
 
@@ -50,6 +50,7 @@ static bool state_initialized = false;
 SGCloudLayer::SGCloudLayer( const string &tex_path ) :
     layer_root(new ssgRoot),
     layer_transform(new ssgTransform),
+    state_sel(0),
     texture_path(tex_path),
     layer_span(0.0),
     layer_asl(0.0),
@@ -162,30 +163,49 @@ SGCloudLayer::rebuild()
         SG_LOG(SG_ASTRO, SG_INFO, "initializing cloud layers");
 
         SGPath cloud_path;
+        ssgStateSelector *state_sel;
+        ssgSimpleState *state;
 
+        state_sel = new ssgStateSelector( 2 );
         cloud_path.set(texture_path.str());
         cloud_path.append("overcast.rgb");
-        layer_states[SG_CLOUD_OVERCAST] = sgCloudMakeState(cloud_path.str());
+        state_sel->setStep( 0, sgCloudMakeState(cloud_path.str()) );
+        cloud_path.set(texture_path.str());
+        cloud_path.append("overcast_top.rgb");
+        state_sel->setStep( 1, sgCloudMakeState(cloud_path.str()) );
+        layer_states[SG_CLOUD_OVERCAST] = state_sel;
 
+        state_sel = new ssgStateSelector( 2 );
         cloud_path.set(texture_path.str());
         cloud_path.append("broken.rgba");
-        layer_states[SG_CLOUD_BROKEN]
-            = sgCloudMakeState(cloud_path.str());
+        state = sgCloudMakeState(cloud_path.str());
+        state_sel->setStep( 0, state );
+        state_sel->setStep( 1, state );
+        layer_states[SG_CLOUD_BROKEN] = state_sel;
 
+        state_sel = new ssgStateSelector( 2 );
         cloud_path.set(texture_path.str());
         cloud_path.append("scattered.rgba");
-        layer_states[SG_CLOUD_SCATTERED]
-            = sgCloudMakeState(cloud_path.str());
+        state = sgCloudMakeState(cloud_path.str());
+        state_sel->setStep( 0, state );
+        state_sel->setStep( 1, state );
+        layer_states[SG_CLOUD_SCATTERED] = state_sel;
 
+        state_sel = new ssgStateSelector( 2 );
         cloud_path.set(texture_path.str());
         cloud_path.append("few.rgba");
-        layer_states[SG_CLOUD_FEW]
-            = sgCloudMakeState(cloud_path.str());
+        state = sgCloudMakeState(cloud_path.str());
+        state_sel->setStep( 0, state );
+        state_sel->setStep( 1, state );
+        layer_states[SG_CLOUD_FEW] = state_sel;
 
+        state_sel = new ssgStateSelector( 2 );
         cloud_path.set(texture_path.str());
         cloud_path.append("cirrus.rgba");
-        layer_states[SG_CLOUD_CIRRUS]
-            = sgCloudMakeState(cloud_path.str());
+        state = sgCloudMakeState(cloud_path.str());
+        state_sel->setStep( 0, state );
+        state_sel->setStep( 1, state );
+        layer_states[SG_CLOUD_CIRRUS] = state_sel;
 
         layer_states[SG_CLOUD_CLEAR] = 0;
     }
@@ -285,6 +305,7 @@ SGCloudLayer::rebuild()
         if ( layer_states[layer_coverage] != NULL ) {
             layer[i]->setState( layer_states[layer_coverage] );
         }
+        state_sel = layer_states[layer_coverage];
     }
 
     // force a repaint of the sky colors with arbitrary defaults
@@ -476,8 +497,9 @@ bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat,
 }
 
 
-void SGCloudLayer::draw() {
+void SGCloudLayer::draw( bool top ) {
     if ( layer_coverage != SG_CLOUD_CLEAR ) {
+        state_sel->selectStep( top ? 1 : 0 );
         ssgCullAndDraw( layer_root );
     }
 }
index 76a3cb881df6245adaa59f229d18ced32bafe046..cda7245f3a75ee45e36316f1d3a50b2061a77661 100644 (file)
@@ -167,13 +167,14 @@ public:
                      double dt = 0.0 );
 
     /** draw the cloud layer */
-    void draw();
+    void draw( bool top );
 
 private:
 
     ssgRoot *layer_root;
     ssgTransform *layer_transform;
     ssgLeaf *layer[4];
+    ssgStateSelector *state_sel;
 
     ssgColourArray *cl[4]; 
     ssgVertexArray *vl[4];
index df4505f55867b8eaffeec7150fe583d08ac54ef3..3d446981bdb6c02d2c8aafe34751e1ef08af7964 100644 (file)
@@ -212,7 +212,7 @@ void SGSky::drawUpperClouds( ) {
     // draw the cloud layers that are above us, top to bottom
     for ( int i = (int)cloud_layers.size() - 1; i >= cur_layer_pos; --i ) {
         if ( i != in_cloud ) {
-            cloud_layers[i]->draw();
+            cloud_layers[i]->draw( false );
         }
     }
 }
@@ -225,7 +225,7 @@ void SGSky::drawLowerClouds() {
     // draw the cloud layers that are below us, bottom to top
     for ( int i = 0; i < cur_layer_pos; ++i ) {
         if ( i != in_cloud ) {
-            cloud_layers[i]->draw();
+            cloud_layers[i]->draw( true );
         }
     }
 }