// // texture_cloud.cc // // Procedural cloud texture. // // Copyright (C) J. Belson 2003.09.27 // // $Id: texture_cloud.cc,v 1.1 2003/10/11 18:11:00 jon Exp $ // #include "texture_cloud.h" /** * Load current settings. * @param ts textset_cloud instance to load into. */ void textset_cloud::load_settings(textset_cloud& ts) { settings* my_settings = settings::get_instance(); my_settings->get_colour(SKY_HORIZON_COLOUR, &ts.horizon_colour); my_settings->get_colour(SKY_ZENITH_COLOUR, &ts.zenith_colour); my_settings->get_int(CLOUD_SEED, &ts.seed); my_settings->get_colour(CLOUD_COLOUR, &ts.fg); my_settings->get_float(CLOUD_PERSISTENCE, &ts.persistence); my_settings->get_float(CLOUD_PRESENCE, &ts.presence); my_settings->get_float(CLOUD_COVER, &ts.cloud_cover); my_settings->get_float(CLOUD_SCALE, &ts.scale); } /** * Constructor. */ texture_cloud::texture_cloud(const textset_cloud& ts) : texture(ts) { my_settings = settings::get_instance(); scale = ts.scale; presence = ts.presence; cloud_cover = ts.cloud_cover; horizon_colour = ts.horizon_colour; zenith_colour = ts.zenith_colour; #ifdef USE_OLD_PERLIN noise = new perlin; noise->set_seed(ts.seed); noise->set_persistence(ts.persistence); noise->set_iterations(3); #else noise = new perlin2; noise->set_seed(ts.seed); //noise->set_freq_scale(scale); scale *= 25; #endif } /** * Destructor. */ texture_cloud::~texture_cloud() { delete noise; } /** * Calculate colour at specified point. * @param s Texture coordinate. * @param t Texture coordinate. * @param u Texture coordinate. * @return Colour at specified point. */ fcolour texture_cloud::colour(float s, float t, float /*u*/, vector3d*) { #ifdef USE_OLD_PERLIN // XXX original perlin routine cant handle -ve texture coordinates static const int TERRAIN_WIDTH = 256; float height = noise->perlin_noise_2d(scale*s + TERRAIN_WIDTH/2, scale*t + TERRAIN_WIDTH/2); #else point2d pnt(scale*s, scale*t); float height = noise->noise2(pnt); #endif // fcolour difference = zenith_colour - horizon_colour; // fcolour sky = zenith_colour + difference * (u - SKYDOME_OFFSET)/SKYDOME_SCALE; // Calculate clound density float val = cloud_cover + presence*height; if (val < 0) { val = 0; } float density = 1.0 - pow(0.5, val); fcolour colour = fg; //*density; colour.alpha = density; return colour; }