* updated ShTLTerrainSceneNode to official irr 1.4 version (with some changes)

* some renderer settings can now be modified via conf
* disabled irrlicht logger console spam
This commit is contained in:
false_genesis 2008-04-20 21:34:01 +00:00
parent d2dc2b82a2
commit 170006b659
12 changed files with 489 additions and 274 deletions

View File

@ -22,3 +22,48 @@ shadows=1
// color depth; 16 or 32 bit
depth=32
//================================================================================================
// Expert options: Renderer finetuning
// Uncomment/Adjust the following settings if you really know what you do or if you need some extra performance!
// Set a value to 0 or comment it out to use the default setting.
//------------------------------------------------------------------------------------------------
// The terrain is split into sectors, here you can specify how many will be used on every axis.
// Each sector is seperately culled if not visible, removing GPU load, but the culling test takes up some CPU.
// If the terrain draw size is very large, it might be better to increase the sector amount. [Default: 5]
//TerrainSectors=5
// The higher this value is, the more CPU+GPU power is needed to render the terrain.
// Note that if you set it too low, you will get hard terrin cut-offs in some distance.
// It looks best if this value is larger then <fogfar>. [Default: <farclip> * 0.33]
//TerrainDrawSize=300
// The terrain gets updated after walking some distance over it. Updating needs some CPU, but the more often
// it is updated the smoother it will look like. If the fog starts early enough and covers places where there is no terrain drawn yet
// (depends also on <TerrainDrawSize>) there will be no real visual disadvantages. [Default: 1 (min: 1, max: 50)]
//TerrainUpdateStep=3
// The distance until the driver will stop drawing. This value has the most impact on the framerate, but setting it too low
// will end up in a very short view distance. If your hardware is good enough, set it as high as possible, but don't forget to
// adjust terrain drawing and fog distances if you do! [Default: 533.33]
//farclip=533.33
// The fog gets 100% thickness in the distance specified here. [Default: <farclip> * 0.7]
//fogfar=380
// The fog starts here, getting thicker until reaching <fogfar>. [Default: <fogfar> * 0.75]
//fognear=280
// Field of view. The higher the FOV is the more of the scene is visible on the screen, but the more distorted the scene will be!
// Examples: < 0.5 is like looking through a sniper scope
// > 1.0 is the best setting for a "normal" field of view
// > 1.4 is like looking through a fish's eye
// > 2 offers a very high but still playable field of view, but can cause extreme headache after a while
// 2.5 isn't a reasonable value anymore (psychotic)
// at around 3 it starts f***ing up the renderer
// Note that the FOV also has a great impact on the framerate, the higher the value is, the less frames per sec.
// [Default: 1.25]
//FOV=1.1

View File

@ -2,12 +2,6 @@
#include "CM2MeshFileLoader.h"
#include "common.h"
#ifdef _DEBUG
#define DEBUG(code) code;
#else
#define DEBUG(code) ;
#endif
namespace irr
{
@ -204,7 +198,7 @@ for(u32 i=0; i<M2MTextureDef.size(); i++)
file->seek(M2MTextureDef[i].texFileOfs);
file->read((void*)tempTexFileName.c_str(),M2MTextureDef[i].texFileLen);
M2MTextureFiles.push_back(tempTexFileName.c_str());
std::cout<<M2MTextureFiles.size()<<"-"<<M2MTextureFiles[i].c_str()<<"\n";
DEBUG(logdebug("Texture: %u (%s)",M2MTextureFiles.size(),M2MTextureFiles[i].c_str()));
}
// std::cout << "Read "<<M2MTextureFiles.size()<<"/"<<M2MTextureDef.size()<<" Texture file names\n";

View File

@ -121,6 +121,9 @@ void PseuGUI::_Init(void)
_timer = _device->getTimer();
//...
// disable crappy irrlicht logging
_device->getLogger()->setLogLevel(ELL_NONE);
// register external loaders for not supported filetypes
video::CImageLoaderBLP* BLPloader = new video::CImageLoaderBLP();
_driver->addExternalImageLoader(BLPloader);

View File

@ -108,8 +108,6 @@ private:
ZThread::FastMutex mutex;
PseuGUI *gui;
uint32 map_gridX, map_gridY;
s32 mapsize, meshsize;
f32 tilesize;
WorldSession *wsession;
World *world;
MapMgr *mapmgr;

View File

@ -24,9 +24,6 @@ SceneWorld::SceneWorld(PseuGUI *g) : Scene(g)
world = wsession->GetWorld();
mapmgr = world->GetMapMgr();
// TODO: hardcoded for now, make this adjustable later
float fogdist = 150;
ILightSceneNode* light = smgr->addLightSceneNode(0, core::vector3df(0,0,0), SColorf(255, 255, 255, 255), 1000.0f);
SLight ldata = light->getLightData();
ldata.AmbientColor = video::SColorf(0.2f,0.2f,0.2f);
@ -40,7 +37,19 @@ SceneWorld::SceneWorld(PseuGUI *g) : Scene(g)
camera = new MCameraFPS(smgr);
camera->setNearValue(0.1f);
camera->setFarValue(TILESIZE); // TODO: make this configurable later
f32 farclip = instance->GetConf()->farclip;
if(farclip < 50)
farclip = TILESIZE;
f32 fov = instance->GetConf()->fov;
if(!iszero(fov))
{
logdetail("Camera: Field of view (FOV) = %.3f",fov);
camera->setFOV(fov);
}
camera->setFarValue(farclip);
debugText = guienv->addStaticText(L"< debug text >",rect<s32>(0,0,driver->getScreenSize().Width,30),true,true,0,-1,true);
@ -56,8 +65,16 @@ SceneWorld::SceneWorld(PseuGUI *g) : Scene(g)
sky->remove(); // thus we grab the sky node while removing it from rendering.
*/
f32 fogfar = camera->getFarValue() * 0.7f;
f32 fognear = fogfar * 0.75f;
f32 fogfar = instance->GetConf()->fogfar;
if(fogfar < 30)
fogfar = farclip * 0.7f;
f32 fognear = instance->GetConf()->fognear;
if(fognear < 10)
fognear = fogfar * 0.75f;
logdetail("GUI: Using farclip=%.2f fogfar=%.2f fognear=%.2f", farclip, fogfar, fognear);
driver->setFog(envBasicColor, true, fognear, fogfar, 0.02f);
// setup cursor
@ -212,6 +229,10 @@ void SceneWorld::OnUpdate(s32 timediff)
str += (int)terrain->getSectorsRendered();
str += L" / ";
str += (int)terrain->getSectorCount();
str += L" (";
str += (u32)(((f32)terrain->getSectorsRendered()/(f32)terrain->getSectorCount())*100.0f);
str += L"%)";
str += L"\n";
@ -273,17 +294,28 @@ void SceneWorld::InitTerrain(void)
gui->SetSceneState(SCENESTATE_GUISTART);
return;
}
s32 mapsize = (8 * 16 * 3) - 1; // 9-1 height floats in 16 chunks per tile per axis in 3 MapTiles
mapsize = (8 * 16 * 3) - 1; // 9-1 height floats in 16 chunks per tile per axis in 3 MapTiles
tilesize = UNITSIZE;
meshsize = (s32)TILESIZE/3;
// terrain rendering settings
u32 rendersize = instance->GetConf()->terrainrendersize;
if(!rendersize)
rendersize = camera->getFarValue() / 3.0f;
//camera->setPosition(core::vector3df(mapsize*tilesize/2, 0, mapsize*tilesize/2) + terrainPos);
u32 sectors = instance->GetConf()->terrainsectors;
if(!sectors)
sectors = 5;
terrain = new ShTlTerrainSceneNode(smgr,mapsize,mapsize,tilesize,meshsize);
u32 step = instance->GetConf()->terrainupdatestep;
if(!step || step > 50)
step = 1;
logdetail("Terrain: Using %ux%u sectors, rendersize=%u, updatestep=%u",sectors,sectors,rendersize,step);
terrain = new ShTlTerrainSceneNode(smgr,mapsize,mapsize,UNITSIZE,rendersize,sectors);
terrain->drop();
terrain->setStep(step);
terrain->follow(camera->getNode());
terrain->getMaterial(0).setTexture(0, driver->getTexture("data/misc/dirt_test.jpg"));
terrain->getMaterial(0).setTexture(1,driver->getTexture("data/misc/dirt_test.jpg"));
terrain->getMaterial(0).setFlag(video::EMF_LIGHTING, true);
terrain->getMaterial(0).setFlag(video::EMF_FOG_ENABLE, true);

View File

@ -1,10 +1,23 @@
/*-----------------------------------------------------------------------------*
| sourcefile ShTlTerrainSceneNode.cpp |
| |
| version 2.20 |
| date: (17.04.2008) |
| |
| author: Michal Švantner |
| |
| Shifting Tiled Terrain Scene Node |
| |
| Writen for Irrlicht engine version 1.4 |
*-----------------------------------------------------------------------------*/
#include "ShTlTerrainSceneNode.h"
// constructor
ShTlTerrainSceneNode::ShTlTerrainSceneNode(scene::ISceneManager* pSceneManager,
s32 width, s32 height, f32 tilesize, s32 visiblesize,
ShTlTerrainSceneNode::ShTlTerrainSceneNode(scene::ISceneManager* smgr,
s32 width, s32 height, f32 tilesize, s32 visiblesize, s32 sect,
scene::ISceneNode* parent, s32 id)
: scene::ISceneNode(pSceneManager->getRootSceneNode(), pSceneManager, id)
: scene::ISceneNode(smgr->getRootSceneNode(), smgr, id)
{
Size.Width = width;
Size.Height = height;
@ -51,12 +64,16 @@ ShTlTerrainSceneNode::ShTlTerrainSceneNode(scene::ISceneManager* pSceneManager,
// calculate number of sectors
// terrain mesh will be split to 1 or 3 or 5 sectors on each axis depending on size
s32 w = 1;
s32 h = 1;
s32 w,h;
w = h = sect;
if(!(w && h))
{
w = h = 1;
if(MeshSize.Width >= 30) w = 3;
if(MeshSize.Height >= 30) h = 3;
if(MeshSize.Width >= 50) w = 5;
if(MeshSize.Height >= 50) h = 5;
}
// create sectors
Sector.reset(w, h);
@ -67,7 +84,7 @@ ShTlTerrainSceneNode::ShTlTerrainSceneNode(scene::ISceneManager* pSceneManager,
for(s32 j=0; j<Sector.height(); j++)
for(s32 i=0; i<Sector.width(); i++)
Sector(i,j).Size = core::dimension2d<u32>(w, h);
Sector(i,j).Size = core::dimension2d<s32>(w, h);
// find size of center sector in tiles
w = MeshSize.Width - Sector(0,0).Size.Width * (Sector.width()-1);
@ -122,13 +139,13 @@ ShTlTerrainSceneNode::ShTlTerrainSceneNode(scene::ISceneManager* pSceneManager,
for(s32 j=0; j<Sector.height(); j++)
for(s32 i=0; i<Sector.width(); i++)
{
u32 k = 0;
s32 k = 0;
for(u32 n=0; n<Sector(i,j).Size.Height; n++)
for(u32 m=0; m<Sector(i,j).Size.Width; m++)
for(s32 n=0; n<Sector(i,j).Size.Height; n++)
for(s32 m=0; m<Sector(i,j).Size.Width; m++)
{
u32 x = m + Sector(i,j).Offset.X;
u32 y = n + Sector(i,j).Offset.Y;
s32 x = m + Sector(i,j).Offset.X;
s32 y = n + Sector(i,j).Offset.Y;
Tile(x,y).Vertex[0] = &Sector(i,j).Vertex[k];
k++;
@ -182,23 +199,23 @@ ShTlTerrainSceneNode::ShTlTerrainSceneNode(scene::ISceneManager* pSceneManager,
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, mmflag);
Material[0].TextureLayer[1].Texture = CTexture;
Material[0].TextureLayer[1].TextureWrap = video::ETC_CLAMP_TO_EDGE;
Material[0].TextureLayer[0].Texture = CTexture;
Material[0].TextureLayer[0].TextureWrap = video::ETC_CLAMP_TO_EDGE;
// setup UV coordinates of vertices on 2nd texture layer
f32 ax = (f32)MeshSize.Width / CTexture->getSize().Width / MeshSize.Width;
f32 ay = (f32)MeshSize.Height/ CTexture->getSize().Height / MeshSize.Height;
f32 ry = 1.0f - (f32)MeshSize.Height/ CTexture->getSize().Height;
u32 n = MeshSize.Height-1;
s32 n = MeshSize.Height-1;
for(s32 j=0; j<MeshSize.Height; j++)
{
for(s32 i=0; i<MeshSize.Width; i++)
{
Tile(i,n).Vertex[0]->TCoords2 = core::vector2d<f32>(i*ax, ry+(j+1)*ay);
Tile(i,n).Vertex[1]->TCoords2 = core::vector2d<f32>(i*ax, ry+j*ay);
Tile(i,n).Vertex[3]->TCoords2 = core::vector2d<f32>((i+1)*ax, ry+(j+1)*ay);
Tile(i,n).Vertex[2]->TCoords2 = core::vector2d<f32>((i+1)*ax, ry+j*ay);
Tile(i,n).Vertex[0]->TCoords = core::vector2d<f32>(i*ax, ry+(j+1)*ay);
Tile(i,n).Vertex[1]->TCoords = core::vector2d<f32>(i*ax, ry+j*ay);
Tile(i,n).Vertex[3]->TCoords = core::vector2d<f32>((i+1)*ax, ry+(j+1)*ay);
Tile(i,n).Vertex[2]->TCoords = core::vector2d<f32>((i+1)*ax, ry+j*ay);
}
n--;
}
@ -231,7 +248,6 @@ ShTlTerrainSceneNode::ShTlTerrainSceneNode(scene::ISceneManager* pSceneManager,
// culling will be done by terrain itself, sector by sector so that sectors
// which are not on screen will not be renderd to save time
setAutomaticCulling( scene::EAC_OFF );
}
@ -376,6 +392,7 @@ void ShTlTerrainSceneNode::render()
}
}
}
}
@ -425,7 +442,7 @@ void ShTlTerrainSceneNode::recalculateBoundingBox()
// returns amount of materials used by terrain
u32 ShTlTerrainSceneNode::getMaterialCount()
u32 ShTlTerrainSceneNode::getMaterialCount() const
{
return Material.size();
}
@ -451,7 +468,7 @@ s32 ShTlTerrainSceneNode::getStep()
// set number of tiles to skip before terrain mesh gets updated
// default is 1
// updating slows down rendering and seting step higher will cause terrain to update less ofthen
void ShTlTerrainSceneNode::setStep(u32 newstep)
void ShTlTerrainSceneNode::setStep(s32 newstep)
{
ShStep = newstep;
}
@ -496,7 +513,7 @@ core::dimension2d<s32> ShTlTerrainSceneNode::getRenderedSize()
// return number of sectors
u32 ShTlTerrainSceneNode::getSectorCount()
s32 ShTlTerrainSceneNode::getSectorCount()
{
return Sector.width() * Sector.height();
}
@ -504,7 +521,7 @@ u32 ShTlTerrainSceneNode::getSectorCount()
// returns numner of sectors rendered last frame
u32 ShTlTerrainSceneNode::getSectorsRendered()
s32 ShTlTerrainSceneNode::getSectorsRendered()
{
return SectorsRendered;
}
@ -512,7 +529,7 @@ u32 ShTlTerrainSceneNode::getSectorsRendered()
// return height of terrain spot at terrain coordinates
f32 ShTlTerrainSceneNode::getHeight(u32 w, u32 h)
f32 ShTlTerrainSceneNode::getHeight(s32 w, s32 h)
{
return Data(w,h).Height;
}
@ -565,7 +582,7 @@ f32 ShTlTerrainSceneNode::getHeight(core::vector3df pos)
// set relative height of terrain spot at terrain coordinates
void ShTlTerrainSceneNode::setHeight(u32 w, u32 h, f32 newheight)
void ShTlTerrainSceneNode::setHeight(s32 w, s32 h, f32 newheight)
{
Data(w,h).Height = newheight;
@ -593,7 +610,7 @@ void ShTlTerrainSceneNode::setHeight(u32 w, u32 h, f32 newheight)
// return normal of terrain at terrain coordinates
core::vector3df ShTlTerrainSceneNode::getNormal(u32 w, u32 h)
core::vector3df ShTlTerrainSceneNode::getNormal(s32 w, s32 h)
{
return Data(w,h).Normal;
}
@ -697,7 +714,7 @@ void ShTlTerrainSceneNode::smoothNormals()
// get texture coordinates of tile corner
core::vector2d<f32> ShTlTerrainSceneNode::getTileUV(u32 w, u32 h, TILE_VERTEX corner)
core::vector2d<f32> ShTlTerrainSceneNode::getTileUV(s32 w, s32 h, TILE_VERTEX corner)
{
return UVdata(w,h).Vertex[corner];
}
@ -705,7 +722,7 @@ core::vector2d<f32> ShTlTerrainSceneNode::getTileUV(u32 w, u32 h, TILE_VERTEX co
// set texture coordinates of tile
void ShTlTerrainSceneNode::setTileUV(u32 w, u32 h, core::vector2d<f32> UVlowerLeft,
void ShTlTerrainSceneNode::setTileUV(s32 w, s32 h, core::vector2d<f32> UVlowerLeft,
core::vector2d<f32> UVupperLeft, core::vector2d<f32> UVupperRight,
core::vector2d<f32> UVlowerRight)
{
@ -723,7 +740,7 @@ void ShTlTerrainSceneNode::stretchTexture(core::vector2d<f32> scale)
f32 ax = scale.X / Size.Width;
f32 ay = scale.X / Size.Height;
u32 n = Size.Height-1;
s32 n = Size.Height-1;
for(s32 j=0; j<Size.Height; j++)
{
for(s32 i=0; i<Size.Width; i++)
@ -755,7 +772,7 @@ void ShTlTerrainSceneNode::stretchTextureOverTile(core::vector2d<f32> scale)
// rotate texture of tile 90 degrees
void ShTlTerrainSceneNode::rotateTileTexture90(u32 w, u32 h)
void ShTlTerrainSceneNode::rotateTileTexture90(s32 w, s32 h)
{
core::vector2d<f32> tmp = UVdata(w,h).Vertex[3];
@ -768,7 +785,7 @@ void ShTlTerrainSceneNode::rotateTileTexture90(u32 w, u32 h)
// rotate texture of tile 180 degrees
void ShTlTerrainSceneNode::rotateTileTexture180(u32 w, u32 h)
void ShTlTerrainSceneNode::rotateTileTexture180(s32 w, s32 h)
{
core::vector2d<f32> tmp = UVdata(w,h).Vertex[3];
@ -784,7 +801,7 @@ void ShTlTerrainSceneNode::rotateTileTexture180(u32 w, u32 h)
// rotate texture of tile 270 degrees
void ShTlTerrainSceneNode::rotateTileTexture270(u32 w, u32 h)
void ShTlTerrainSceneNode::rotateTileTexture270(s32 w, s32 h)
{
core::vector2d<f32> tmp = UVdata(w,h).Vertex[3];
@ -797,7 +814,7 @@ void ShTlTerrainSceneNode::rotateTileTexture270(u32 w, u32 h)
// flip (mirror) texture of tile horizontaly
void ShTlTerrainSceneNode::flipTileTextureHorizontal(u32 w, u32 h)
void ShTlTerrainSceneNode::flipTileTextureHorizontal(s32 w, s32 h)
{
core::vector2d<f32> tmp = UVdata(w,h).Vertex[3];
@ -813,7 +830,7 @@ void ShTlTerrainSceneNode::flipTileTextureHorizontal(u32 w, u32 h)
// flip (mirror) texture of tile verticaly
void ShTlTerrainSceneNode::flipTileTextureVertical(u32 w, u32 h)
void ShTlTerrainSceneNode::flipTileTextureVertical(s32 w, s32 h)
{
core::vector2d<f32> tmp = UVdata(w,h).Vertex[3];
@ -829,7 +846,7 @@ void ShTlTerrainSceneNode::flipTileTextureVertical(u32 w, u32 h)
// get color of tile at terrain coordinates
video::SColor ShTlTerrainSceneNode::getColor(u32 w, u32 h)
video::SColor ShTlTerrainSceneNode::getColor(s32 w, s32 h)
{
return Data(w,h).Color;
}
@ -837,7 +854,7 @@ video::SColor ShTlTerrainSceneNode::getColor(u32 w, u32 h)
// set color of tile at terrain coordinates
void ShTlTerrainSceneNode::setColor(u32 w, u32 h, video::SColor newcolor)
void ShTlTerrainSceneNode::setColor(s32 w, s32 h, video::SColor newcolor)
{
Data(w,h).Color = newcolor;
}
@ -1052,7 +1069,7 @@ bool ShTlTerrainSceneNode::getIntersectionWithLine( core::line3d<f32> line, core
// load height data from texture
void ShTlTerrainSceneNode::loadHeightMap(const c8 *filename, f32 scale, u32 w, u32 h)
void ShTlTerrainSceneNode::loadHeightMap(const c8 *filename, f32 scale, s32 w, s32 h)
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
if(!driver) return;
@ -1095,7 +1112,7 @@ void ShTlTerrainSceneNode::loadHeightMap(const c8 *filename, f32 scale, u32 w, u
// load color data from texture
void ShTlTerrainSceneNode::loadColorMap(const c8 *filename, u32 w, u32 h)
void ShTlTerrainSceneNode::loadColorMap(const c8 *filename, s32 w, s32 h)
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
if(!driver) return;
@ -1103,8 +1120,8 @@ void ShTlTerrainSceneNode::loadColorMap(const c8 *filename, u32 w, u32 h)
video::IImage *image = driver->createImageFromFile(filename);
if(!image) return;
s32 tw = (u32)image->getDimension().Width;
s32 th = (u32)image->getDimension().Height;
s32 tw = image->getDimension().Width;
s32 th = image->getDimension().Height;
s32 we = w + tw;
if(we > Size.Width+1) we = Size.Width+1;
@ -1120,7 +1137,7 @@ void ShTlTerrainSceneNode::loadColorMap(const c8 *filename, u32 w, u32 h)
{
video::SColor color = image->getPixel(tw, th);
Data(i,j).Color = color;
setColor(i,j, color);
tw++;
}
@ -1145,32 +1162,32 @@ bool ShTlTerrainSceneNode::isSectorOnScreen(TlTSector* sctr)
// get camera frustrum planes
const scene::SViewFrustum* frustrum = SceneManager->getActiveCamera()->getViewFrustum();
core::plane3d<f32> Left = frustrum->planes[scene::SViewFrustum::VF_LEFT_PLANE];
core::plane3d<f32> Right = frustrum->planes[scene::SViewFrustum::VF_RIGHT_PLANE];
core::plane3d<f32> Top = frustrum->planes[scene::SViewFrustum::VF_TOP_PLANE];
core::plane3d<f32> Bottom = frustrum->planes[scene::SViewFrustum::VF_BOTTOM_PLANE];
core::plane3d<f32> Near = frustrum->planes[scene::SViewFrustum::VF_NEAR_PLANE];
core::plane3d<f32> Far = frustrum->planes[scene::SViewFrustum::VF_FAR_PLANE];
core::plane3d<f32> left = frustrum->planes[scene::SViewFrustum::VF_LEFT_PLANE];
core::plane3d<f32> right = frustrum->planes[scene::SViewFrustum::VF_RIGHT_PLANE];
core::plane3d<f32> top = frustrum->planes[scene::SViewFrustum::VF_TOP_PLANE];
core::plane3d<f32> bottom = frustrum->planes[scene::SViewFrustum::VF_BOTTOM_PLANE];
core::plane3d<f32> near = frustrum->planes[scene::SViewFrustum::VF_NEAR_PLANE];
core::plane3d<f32> far = frustrum->planes[scene::SViewFrustum::VF_FAR_PLANE];
// test sector bounding box against planes
s32 leftRel, rightRel, topRel, bottomRel, nearRel, farRel;
nearRel = box.classifyPlaneRelation(Near);
nearRel = box.classifyPlaneRelation(near);
if(nearRel == core::ISREL3D_FRONT) return false;
leftRel = box.classifyPlaneRelation(Left);
leftRel = box.classifyPlaneRelation(left);
if(leftRel == core::ISREL3D_FRONT) return false;
rightRel = box.classifyPlaneRelation(Right);
rightRel = box.classifyPlaneRelation(right);
if(rightRel == core::ISREL3D_FRONT) return false;
bottomRel = box.classifyPlaneRelation(Bottom);
bottomRel = box.classifyPlaneRelation(bottom);
if(bottomRel == core::ISREL3D_FRONT) return false;
farRel = box.classifyPlaneRelation(Far);
farRel = box.classifyPlaneRelation(far);
if(farRel == core::ISREL3D_FRONT) return false;
topRel = box.classifyPlaneRelation(Top);
topRel = box.classifyPlaneRelation(top);
if(topRel == core::ISREL3D_FRONT) return false;
return true;
@ -1181,15 +1198,12 @@ bool ShTlTerrainSceneNode::isSectorOnScreen(TlTSector* sctr)
// update vertices of sector
void ShTlTerrainSceneNode::updateVertices(TlTSector &sector)
{
scene::SMeshBuffer* MeshBuffer=new scene::SMeshBuffer();
scene::SMesh* Mesh=new scene::SMesh();
for(u32 j=sector.Offset.Y; j<sector.Offset.Y+sector.Size.Height; j++)
for(u32 i=sector.Offset.X; i<sector.Offset.X+sector.Size.Width; i++)
for(s32 j=sector.Offset.Y; j<sector.Offset.Y+sector.Size.Height; j++)
for(s32 i=sector.Offset.X; i<sector.Offset.X+sector.Size.Width; i++)
{
// positon of tile relative to terrain
u32 x = i + MeshPosition.X;
u32 y = j + MeshPosition.Y;
s32 x = i + MeshPosition.X;
s32 y = j + MeshPosition.Y;
// update position
Tile(i,j).Vertex[0]->Pos = core::vector3df(x*TileSize, Data(x,y).Height, y*TileSize);
@ -1198,33 +1212,17 @@ void ShTlTerrainSceneNode::updateVertices(TlTSector &sector)
Tile(i,j).Vertex[3]->Pos = core::vector3df( (x+1)*TileSize, Data(x+1,y).Height, y*TileSize);
// update normals
Tile(i,j).Vertex[0]->Normal = Data(x,y).Normal;
Tile(i,j).Vertex[1]->Normal = Data(x,y+1).Normal;
Tile(i,j).Vertex[2]->Normal = Data(x+1,y+1).Normal;
Tile(i,j).Vertex[3]->Normal = Data(x+1,y).Normal;
Tile(i,j).Vertex[0]->Normal = getNormal(x,y);
Tile(i,j).Vertex[1]->Normal = getNormal(x,y+1);
Tile(i,j).Vertex[2]->Normal = getNormal(x+1,y+1);
Tile(i,j).Vertex[3]->Normal = getNormal(x+1,y);
// update texture coordinates
Tile(i,j).Vertex[0]->TCoords = UVdata(x,y).Vertex[0];
Tile(i,j).Vertex[1]->TCoords = UVdata(x,y).Vertex[1];
Tile(i,j).Vertex[2]->TCoords = UVdata(x,y).Vertex[2];
Tile(i,j).Vertex[3]->TCoords = UVdata(x,y).Vertex[3];
for (int z=0;z<4;z++)
MeshBuffer->Vertices.push_back(video::S3DVertex(
Tile(i,j).Vertex[z]->Pos,
core::vector3df(0,0,0), video::SColor(0,0,0,0), core::vector2df(0,0)));
Tile(i,j).Vertex[0]->TCoords2 = getTileUV(x,y,LOWER_LEFT);
Tile(i,j).Vertex[1]->TCoords2 = getTileUV(x,y,UPPER_LEFT);
Tile(i,j).Vertex[2]->TCoords2 = getTileUV(x,y,UPPER_RIGHT);
Tile(i,j).Vertex[3]->TCoords2 = getTileUV(x,y,LOWER_RIGHT);
}
for (u32 z=0;z<sector.Index.size();z++)
{
MeshBuffer->Indices.push_back(
sector.Index[z]);
}
Mesh->addMeshBuffer(MeshBuffer);
MeshBuffer->drop();
Mesh->drop();
}
@ -1232,24 +1230,24 @@ void ShTlTerrainSceneNode::updateVertices(TlTSector &sector)
// update 2nd texture layer
void ShTlTerrainSceneNode::updateTexture(u32* p, TlTSector &sector)
{
u32 x, y;
s32 x, y;
// in case created texure is larger than terrain mesh, update one more pixel
// on each axis to get rid of unused pixels at the border blended in to used ones
u32 w = 0;
s32 w = 0;
if(MeshSize.Width < CTexture->getSize().Width) w = 1;
u32 h = 0;
s32 h = 0;
if(MeshSize.Height < CTexture->getSize().Height) h = 1;
for(u32 j=sector.Offset.Y; j<sector.Offset.Y + sector.Size.Height + h; j++)
for(s32 j=sector.Offset.Y; j<sector.Offset.Y + sector.Size.Height + h; j++)
{
u32 n = CTexture->getSize().Height-1 - j;
for(u32 i=sector.Offset.X; i<sector.Offset.X + sector.Size.Width + w; i++)
s32 n = CTexture->getSize().Height-1 - j;
for(s32 i=sector.Offset.X; i<sector.Offset.X + sector.Size.Width + w; i++)
{
x = i + MeshPosition.X;
y = j + MeshPosition.Y;
p[n*CTexture->getSize().Width + i] = Data(x,y).Color.color;
p[n*CTexture->getSize().Width + i] = getColor(x,y).color;
}
}
}

View File

@ -1,8 +1,8 @@
/*-----------------------------------------------------------------------------*
| headerfile ShTlTerrainSceneNode.h |
| |
| version 2.00 |
| date: (29.04.2007) |
| version 2.20 |
| date: (17.04.2008) |
| |
| author: Michal Švantner |
| |
@ -43,7 +43,7 @@
| Rendered mesh is split in to seweral sectors which are culled individualy. |
| This exclude around 60% of polygoons from rendering. |
| |
| Writen for Irrlicht engine version 1.3 |
| Writen for Irrlicht engine version 1.4 |
*-----------------------------------------------------------------------------*/
#ifndef SHTLTERRAINSCENENODE_H
@ -94,7 +94,7 @@ class ShTlTerrainSceneNode : public scene::ISceneNode
video::ITexture* CTexture;
// number of sectors rendered last frame
u32 SectorsRendered;
s32 SectorsRendered;
// howe many tiles should be skiped before terrain mesh gets updated
s32 ShStep;
@ -122,8 +122,8 @@ public:
// \param rendersize -size of rendered terrain mesh in tiles
// \param parent -parent scene node
// \param id -ID number
ShTlTerrainSceneNode(scene::ISceneManager* pSceneManager, s32 width, s32 height,
f32 tilesize, s32 rendersize, scene::ISceneNode* parent = 0, s32 id = -1);
ShTlTerrainSceneNode(scene::ISceneManager* smgr, s32 width, s32 height,
f32 tilesize, s32 rendersize, s32 sect = 0, scene::ISceneNode* parent = 0, s32 id = -1);
// destructor
~ShTlTerrainSceneNode();
@ -142,7 +142,7 @@ public:
// returns amount of materials used by terrain
// this terrain uses only one material
virtual u32 getMaterialCount();
virtual u32 getMaterialCount() const;
// returns the material of terrain based on the zero based index
// \param i -index of material to return
@ -154,7 +154,7 @@ public:
// set number of tiles to skip before terrain mesh gets updated, default is 1
// updating slows down rendering and seting step higher will cause terrain to update less ofthen
// \param newstep -amount of tiles to skip before updating
virtual void setStep(u32 newstep);
virtual void setStep(s32 newstep);
// return dimensions of whole terrain in tiles
virtual core::dimension2d<s32> getSize();
@ -170,15 +170,15 @@ public:
virtual core::dimension2d<s32> getRenderedSize();
// return number of sectors into which terrain mesh is divided
virtual u32 getSectorCount();
virtual s32 getSectorCount();
// returns sectors rendered last frame
virtual u32 getSectorsRendered();
virtual s32 getSectorsRendered();
// return relative height of terrain spot at terrain coordinates
// \param w -width coordinate of spot in tiles
// \param h -height coordinate of spot in tiles
virtual f32 getHeight(u32 w, u32 h);
virtual f32 getHeight(s32 w, s32 h);
// return height of terrain at any position
// \param pos -3d coordinates at which to get height of terrain
@ -188,12 +188,12 @@ public:
// \param w -width coordinate of spot in tiles
// \param h -height coordinate of spot in tiles
// \param newheight -new height of spot
virtual void setHeight(u32 w, u32 h, f32 newheight);
virtual void setHeight(s32 w, s32 h, f32 newheight);
// return normal of terrain at terrain coordinates
// \param w -width coordinate of spot in tiles
// \param h -height coordinate of spot in tiles
virtual core::vector3df getNormal(u32 w, u32 h);
virtual core::vector3df getNormal(s32 w, s32 h);
// set normal of terrain at terrain coordinates
// \param w -width coordinate of spot in tiles
@ -213,7 +213,7 @@ public:
// \param w -width coordinate of tile
// \param h -height coordinate of tile
// \param corner -tile corner, can be LOWER_LEFT, UPPER_LEFT, UPPER_RIGHT, LOWER_RIGHT
virtual core::vector2d<f32> getTileUV(u32 w, u32 h, TILE_VERTEX corner);
virtual core::vector2d<f32> getTileUV(s32 w, s32 h, TILE_VERTEX corner);
// set texture coordinates of tile
// \param w -width coordinate of tile
@ -222,7 +222,7 @@ public:
// \param UVUpperLeft -UV coordinates of upper left corner
// \param UVUpperRight -UV coordinates of upper right corner
// \param UVLowerRight -UV coordinates of lower right corner
virtual void setTileUV(u32 w, u32 h, core::vector2d<f32> UVLowerLeft,
virtual void setTileUV(s32 w, s32 h, core::vector2d<f32> UVLowerLeft,
core::vector2d<f32> UVUpperLeft, core::vector2d<f32> UVUpperRight,
core::vector2d<f32> UVLowerRight);
@ -237,38 +237,38 @@ public:
// rotate texture of tile 90 degrees
// \param w -width coordinate of tile
// \param h -height coordinate of tile
virtual void rotateTileTexture90(u32 w, u32 h);
virtual void rotateTileTexture90(s32 w, s32 h);
// rotate texture of tile 180 degrees
// \param w -width coordinate of tile
// \param h -height coordinate of tile
virtual void rotateTileTexture180(u32 w, u32 h);
virtual void rotateTileTexture180(s32 w, s32 h);
// rotate texture of tile 270 degrees
// \param w -width coordinate of tile
// \param h -height coordinate of tile
virtual void rotateTileTexture270(u32 w, u32 h);
virtual void rotateTileTexture270(s32 w, s32 h);
// flip (mirror) texture of tile horizontaly
// \param w -width coordinate of tile
// \param h -height coordinate of tile
virtual void flipTileTextureHorizontal(u32 w, u32 h);
virtual void flipTileTextureHorizontal(s32 w, s32 h);
// flip (mirror) texture of tile verticaly
// \param w -width coordinate of tile
// \param h -height coordinate of tile
virtual void flipTileTextureVertical(u32 w, u32 h);
virtual void flipTileTextureVertical(s32 w, s32 h);
// get color of tile at terrain coordinates
// \param w -width coordinate of tile
// \param h -height coordinate of tile
virtual video::SColor getColor(u32 w, u32 h);
virtual video::SColor getColor(s32 w, s32 h);
// set color of tile at terrain coordinates
// \param w -width coordinate of tile
// \param h -height coordinate of tile
// \param newcolor -new color of tile
virtual void setColor(u32 w, u32 h, video::SColor newcolor);
virtual void setColor(s32 w, s32 h, video::SColor newcolor);
// set rendered mesh position relative to terrain
// note that origin of mesh is in its lower left corner
@ -304,7 +304,7 @@ public:
// \param scale -scale to apply at height data, if you want white color to be height of 10.5 set scale to 10.5
// \param w -width coordinate of tile were to start loading
// \param h -height coordinate of tile were to start loading
virtual void loadHeightMap(const c8 *filename, f32 scale, u32 w = 0, u32 h = 0);
virtual void loadHeightMap(const c8 *filename, f32 scale, s32 w = 0, s32 h = 0);
// load color data from texture
// parameters allow to specify place where to load data, which makes possible
@ -312,6 +312,6 @@ public:
// \param filename -filename of texture
// \param w -width coordinate of tile were to start loading
// \param h -height coordinate of tile were to start loading
virtual void loadColorMap(const c8 *filename, u32 w = 0, u32 h = 0);
virtual void loadColorMap(const c8 *filename, s32 w = 0, s32 h = 0);
};
#endif

View File

@ -1,19 +1,19 @@
/*-----------------------------------------------------------------------------*
| headerfile TLTMesh.h |
| |
| version 1.00 |
| date: (17.04.2007) |
| version 1.10 |
| date: (07.04.2008) |
| |
| author: Michal Švantner |
| |
| Some structures used for Tiled Terrain |
| Writen for Irrlicht engine version 1.3 |
| Writen for Irrlicht engine version 1.4 |
*-----------------------------------------------------------------------------*/
#ifndef TLTMESH_H
#define TLTMESH_H
#include <irrlicht/irrlicht.h>
#include "irrlicht/irrlicht.h"
using namespace irr;
@ -27,12 +27,21 @@ template <class T> class array2d
public:
array2d() : w(0), h(0) {}
array2d(int width, int height) : w(width), h(height)
array2d(s32 width, s32 height) : w(width), h(height)
{
data = new T*[w];
for(int i=0; i<w; i++) data[i] = new T[h];
}
virtual ~array2d()
{
if(w && h)
{
for(int i=0; i<w; i++) delete [] data[i];
delete [] data;
}
}
virtual void reset(int width, int height)
{
if(w && h)
@ -56,16 +65,7 @@ public:
}
}
~array2d()
{
if(w && h)
{
for(int i=0; i<w; i++) delete [] data[i];
delete [] data;
}
}
virtual T& operator ()(u32 index1, u32 index2)
virtual T& operator ()(s32 index1, s32 index2)
{
return data[index1][index2];
}
@ -116,16 +116,13 @@ struct TlTData
// structure which is used as meshbuffer for Tiled Terrain
class TlTSector
struct TlTSector
{
public:
TlTSector() {};
~TlTSector() {};
// position relative to whole mesh of which sector is part in tiles
core::vector2d<s32> Offset;
// dimension of sector in tiles
core::dimension2d<u32> Size;
core::dimension2d<s32> Size;
// array of vertices
core::array<video::S3DVertex2TCoords> Vertex;

130
src/Client/GUI/TlTSector.h Normal file
View File

@ -0,0 +1,130 @@
#ifndef TLMESH_H
#define TLMESH_H
#include <irrlicht.h>
using namespace irr;
template <class T> class array2d
{
T** data;
u32 w, h;
public:
array2d() : w(0), h(0) {}
array2d(int width, int height) : w(width), h(height)
{
data = new T*[w];
for(int i=0; i<w; i++) data[i] = new T[h];
}
virtual void reset(int width, int height)
{
if(w && h)
{
for(int i=0; i<w; i++) delete data[i];
delete [] data;
}
if(width && height)
{
w = width;
h = height;
data = new T*[w];
for(int i=0; i<w; i++) data[i] = new T[h];
}
else
{
w = 0;
h = 0;
}
}
~array2d()
{
if(w && h)
{
for(int i=0; i<w; i++) delete data[i];
delete [] data;
}
}
virtual T& operator ()(u32 index1, u32 index2)
{
return data[index1][index2];
}
virtual u32 width() {return w;}
virtual u32 height() {return h;}
};
enum TILE_VERTEX
{
LOWER_LEFT = 0,
UPPER_LEFT,
UPPER_RIGHT,
LOWER_RIGHT,
};
struct TlTTile
{
video::S3DVertex2TCoords* Vertex[4];
};
struct TlTCoords
{
core::vector2d<f32> Vertex[4];
};
struct TlTData
{
f32 Height;
core::vector3df Normal;
video::SColor Color;
};
struct TlTSector
{
core::vector2d<s32> Offset;
core::dimension2d<u32> Size;
core::array<video::S3DVertex2TCoords> Vertex;
core::array<u16> Index;
core::aabbox3d<f32> BoundingBox;
array2d<TlTTile> Tile;
virtual void addTile()
{
u32 n = Vertex.size();
video::S3DVertex2TCoords v;
Vertex.push_back(v);
Vertex.push_back(v);
Vertex.push_back(v);
Vertex.push_back(v);
Index.push_back(n);
Index.push_back(n+1);
Index.push_back(n+2);
Index.push_back(n);
Index.push_back(n+2);
Index.push_back(n+3);
}
virtual void recalculateBoundingBox()
{
if(Vertex.empty())
BoundingBox.reset(0,0,0);
else
{
BoundingBox.reset(Vertex[0].Pos);
for(u32 i=1; i<Vertex.size(); ++i)
BoundingBox.addInternalPoint(Vertex[i].Pos);
}
}
};
#endif

View File

@ -488,6 +488,15 @@ void PseuInstanceConf::ApplyFromVarSet(VarSet &v)
}
}
// GUI related
terrainsectors = atoi(v.Get("GUI::TERRAINSECTORS").c_str());
terrainrendersize = atoi(v.Get("GUI::TERRAINRENDERSIZE").c_str());
terrainupdatestep = atoi(v.Get("GUI::TERRAINUPDATESTEP").c_str());
farclip = atof(v.Get("GUI::FARCLIP").c_str());
fogfar = atof(v.Get("GUI::FOGFAR").c_str());
fognear = atof(v.Get("GUI::FOGNEAR").c_str());
fov = atof(v.Get("GUI::FOV").c_str());
log_setloglevel(debug);
}

View File

@ -60,7 +60,13 @@ class PseuInstanceConf
// gui related
bool enablegui;
// need more here
uint32 terrainsectors;
uint32 terrainrendersize;
uint32 terrainupdatestep;
float farclip;
float fogfar;
float fognear;
float fov;
};

View File

@ -489,6 +489,9 @@
<File
RelativePath=".\Client\Gui\TlTMesh.h">
</File>
<File
RelativePath=".\Client\Gui\TlTSector.h">
</File>
</Filter>
</Filter>
<Filter