#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::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;
}
// 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;
// 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 );