- if ( !cld_def ) return;
-
- double min_width = cld_def->getDoubleValue("min-cloud-width-m", 500.0);
- double max_width = cld_def->getDoubleValue("max-cloud-width-m", 1000.0);
- double min_height = cld_def->getDoubleValue("min-cloud-height-m", min_width);
- double max_height = cld_def->getDoubleValue("max-cloud-height-m", max_width);
- double min_sprite_width = cld_def->getDoubleValue("min-sprite-width-m", 200.0);
- double max_sprite_width = cld_def->getDoubleValue("max-sprite-width-m", min_sprite_width);
- double min_sprite_height = cld_def->getDoubleValue("min-sprite-height-m", min_sprite_width);
- double max_sprite_height = cld_def->getDoubleValue("max-sprite-height-m", max_sprite_width);
- int num_sprites = cld_def->getIntValue("num-sprites", 20);
- int num_textures_x = cld_def->getIntValue("num-textures-x", 1);
- int num_textures_y = cld_def->getIntValue("num-textures-y", 1);
- double bottom_shade = cld_def->getDoubleValue("bottom-shade", 1.0);
- string texture = cld_def->getStringValue("texture", "cl_cumulus.rgb");
-
- SGNewCloud *cld =
- new SGNewCloud(type,
- texture_root,
- texture,
- min_width,
- max_width,
- min_height,
- max_height,
- min_sprite_width,
- max_sprite_width,
- min_sprite_height,
- max_sprite_height,
- bottom_shade,
- num_sprites,
- num_textures_x,
- num_textures_y);
- layer->addCloud(newpos, cld);
+ if ( !cld_def ) return 0.0;
+
+ double w = abox->getDoubleValue("width", 1000.0);
+ double h = abox->getDoubleValue("height", 1000.0);
+ int hdist = abox->getIntValue("hdist", 1);
+ int vdist = abox->getIntValue("vdist", 1);
+
+ double c = abox->getDoubleValue("count", 5);
+ int count = (int) (c + (sg_random() - 0.5) * c);
+
+ extent = max(w*w, extent);
+
+ for (int j = 0; j < count; j++) {
+
+ // Locate the clouds randomly in the defined space. The hdist and
+ // vdist values control the horizontal and vertical distribution
+ // by simply summing random components.
+ double x = 0.0;
+ double y = 0.0;
+ double z = 0.0;
+
+ for (int k = 0; k < hdist; k++)
+ {
+ x += (sg_random() / hdist);
+ y += (sg_random() / hdist);
+ }
+
+ for (int k = 0; k < vdist; k++)
+ {
+ z += (sg_random() / vdist);
+ }
+
+ x = w * (x - 0.5) + pos[0]; // N/S
+ y = w * (y - 0.5) + pos[1]; // E/W
+ z = h * z + pos[2]; // Up/Down. pos[2] is the cloudbase
+
+ SGVec3f newpos = SGVec3f(x, y, z);
+
+ double min_width = cld_def->getDoubleValue("min-cloud-width-m", 500.0);
+ double max_width = cld_def->getDoubleValue("max-cloud-width-m", 1000.0);
+ double min_height = cld_def->getDoubleValue("min-cloud-height-m", min_width);
+ double max_height = cld_def->getDoubleValue("max-cloud-height-m", max_width);
+ double min_sprite_width = cld_def->getDoubleValue("min-sprite-width-m", 200.0);
+ double max_sprite_width = cld_def->getDoubleValue("max-sprite-width-m", min_sprite_width);
+ double min_sprite_height = cld_def->getDoubleValue("min-sprite-height-m", min_sprite_width);
+ double max_sprite_height = cld_def->getDoubleValue("max-sprite-height-m", max_sprite_width);
+ int num_sprites = cld_def->getIntValue("num-sprites", 20);
+ int num_textures_x = cld_def->getIntValue("num-textures-x", 1);
+ int num_textures_y = cld_def->getIntValue("num-textures-y", 1);
+ double bottom_shade = cld_def->getDoubleValue("bottom-shade", 1.0);
+ string texture = cld_def->getStringValue("texture", "cu.png");
+
+ SGNewCloud *cld =
+ new SGNewCloud(type,
+ texture_root,
+ texture,
+ min_width,
+ max_width,
+ min_height,
+ max_height,
+ min_sprite_width,
+ max_sprite_width,
+ min_sprite_height,
+ max_sprite_height,
+ bottom_shade,
+ num_sprites,
+ num_textures_x,
+ num_textures_y);
+ layer->addCloud(newpos, cld);
+ }