// // colour.cc // // Colour utility functions // // Copyright (c) J. Belson 1999.01.31 // // $Author: jon $ : $Date: 2003/05/21 11:40:09 $ // #include "fcolour.h" #include "colour.h" #include "hf.h" #include "types.h" #include "settings.h" static unsigned char palette[5][3] = { { 222, 228, 244 }, { 90, 100, 90 }, { 82, 121, 57 }, /*{ 53, 52, 0},*/ { 60, 100, 132 }, /*{ 85, 103, 158 },*/ { 40, 40, 181 } /*{ 89, 99, 148 }*/ }; const float SEA_LEVEL = -0.1*256*0.15; const float GRASS_LEVEL = -0.01;//0.0; const float MOUNTAIN_LEVEL = 0.4*256*0.15; const float SNOW_LEVEL = 0.6*256*0.15; /** * Prepare colour class to provide RGB information */ void colour::init_colour(void) { uint8 r, g, b; fcolour col; settings::get_instance()->get_colour(WATER_COLOUR, &col); col.get_rgb8(&r, &g, &b); palette[3][0] = r; palette[3][1] = g; palette[3][2] = b; } /** * Calculate colour for specifed heightfield */ fcolour colour::get_colour_from_height(float height) { uint8 r, g, b; if (height > SNOW_LEVEL) { height -= SNOW_LEVEL; r = palette[0][0]; g = palette[0][1]; b = palette[0][2]; } else if (height > MOUNTAIN_LEVEL) { r = palette[1][0]; // + (10 - rand()%20); g = palette[1][1]; // + (10 - rand()%20); b = palette[1][2]; //+ (10 - rand()%20); } else if (height >= GRASS_LEVEL) { //int offset = rand()%10 + rand()%10; r = palette[2][0]; //+ (10 - rand()%20); g = palette[2][1] /*+ 3*offset*/; //+ (5 - rand()%10); b = palette[2][2]; //+ (10 - rand()%20); } else if (height > SEA_LEVEL) { r = palette[3][0]; g = palette[3][1]; b = palette[3][2]; } else { r = palette[4][0]; g = palette[4][1]; b = palette[4][2]; } return fcolour(r/255.0, g/255.0, b/255.0); }