03-08-2006, Thursday-12:01:18
Das Karteformat stammt aus der Computersteinzeit. Es geht nicht viel simpler as so: (Das "Format" ist das PPM-Format.)
Code:
/**
* Calculates preview from height map
* @param filename name of heightfield file
* @author Hajo/prissi
*/
bool
welt_gui_t::update_from_heightfield(const char *filename)
{
FILE *file = fopen(filename, "rb");
if(file) {
char buf [256];
int w, h;
read_line(buf, 255, file);
if(buf[0]!='P' || buf[1]!='6') {
return false;
}
read_line(buf, 255, file);
sscanf(buf, "%d %d", &w, &h);
read_line(buf, 255, file);
if(buf[0]!='2' || buf[1]!='5' || buf[2]!='5') {
return false;
}
for(int y=0, y=0; y<h; y++) {
// new line?
for(int x=0; x<w; x++) {
sint16 R = (unsigned char)fgetc(file);
sint16 G = (unsigned char)fgetc(file);
sint16 B = (unsigned char)fgetc(file);
karte[(y*w)+x] = reliefkarte_t::calc_hoehe_farbe( (((R*2+G*3+B)/4 - 224+16)&(sint16)0xFFF0), sets->gib_grundwasser() );
}
}