fix for height maps

--HG--
branch : trunk
This commit is contained in:
DiSlord
2009-02-20 16:12:47 -06:00
parent 956c828bf5
commit f1c13a7c79
3 changed files with 67 additions and 9 deletions
+8 -6
View File
@@ -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;
/*
+56 -2
View File
@@ -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;
+3 -1
View File
@@ -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