X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fsky%2Fcloud.cxx;h=720e53cddca449f7257929e784ca0a2bd85a6a03;hb=1dde23a0c948d3f002789de3c7d096ae063f72e7;hp=e64d8648ad4332f402c2f8423402c6de5aa7cde5;hpb=1fce27f0c3d363dae413071c5e154ce029305fe9;p=simgear.git diff --git a/simgear/scene/sky/cloud.cxx b/simgear/scene/sky/cloud.cxx index e64d8648..720e53cd 100644 --- a/simgear/scene/sky/cloud.cxx +++ b/simgear/scene/sky/cloud.cxx @@ -32,8 +32,9 @@ #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 @@ -47,6 +48,8 @@ SGCloudLayer::SGCloudLayer( const string &tex_path ) : 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) { @@ -55,9 +58,6 @@ SGCloudLayer::SGCloudLayer( const string &tex_path ) : 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(); } @@ -90,9 +90,16 @@ SGCloudLayer::getElevation_m () const } 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 @@ -139,33 +146,37 @@ SGCloudLayer::setCoverage (Coverage coverage) 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; } @@ -183,6 +194,7 @@ SGCloudLayer::rebuild() const float layer_scale = layer_span / scale; const float mpi = SG_PI/4; + const float alt_diff = layer_asl * 0.8; for (int i = 0; i < 4; i++) { @@ -196,7 +208,7 @@ SGCloudLayer::rebuild() sgSetVec3( vertex, layer_span*(i-2)/2, -layer_span, - 500 * (sin(i*mpi) - 2) ); + alt_diff * (sin(i*mpi) - 2) ); sgSetVec2( tc, base[0] + layer_scale * i/4, base[1] ); @@ -209,7 +221,7 @@ SGCloudLayer::rebuild() for (int j = 0; j < 4; j++) { sgSetVec3( vertex, layer_span*(i-1)/2, layer_span*(j-2)/2, - 500 * (sin((i+1)*mpi) + sin(j*mpi) - 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 ); @@ -224,7 +236,7 @@ SGCloudLayer::rebuild() sgSetVec3( vertex, layer_span*(i-2)/2, layer_span*(j-1)/2, - 500 * (sin(i*mpi) + sin((j+1)*mpi) - 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 ); @@ -238,7 +250,7 @@ SGCloudLayer::rebuild() } sgSetVec3( vertex, layer_span*(i-1)/2, layer_span, - 500 * (sin((i+1)*mpi) - 2) ); + alt_diff * (sin((i+1)*mpi) - 2) ); sgSetVec2( tc, base[0] + layer_scale * (i+1)/4, base[1] + layer_scale ); @@ -283,7 +295,7 @@ bool SGCloudLayer::repaint( sgVec3 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; @@ -341,15 +353,35 @@ bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat, 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; @@ -424,9 +456,11 @@ void SGCloudLayer::draw() { // 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 ); @@ -434,8 +468,10 @@ ssgSimpleState *SGCloudMakeState( const string &path ) { 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 );