00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "flattern.h"
00021
00022 #include "map.h"
00023
00024 #include <cmath>
00025
00026 namespace MapGen
00027 {
00028
00029
00030 Flattern::Flattern()
00031 {
00032 MAP_DEBUG( "ctor1" );
00033 }
00034
00035
00036
00037 Flattern::Flattern( const float power ):
00038 _power(power)
00039 {
00040 MAP_DEBUG( "ctor2" );
00041 }
00042
00043
00044
00045 Flattern::~Flattern()
00046 {
00047 MAP_DEBUG( "dtor" );
00048 }
00049
00050
00051
00052 void Flattern::apply( Map* map )
00053 {
00054 float min, max;
00055 _getMinMax( map, &min, &max );
00056
00057 float coef = fabs( max - min );
00058
00059 for( uint x=0 ; x<map->getW() ; ++x )
00060 for( uint y=0 ; y<map->getH() ; ++y )
00061 {
00062 if( min >= 0 )
00063 {
00064 map->setAt( x, y, powf((map->getAt(x,y)-min)/coef,_power)*coef+min );
00065 }
00066 else
00067 {
00068 float h = map->getAt(x,y);
00069 if( h >= 0 )
00070 {
00071 map->setAt( x, y, powf(h/max,_power)*max );
00072 }
00073 else
00074 {
00075 map->setAt( x, y, fabs(powf(fabs(h)/min,_power))*min );
00076 }
00077 }
00078 }
00079 }
00080
00081 }