diff options
author | DiSlord <none@none> | 2009-02-20 16:12:47 -0600 |
---|---|---|
committer | DiSlord <none@none> | 2009-02-20 16:12:47 -0600 |
commit | f1c13a7c79f7c2eb5d1d08d3e4724a29d383538c (patch) | |
tree | fd76047eef95e93215476c4d6b6f2e988a89185d | |
parent | 956c828bf56f06b5c25ff20d760ad41be2642a51 (diff) |
fix for height maps
--HG--
branch : trunk
-rw-r--r-- | contrib/extractor/adt.cpp | 14 | ||||
-rw-r--r-- | src/game/Map.cpp | 58 | ||||
-rw-r--r-- | src/game/Map.h | 4 |
3 files changed, 67 insertions, 9 deletions
diff --git a/contrib/extractor/adt.cpp b/contrib/extractor/adt.cpp index 37e4c0883d9..b512fc6a715 100644 --- a/contrib/extractor/adt.cpp +++ b/contrib/extractor/adt.cpp @@ -403,15 +403,14 @@ void TransformData() { for(int y=0;y<128;y++) { - cell->v8[x][y] = (float)mcells->ch[x/8][y/8].v8[x%8][y%8]; - cell->v9[x][y] = (float)mcells->ch[x/8][y/8].v9[x%8][y%8]; + cell->v8[y][x] = (float)mcells->ch[x/8][y/8].v8[x%8][y%8]; + cell->v9[y][x] = (float)mcells->ch[x/8][y/8].v9[x%8][y%8]; } //extra 1 point on bounds - cell->v9[x][128] = (float)mcells->ch[x/8][15].v9[x%8][8]; + cell->v9[128][x] = (float)mcells->ch[x/8][15].v9[x%8][8]; //x==y - cell->v9[128][x] = (float)mcells->ch[15][x/8].v9[8][x%8]; - + cell->v9[x][128] = (float)mcells->ch[15][x/8].v9[8][x%8]; } //and the last 1 @@ -470,6 +469,7 @@ bool ConvertADT(char * filename,char * filename2) delete cell; TransformData(); + /* for(unsigned int x=0;x<iRes;x++) for(unsigned int y=0;y<iRes;y++) { @@ -478,8 +478,10 @@ bool ConvertADT(char * filename,char * filename2) (((double)(x))*TILESIZE)/((double)(iRes-1))); fwrite(&z,1,sizeof(z),output); - } + }*/ + fwrite(&cell->v9, 1, sizeof(cell->v9), output); + fwrite(&cell->v8, 1, sizeof(cell->v8), output); fclose(output); delete cell; /* diff --git a/src/game/Map.cpp b/src/game/Map.cpp index 2211aa5b69c..8d0b40c90ac 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -1082,8 +1082,8 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const int gx=(int)(32-x/SIZE_OF_GRIDS); //grid x int gy=(int)(32-y/SIZE_OF_GRIDS); //grid y - float lx=MAP_RESOLUTION*(32 -x/SIZE_OF_GRIDS - gx); - float ly=MAP_RESOLUTION*(32 -y/SIZE_OF_GRIDS - gy); + float lx=128*(32 -x/SIZE_OF_GRIDS - gx); + float ly=128*(32 -y/SIZE_OF_GRIDS - gy); // ensure GridMap is loaded const_cast<Map*>(this)->EnsureGridCreated(GridPair(63-gx,63-gy)); @@ -1095,10 +1095,63 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const int lx_int = (int)lx; int ly_int = (int)ly; + lx -= lx_int; + ly -= ly_int; + + float a,b,c; + if (lx+ly < 1) + { + if (lx > ly) + { + // 1 + float h1 = gmap->v9[lx_int][ly_int]; + float h2 = gmap->v9[lx_int+1][ly_int]; + float h5 = 2 * gmap->v8[lx_int][ly_int]; + a = h2-h1; + b = h5-h1-h2; + c = h1; + } + else + { + // 2 + float h1 = gmap->v9[lx_int][ly_int]; + float h3 = gmap->v9[lx_int][ly_int+1]; + float h5 = 2 * gmap->v8[lx_int][ly_int]; + a = h5 - h1 - h3; + b = h3 - h1; + c = h1; + } + } + else + { + if (lx > ly) + { + // 3 + float h2 = gmap->v9[lx_int+1][ly_int]; + float h4 = gmap->v9[lx_int+1][ly_int+1]; + float h5 = 2 * gmap->v8[lx_int][ly_int]; + a = h2 + h4 - h5; + b = h4 - h2; + c = h5 - h4; + } + else + { + // 4 + float h3 = gmap->v9[lx_int][ly_int+1]; + float h4 = gmap->v9[lx_int+1][ly_int+1]; + float h5 = 2 * gmap->v8[lx_int][ly_int]; + a = h4 - h3; + b = h3 + h4 - h5; + c = h5 - h4; + } + } + float _mapheight = a * lx + b * ly + c; + // In some very rare case this will happen. Need find a better way. if(lx_int == MAP_RESOLUTION) --lx_int; if(ly_int == MAP_RESOLUTION) --ly_int; + /* float zi[4]; // Probe 4 nearest points (except border cases) zi[0] = gmap->Z[lx_int][ly_int]; @@ -1117,6 +1170,7 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const // Use the simplified bilinear equation, as described in [url="http://en.wikipedia.org/wiki/Bilinear_interpolation"]http://en.wikipedia.org/wiki/Bilinear_interpolation[/url] float _mapheight = b[0] + (b[1]*fact_x) + (b[2]*fact_y) + (b[3]*fact_x*fact_y); + */ // look from a bit higher pos to find the floor, ignore under surface case if(z + 2.0f > _mapheight) mapHeight = _mapheight; diff --git a/src/game/Map.h b/src/game/Map.h index fb921309cba..10d8c914cc2 100644 --- a/src/game/Map.h +++ b/src/game/Map.h @@ -75,7 +75,9 @@ typedef struct uint16 area_flag[16][16]; uint8 terrain_type[16][16]; float liquid_level[128][128]; - float Z[MAP_RESOLUTION][MAP_RESOLUTION]; + float v9[16 * 8 + 1][16 * 8 + 1]; + float v8[16 * 8][16 * 8]; + //float Z[MAP_RESOLUTION][MAP_RESOLUTION]; }GridMap; struct CreatureMover |