#include "cloud.hxx"
-ssgSimpleState *
-SGCloudLayer::layer_states[SGCloudLayer::SG_MAX_CLOUD_COVERAGES];
+
+static ssgSimpleState *layer_states[SGCloudLayer::SG_MAX_CLOUD_COVERAGES];
+static bool state_initialized = false;
// Constructor
layer_transition(0.0),
layer_coverage(SG_CLOUD_CLEAR),
scale(4000.0),
+ speed(0.0),
+ direction(0.0),
last_lon(0.0),
last_lat(0.0)
{
tl[0] = tl[1] = tl[2] = tl[3] = NULL;
layer[0] = layer[1] = layer[2] = layer[3] = NULL;
- for ( int i = 0; i < SG_MAX_CLOUD_COVERAGES; ++i ) {
- layer_states[i] = NULL;
- }
layer_root->addKid(layer_transform);
rebuild();
}
}
void
-SGCloudLayer::setElevation_m (float elevation_m)
+SGCloudLayer::setElevation_m (float elevation_m, bool set_span)
{
layer_asl = elevation_m;
+
+ if (set_span) {
+ if (elevation_m > 4000)
+ setSpan_m( elevation_m * 10 );
+ else
+ setSpan_m( 40000 );
+ }
}
float
void
SGCloudLayer::rebuild()
{
- // Initialize states and sizes if necessary.
- if ( layer_states[0] == NULL ) {
+ // Initialize states and sizes if necessary.
+ if ( !state_initialized ) {
+ state_initialized = true;
+
+ cout << "initializing cloud layers" << endl;
+
SGPath cloud_path;
cloud_path.set(texture_path.str());
cloud_path.append("overcast.rgb");
- layer_states[SG_CLOUD_OVERCAST] = SGCloudMakeState(cloud_path.str());
+ layer_states[SG_CLOUD_OVERCAST] = sgCloudMakeState(cloud_path.str());
cloud_path.set(texture_path.str());
cloud_path.append("broken.rgba");
layer_states[SG_CLOUD_BROKEN]
- = SGCloudMakeState(cloud_path.str());
+ = sgCloudMakeState(cloud_path.str());
cloud_path.set(texture_path.str());
cloud_path.append("scattered.rgba");
layer_states[SG_CLOUD_SCATTERED]
- = SGCloudMakeState(cloud_path.str());
+ = sgCloudMakeState(cloud_path.str());
cloud_path.set(texture_path.str());
cloud_path.append("few.rgba");
layer_states[SG_CLOUD_FEW]
- = SGCloudMakeState(cloud_path.str());
+ = sgCloudMakeState(cloud_path.str());
cloud_path.set(texture_path.str());
cloud_path.append("cirrus.rgba");
layer_states[SG_CLOUD_CIRRUS]
- = SGCloudMakeState(cloud_path.str());
+ = sgCloudMakeState(cloud_path.str());
layer_states[SG_CLOUD_CLEAR] = 0;
}
sgVec2 tc;
const float layer_scale = layer_span / scale;
- const float mpi = SG_PI/2;
+ const float mpi = SG_PI/4;
+ const float alt_diff = layer_asl * 0.8;
- for (int i = -2; i < 2; i++)
+ for (int i = 0; i < 4; i++)
{
- int row = i + 2;
-
- if ( layer[row] != NULL ) {
- layer_transform->removeKid(layer[row]); // automatic delete
+ if ( layer[i] != NULL ) {
+ layer_transform->removeKid(layer[i]); // automatic delete
}
- vl[row] = new ssgVertexArray( 10 );
- cl[row] = new ssgColourArray( 10 );
- tl[row] = new ssgTexCoordArray( 10 );
+ vl[i] = new ssgVertexArray( 10 );
+ cl[i] = new ssgColourArray( 10 );
+ tl[i] = new ssgTexCoordArray( 10 );
- sgSetVec3( vertex, layer_span*i/2, -layer_span,
- -250 * (cos((i+2)*mpi) + 3) );
+ sgSetVec3( vertex, layer_span*(i-2)/2, -layer_span,
+ alt_diff * (sin(i*mpi) - 2) );
- sgSetVec2( tc, base[0] + layer_scale * (i+2)/4, base[1] );
+ sgSetVec2( tc, base[0] + layer_scale * i/4, base[1] );
- sgSetVec4( color, 1.0f, 1.0f, 1.0f, (i == -2) ? 0.0f : 0.15f );
+ sgSetVec4( color, 1.0f, 1.0f, 1.0f, (i == 0) ? 0.0f : 0.15f );
- cl[row]->add( color );
- vl[row]->add( vertex );
- tl[row]->add( tc );
+ cl[i]->add( color );
+ vl[i]->add( vertex );
+ tl[i]->add( tc );
- for (int j = -2; j < 2; j++)
+ for (int j = 0; j < 4; j++)
{
- sgSetVec3( vertex, layer_span*(i+1)/2, layer_span*j/2,
- -250 * (cos((i+3)*mpi) + cos((j+2)*mpi) + 2) );
+ 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+3)/4,
- base[1] + layer_scale * (j+2)/4 );
+ sgSetVec2( tc, base[0] + layer_scale * (i+1)/4,
+ base[1] + layer_scale * j/4 );
sgSetVec4( color, 1.0f, 1.0f, 1.0f,
- ((j == -2) || (i == 1)) ?
- ((j == -2) && (i == 1)) ? 0.0f : 0.15f : 1.0f );
+ ( (j == 0) || (i == 3)) ?
+ ( (j == 0) && (i == 3)) ? 0.0f : 0.15f : 1.0f );
- cl[row]->add( color );
- vl[row]->add( vertex );
- tl[row]->add( tc );
+ cl[i]->add( color );
+ vl[i]->add( vertex );
+ tl[i]->add( tc );
- sgSetVec3( vertex, layer_span*i/2, layer_span*(j+1)/2,
- -250 * (cos((i+2)*mpi) + cos((j+3)*mpi) + 2) );
+ 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+2)/4,
- base[1] + layer_scale * (j+3)/4 );
+ sgSetVec2( tc, base[0] + layer_scale * i/4,
+ base[1] + layer_scale * (j+1)/4 );
sgSetVec4( color, 1.0f, 1.0f, 1.0f,
- ((j == 1) || (i == -2)) ?
- ((j == 1) && (i == -2)) ? 0.0f : 0.15f : 1.0f );
- cl[row]->add( color );
- vl[row]->add( vertex );
- tl[row]->add( tc );
+ ((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,
- -250 * (cos((i+3)*mpi) + 3) );
+ sgSetVec3( vertex, layer_span*(i-1)/2, layer_span,
+ alt_diff * (sin((i+1)*mpi) - 2) );
- sgSetVec2( tc, base[0] + layer_scale * (i+3)/4,
+ sgSetVec2( tc, base[0] + layer_scale * (i+1)/4,
base[1] + layer_scale );
- sgSetVec4( color, 1.0f, 1.0f, 1.0f, (i == 1) ? 0.0f : 0.15f );
+ sgSetVec4( color, 1.0f, 1.0f, 1.0f, (i == 3) ? 0.0f : 0.15f );
- cl[row]->add( color );
- vl[row]->add( vertex );
- tl[row]->add( tc );
+ cl[i]->add( color );
+ vl[i]->add( vertex );
+ tl[i]->add( tc );
- layer[row] = new ssgVtxTable ( GL_TRIANGLE_STRIP, vl[row], NULL, tl[row], cl[row] );
- layer_transform->addKid( layer[row] );
+ 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[row]->setState( layer_states[layer_coverage] );
+ layer[i]->setState( layer_states[layer_coverage] );
}
}
bool SGCloudLayer::repaint( sgVec3 fog_color ) {
float *color;
- for ( int row = 0; row < 4; row++ )
- for ( int i = 0; i < 10; ++i ) {
- color = cl[row]->get( i );
+ for ( int i = 0; i < 4; i++ )
+ for ( int j = 0; j < 10; ++j ) {
+ color = cl[i]->get( j );
sgCopyVec3( color, fog_color );
}
// spin specifies a rotation about the new Z axis (and orients the
// sunrise/set effects
bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat,
- double alt )
+ double alt, double dt )
{
sgMat4 T1, LON, LAT;
sgVec3 axis;
last_lat = lat;
}
- if ( lon != last_lon || lat != last_lat ) {
+ double sp_dist = speed*dt;
+
+ if ( lon != last_lon || lat != last_lat || sp_dist != 0 ) {
Point3D start( last_lon, last_lat, 0.0 );
Point3D dest( lon, lat, 0.0 );
- double course, dist;
- calc_gc_course_dist( dest, start, &course, &dist );
+ double course = 0.0, dist = 0.0;
+
+ if (dest != start) {
+ calc_gc_course_dist( dest, start, &course, &dist );
+ }
// cout << "course = " << course << ", dist = " << dist << endl;
- double xoff = cos( course ) * dist / (2 * scale);
- double yoff = sin( course ) * dist / (2 * scale);
+
+ // calculate cloud movement due to external forces
+ double ax = 0.0, ay = 0.0, bx = 0.0, by = 0.0;
+
+ if (dist > 0.0) {
+ ax = cos(course) * dist;
+ ay = sin(course) * dist;
+ }
+
+ if (sp_dist > 0) {
+ bx = cos(-direction * SGD_DEGREES_TO_RADIANS) * sp_dist;
+ by = sin(-direction * SGD_DEGREES_TO_RADIANS) * sp_dist;
+ }
+
+
+ double xoff = (ax + bx) / (2 * scale);
+ double yoff = (ay + by) / (2 * scale);
const float layer_scale = layer_span / scale;
// cout << "base = " << base[0] << "," << base[1] << endl;
- for (int i = -2; i < 2; i++)
+ for (int i = 0; i < 4; i++)
{
- int row = i + 2;
-
- tc = tl[row]->get( 0 );
- sgSetVec2( tc, base[0] + layer_scale * (i+2)/4, base[1] );
+ tc = tl[i]->get( 0 );
+ sgSetVec2( tc, base[0] + layer_scale * i/4, base[1] );
- for (int j = -2; j < 2; j++)
+ for (int j = 0; j < 4; j++)
{
- tc = tl[row]->get( (j+2)*2+1 );
- sgSetVec2( tc, base[0] + layer_scale * (i+3)/4,
- base[1] + layer_scale * (j+2)/4 );
+ tc = tl[i]->get( j*2+1 );
+ sgSetVec2( tc, base[0] + layer_scale * (i+1)/4,
+ base[1] + layer_scale * j/4 );
- tc = tl[row]->get( (j+3)*2 );
- sgSetVec2( tc, base[0] + layer_scale * (i+2)/4,
- base[1] + layer_scale * (j+3)/4 );
+ tc = tl[i]->get( (j+1)*2 );
+ sgSetVec2( tc, base[0] + layer_scale * i/4,
+ base[1] + layer_scale * (j+1)/4 );
}
- tc = tl[row]->get( 9 );
- sgSetVec2( tc, base[0] + layer_scale * (i+3)/4,
+ tc = tl[i]->get( 9 );
+ sgSetVec2( tc, base[0] + layer_scale * (i+1)/4,
base[1] + layer_scale );
}
// make an ssgSimpleState for a cloud layer given the named texture
-ssgSimpleState *SGCloudMakeState( const string &path ) {
+ssgSimpleState *sgCloudMakeState( const string &path ) {
ssgSimpleState *state = new ssgSimpleState();
+ cout << " texture = " << path << endl;
+
state->setTexture( (char *)path.c_str() );
state->setShadeModel( GL_SMOOTH );
state->disable( GL_LIGHTING );
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->setMaterial( GL_EMISSION, 0.05, 0.05, 0.05, 1.0 );
+ state->setMaterial( GL_AMBIENT, 0.2, 0.2, 0.2, 1.0 );
+ state->setMaterial( GL_DIFFUSE, 0.5, 0.5, 0.5, 1.0 );
+ state->setMaterial( GL_SPECULAR, 1.0, 1.0, 1.0, 1.0 );
state->enable( GL_BLEND );
state->enable( GL_ALPHA_TEST );
state->setAlphaClamp( 0.01 );