* correct the heightmap formula (hopefully) - thx bLuma!

* use also surrounding MapTiles (now is a 3x3 map size instead of 1x1). is the formula for loading those correct?
This commit is contained in:
False.Genesis 2007-11-25 21:40:25 +00:00
parent bdbc8cc721
commit 9ec4fb2f8e
6 changed files with 44 additions and 26 deletions

View File

@ -57,6 +57,7 @@ private:
ShTlTerrainSceneNode *terrain;
MCameraFPS *camera;
MyEventReceiver *eventrecv;
ZThread::FastMutex mutex;
};

View File

@ -11,13 +11,14 @@
#include "World.h"
#include <sstream>
SceneWorld::SceneWorld(PseuGUI *g) : Scene(g)
{
DEBUG(logdebug("SceneWorld: Initializing..."));
s32 mapsize = 9 * 16; // 9 height floats in 16 chunks per tile per axis
s32 mapsize = 9 * 16 * 3; // 9 height floats in 16 chunks per tile per axis in 3 MapTiles
s32 tilesize = UNITSIZE;
s32 meshsize = CHUNKSIZE;
s32 meshsize = CHUNKSIZE*3;
vector3df terrainPos(0.0f, 0.0f, 0.0f); // TODO: use PseuWoW's world coords here?
eventrecv = new MyEventReceiver();
@ -60,35 +61,45 @@ SceneWorld::SceneWorld(PseuGUI *g) : Scene(g)
// something is not good here. we have terrain, but the chunks are read incorrectly.
// need to find out where which formula is wrong
// the current terrain renderer code is just a test to see if ADT files are read correctly. apparantly not :D
MapTile *maptile = mapmgr->GetCurrentTile();
if(maptile)
// the current terrain renderer code is just a test to see if ADT files are read correctly.
// EDIT: it seems to display fine now, but i am still not sure if the way it is done is correct...
mutex.acquire(); // prevent other threads deleting the maptile
for(s32 tiley = 0; tiley < 3; tiley++)
{
// apply map height data
for(uint32 chx = 0; chx < 16; chx++)
for(uint32 chy = 0; chy < 16; chy++)
for(s32 tilex = 0; tilex < 3; tilex++)
{
MapTile *maptile = mapmgr->GetNearTile(tilex - 1, tiley - 1);
if(maptile)
{
MapChunk *chunk = maptile->GetChunk(chx, chy);
std::stringstream ss;
DEBUG(logdebug("Apply MapChunk (%u, %u)",chx,chy));
for(uint32 hy = 0; hy < 9; hy++)
{
for(uint32 hx = 0; hx < 9; hx++)
// apply map height data
for(uint32 chy = 0; chy < 16; chy++)
for(uint32 chx = 0; chx < 16; chx++)
{
f32 h = chunk->hmap_rough[hy * 9 + hx];
ss.precision(3);
ss << h << '\t';
terrain->setHeight(9 * chx + hx, 9 * chy + hy, h);
MapChunk *chunk = maptile->GetChunk(chx, chy);
std::stringstream ss;
DEBUG(logdebug("Apply MapChunk (%u, %u)",chx,chy));
for(uint32 hy = 0; hy < 9; hy++)
{
for(uint32 hx = 0; hx < 9; hx++)
{
f32 h = chunk->hmap_rough[hx * 9 + hy] + chunk->baseheight; // not sure if hx and hy are used correctly here
h *= -1; // as suggested by bLuma
ss.precision(3);
ss << h << '\t';
terrain->setHeight((144 * tiley) + (9 * chx) + hx, (144 * tilex) + (9 * chy) + hy, h);
}
ss << "\n";
}
//DEBUG(logdebug("\n%s\n",ss.str().c_str()));
}
ss << "\n";
}
DEBUG(logdebug("\n%s\n",ss.str().c_str()));
}
else
{
logerror("SceneWorld: MapTile not loaded, can't apply heightmap!");
}
}
}
else
{
logerror("SceneWorld: MapTile not loaded, can't apply heightmap!");
}
mutex.release();
terrain->smoothNormals();

View File

@ -135,6 +135,11 @@ MapTile *MapMgr::GetCurrentTile(void)
return GetTile(_gridx,_gridy);
}
MapTile *MapMgr::GetNearTile(int32 xoffs, int32 yoffs)
{
return GetTile(_gridx + xoffs, _gridy + yoffs);
}
uint32 MapMgr::GetGridCoord(float f)
{
return (ZEROPOINT - f) / TILESIZE;

View File

@ -15,6 +15,7 @@ public:
uint32 GetGridCoord(float f);
MapTile *GetTile(uint32 xg, uint32 yg, bool forceLoad = false);
MapTile *GetCurrentTile(void);
MapTile *GetNearTile(int32, int32);
inline bool Loaded(void) { return _mapsLoaded; }
private:

View File

@ -2,7 +2,6 @@
#include "MapTile.h"
#include "log.h"
MapTile::MapTile()
{
}

View File

@ -17,6 +17,7 @@ class MapChunk
public:
float hmap_rough[9*9];
float hmap_fine[8*8];
float hmap[17*17]; // combined rough and fine hmap
float basex,basey,baseheight;
//... TODO: implement the rest of this
};