* 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:
parent
bdbc8cc721
commit
9ec4fb2f8e
@ -57,6 +57,7 @@ private:
|
|||||||
ShTlTerrainSceneNode *terrain;
|
ShTlTerrainSceneNode *terrain;
|
||||||
MCameraFPS *camera;
|
MCameraFPS *camera;
|
||||||
MyEventReceiver *eventrecv;
|
MyEventReceiver *eventrecv;
|
||||||
|
ZThread::FastMutex mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -11,13 +11,14 @@
|
|||||||
#include "World.h"
|
#include "World.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
SceneWorld::SceneWorld(PseuGUI *g) : Scene(g)
|
SceneWorld::SceneWorld(PseuGUI *g) : Scene(g)
|
||||||
{
|
{
|
||||||
DEBUG(logdebug("SceneWorld: Initializing..."));
|
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 tilesize = UNITSIZE;
|
||||||
s32 meshsize = CHUNKSIZE;
|
s32 meshsize = CHUNKSIZE*3;
|
||||||
vector3df terrainPos(0.0f, 0.0f, 0.0f); // TODO: use PseuWoW's world coords here?
|
vector3df terrainPos(0.0f, 0.0f, 0.0f); // TODO: use PseuWoW's world coords here?
|
||||||
|
|
||||||
eventrecv = new MyEventReceiver();
|
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.
|
// something is not good here. we have terrain, but the chunks are read incorrectly.
|
||||||
// need to find out where which formula is wrong
|
// 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
|
// the current terrain renderer code is just a test to see if ADT files are read correctly.
|
||||||
MapTile *maptile = mapmgr->GetCurrentTile();
|
// EDIT: it seems to display fine now, but i am still not sure if the way it is done is correct...
|
||||||
if(maptile)
|
mutex.acquire(); // prevent other threads deleting the maptile
|
||||||
|
for(s32 tiley = 0; tiley < 3; tiley++)
|
||||||
{
|
{
|
||||||
// apply map height data
|
for(s32 tilex = 0; tilex < 3; tilex++)
|
||||||
for(uint32 chx = 0; chx < 16; chx++)
|
{
|
||||||
for(uint32 chy = 0; chy < 16; chy++)
|
MapTile *maptile = mapmgr->GetNearTile(tilex - 1, tiley - 1);
|
||||||
|
if(maptile)
|
||||||
{
|
{
|
||||||
MapChunk *chunk = maptile->GetChunk(chx, chy);
|
// apply map height data
|
||||||
std::stringstream ss;
|
for(uint32 chy = 0; chy < 16; chy++)
|
||||||
DEBUG(logdebug("Apply MapChunk (%u, %u)",chx,chy));
|
for(uint32 chx = 0; chx < 16; chx++)
|
||||||
for(uint32 hy = 0; hy < 9; hy++)
|
|
||||||
{
|
|
||||||
for(uint32 hx = 0; hx < 9; hx++)
|
|
||||||
{
|
{
|
||||||
f32 h = chunk->hmap_rough[hy * 9 + hx];
|
MapChunk *chunk = maptile->GetChunk(chx, chy);
|
||||||
ss.precision(3);
|
std::stringstream ss;
|
||||||
ss << h << '\t';
|
DEBUG(logdebug("Apply MapChunk (%u, %u)",chx,chy));
|
||||||
terrain->setHeight(9 * chx + hx, 9 * chy + hy, h);
|
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
|
mutex.release();
|
||||||
{
|
|
||||||
logerror("SceneWorld: MapTile not loaded, can't apply heightmap!");
|
|
||||||
}
|
|
||||||
|
|
||||||
terrain->smoothNormals();
|
terrain->smoothNormals();
|
||||||
|
|
||||||
|
|||||||
@ -135,6 +135,11 @@ MapTile *MapMgr::GetCurrentTile(void)
|
|||||||
return GetTile(_gridx,_gridy);
|
return GetTile(_gridx,_gridy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MapTile *MapMgr::GetNearTile(int32 xoffs, int32 yoffs)
|
||||||
|
{
|
||||||
|
return GetTile(_gridx + xoffs, _gridy + yoffs);
|
||||||
|
}
|
||||||
|
|
||||||
uint32 MapMgr::GetGridCoord(float f)
|
uint32 MapMgr::GetGridCoord(float f)
|
||||||
{
|
{
|
||||||
return (ZEROPOINT - f) / TILESIZE;
|
return (ZEROPOINT - f) / TILESIZE;
|
||||||
|
|||||||
@ -15,6 +15,7 @@ public:
|
|||||||
uint32 GetGridCoord(float f);
|
uint32 GetGridCoord(float f);
|
||||||
MapTile *GetTile(uint32 xg, uint32 yg, bool forceLoad = false);
|
MapTile *GetTile(uint32 xg, uint32 yg, bool forceLoad = false);
|
||||||
MapTile *GetCurrentTile(void);
|
MapTile *GetCurrentTile(void);
|
||||||
|
MapTile *GetNearTile(int32, int32);
|
||||||
inline bool Loaded(void) { return _mapsLoaded; }
|
inline bool Loaded(void) { return _mapsLoaded; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
#include "MapTile.h"
|
#include "MapTile.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
|
||||||
MapTile::MapTile()
|
MapTile::MapTile()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@ class MapChunk
|
|||||||
public:
|
public:
|
||||||
float hmap_rough[9*9];
|
float hmap_rough[9*9];
|
||||||
float hmap_fine[8*8];
|
float hmap_fine[8*8];
|
||||||
|
float hmap[17*17]; // combined rough and fine hmap
|
||||||
float basex,basey,baseheight;
|
float basex,basey,baseheight;
|
||||||
//... TODO: implement the rest of this
|
//... TODO: implement the rest of this
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user