fix for height maps
--HG-- branch : trunk
This commit is contained in:
@@ -403,15 +403,14 @@ void TransformData()
|
|||||||
{
|
{
|
||||||
for(int y=0;y<128;y++)
|
for(int y=0;y<128;y++)
|
||||||
{
|
{
|
||||||
cell->v8[x][y] = (float)mcells->ch[x/8][y/8].v8[x%8][y%8];
|
cell->v8[y][x] = (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->v9[y][x] = (float)mcells->ch[x/8][y/8].v9[x%8][y%8];
|
||||||
}
|
}
|
||||||
|
|
||||||
//extra 1 point on bounds
|
//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
|
//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
|
//and the last 1
|
||||||
@@ -470,6 +469,7 @@ bool ConvertADT(char * filename,char * filename2)
|
|||||||
delete cell;
|
delete cell;
|
||||||
TransformData();
|
TransformData();
|
||||||
|
|
||||||
|
/*
|
||||||
for(unsigned int x=0;x<iRes;x++)
|
for(unsigned int x=0;x<iRes;x++)
|
||||||
for(unsigned int y=0;y<iRes;y++)
|
for(unsigned int y=0;y<iRes;y++)
|
||||||
{
|
{
|
||||||
@@ -478,8 +478,10 @@ bool ConvertADT(char * filename,char * filename2)
|
|||||||
(((double)(x))*TILESIZE)/((double)(iRes-1)));
|
(((double)(x))*TILESIZE)/((double)(iRes-1)));
|
||||||
|
|
||||||
fwrite(&z,1,sizeof(z),output);
|
fwrite(&z,1,sizeof(z),output);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
fwrite(&cell->v9, 1, sizeof(cell->v9), output);
|
||||||
|
fwrite(&cell->v8, 1, sizeof(cell->v8), output);
|
||||||
fclose(output);
|
fclose(output);
|
||||||
delete cell;
|
delete cell;
|
||||||
/*
|
/*
|
||||||
|
|||||||
+56
-2
@@ -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 gx=(int)(32-x/SIZE_OF_GRIDS); //grid x
|
||||||
int gy=(int)(32-y/SIZE_OF_GRIDS); //grid y
|
int gy=(int)(32-y/SIZE_OF_GRIDS); //grid y
|
||||||
|
|
||||||
float lx=MAP_RESOLUTION*(32 -x/SIZE_OF_GRIDS - gx);
|
float lx=128*(32 -x/SIZE_OF_GRIDS - gx);
|
||||||
float ly=MAP_RESOLUTION*(32 -y/SIZE_OF_GRIDS - gy);
|
float ly=128*(32 -y/SIZE_OF_GRIDS - gy);
|
||||||
|
|
||||||
// ensure GridMap is loaded
|
// ensure GridMap is loaded
|
||||||
const_cast<Map*>(this)->EnsureGridCreated(GridPair(63-gx,63-gy));
|
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 lx_int = (int)lx;
|
||||||
int ly_int = (int)ly;
|
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.
|
// In some very rare case this will happen. Need find a better way.
|
||||||
if(lx_int == MAP_RESOLUTION) --lx_int;
|
if(lx_int == MAP_RESOLUTION) --lx_int;
|
||||||
if(ly_int == MAP_RESOLUTION) --ly_int;
|
if(ly_int == MAP_RESOLUTION) --ly_int;
|
||||||
|
|
||||||
|
/*
|
||||||
float zi[4];
|
float zi[4];
|
||||||
// Probe 4 nearest points (except border cases)
|
// Probe 4 nearest points (except border cases)
|
||||||
zi[0] = gmap->Z[lx_int][ly_int];
|
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]
|
// 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);
|
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
|
// look from a bit higher pos to find the floor, ignore under surface case
|
||||||
if(z + 2.0f > _mapheight)
|
if(z + 2.0f > _mapheight)
|
||||||
mapHeight = _mapheight;
|
mapHeight = _mapheight;
|
||||||
|
|||||||
+3
-1
@@ -75,7 +75,9 @@ typedef struct
|
|||||||
uint16 area_flag[16][16];
|
uint16 area_flag[16][16];
|
||||||
uint8 terrain_type[16][16];
|
uint8 terrain_type[16][16];
|
||||||
float liquid_level[128][128];
|
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;
|
}GridMap;
|
||||||
|
|
||||||
struct CreatureMover
|
struct CreatureMover
|
||||||
|
|||||||
Reference in New Issue
Block a user