Frederic Bouvier:
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.
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user