- sgSetVec3( vertex, -layer_span, -layer_span, 0.0f );
- sgVec2 base;
- sgSetVec2( base, sg_random(), sg_random() );
- sgSetVec2( tc, base[0], base[1] );
- cl->add( color );
- vl->add( vertex );
- tl->add( tc );
-
- sgSetVec3( vertex, layer_span, -layer_span, 0.0f );
- sgSetVec2( tc, base[0] + layer_span / scale, base[1] );
- cl->add( color );
- vl->add( vertex );
- tl->add( tc );
-
- sgSetVec3( vertex, -layer_span, layer_span, 0.0f );
- sgSetVec2( tc, base[0], base[1] + layer_span / scale );
- cl->add( color );
- vl->add( vertex );
- tl->add( tc );
-
- sgSetVec3( vertex, layer_span, layer_span, 0.0f );
- sgSetVec2( tc, base[0] + layer_span / scale, base[1] + layer_span / scale );
- cl->add( color );
- vl->add( vertex );
- tl->add( tc );
-
- if (layer != 0)
- layer_transform->removeKid(layer); // automatic delete
- layer = new ssgVtxTable ( GL_TRIANGLE_STRIP, vl, NULL, tl, cl );
- if (layer_states[layer_type] != 0)
- layer->setState( layer_states[layer_type] );
-
- // force a repaint of the moon colors with arbitrary defaults
+ const float layer_scale = layer_span / scale;
+ const float mpi = SG_PI/4;
+
+ // caclculate the difference between a flat-earth model and
+ // a round earth model given the span and altutude ASL of
+ // the cloud layer. This is the difference in altitude between
+ // the top of the inverted bowl and the edge of the bowl.
+ // const float alt_diff = layer_asl * 0.8;
+ const float layer_to_core = (SG_EARTH_RAD * 1000 + layer_asl);
+ const float layer_angle = acos( 0.5*layer_span / layer_to_core);
+ const float border_to_core = layer_to_core * sin(layer_angle);
+ const float alt_diff = layer_to_core - border_to_core;
+
+ for (int i = 0; i < 4; i++)
+ {
+ if ( layer[i] != NULL ) {
+ layer_transform->removeKid(layer[i]); // automatic delete
+ }
+
+ vl[i] = new ssgVertexArray( 10 );
+ cl[i] = new ssgColourArray( 10 );
+ tl[i] = new ssgTexCoordArray( 10 );
+
+
+ sgSetVec3( vertex, layer_span*(i-2)/2, -layer_span,
+ alt_diff * (sin(i*mpi) - 2) );
+
+ sgSetVec2( tc, base[0] + layer_scale * i/4, base[1] );
+
+ sgSetVec4( color, 1.0f, 1.0f, 1.0f, (i == 0) ? 0.0f : 0.15f );
+
+ cl[i]->add( color );
+ vl[i]->add( vertex );
+ tl[i]->add( tc );
+
+ for (int j = 0; j < 4; j++)
+ {
+ sgSetVec3( vertex, layer_span*(i-1)/2, layer_span*(j-2)/2,
+ alt_diff * (sin((i+1)*mpi) + sin(j*mpi) - 2) );
+
+ sgSetVec2( tc, base[0] + layer_scale * (i+1)/4,
+ base[1] + layer_scale * j/4 );
+
+ sgSetVec4( color, 1.0f, 1.0f, 1.0f,
+ ( (j == 0) || (i == 3)) ?
+ ( (j == 0) && (i == 3)) ? 0.0f : 0.15f : 1.0f );
+
+ cl[i]->add( color );
+ vl[i]->add( vertex );
+ tl[i]->add( tc );
+
+
+ sgSetVec3( vertex, layer_span*(i-2)/2, layer_span*(j-1)/2,
+ alt_diff * (sin(i*mpi) + sin((j+1)*mpi) - 2) );
+
+ sgSetVec2( tc, base[0] + layer_scale * i/4,
+ base[1] + layer_scale * (j+1)/4 );
+
+ sgSetVec4( color, 1.0f, 1.0f, 1.0f,
+ ((j == 3) || (i == 0)) ?
+ ((j == 3) && (i == 0)) ? 0.0f : 0.15f : 1.0f );
+ cl[i]->add( color );
+ vl[i]->add( vertex );
+ tl[i]->add( tc );
+ }
+
+ sgSetVec3( vertex, layer_span*(i-1)/2, layer_span,
+ alt_diff * (sin((i+1)*mpi) - 2) );
+
+ sgSetVec2( tc, base[0] + layer_scale * (i+1)/4,
+ base[1] + layer_scale );
+
+ sgSetVec4( color, 1.0f, 1.0f, 1.0f, (i == 3) ? 0.0f : 0.15f );
+
+ cl[i]->add( color );
+ vl[i]->add( vertex );
+ tl[i]->add( tc );
+
+ layer[i] = new ssgVtxTable(GL_TRIANGLE_STRIP, vl[i], NULL, tl[i], cl[i]);
+ layer_transform->addKid( layer[i] );
+
+ 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