Jump to content
  • Advertisement
Sign in to follow this  
MichaeldeJong

[IRRLICHT] 3D tile-based world problem

This topic is 2350 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone! This one is a bit hard to explain...
I made a tile-based world, and sometimes you can look between some tiles and you see a vertical (or horizontal) gap between two columns of tiles. This gap is about 1 px wide and has the same color as the background, so I guess it really is a gap between the tiles, and not a real rendered "line".
This bug only occurs a very few times when moving the camera and then quickly disappears.
Here is a screenshot of what it looked like:

Howker_tilebug.JPG

Here is a small example program with the irrlicht engine. There are black tiles and sometimes you can see white lines.
White is the background color, so it must be a gap between the tiles:



#define SCREEN_WIDTH 1024
#define SCREEN_HEIGHT 768

const float TILE_RATIO = [color=#800080]0.09f;
const float TILE_HEIGHT = 32 * TILE_RATIO;
const float TILE_WIDTH = 32 * TILE_RATIO;

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(lib, "Irrlicht.lib")
#endif

#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace std;

class Tile
{
public:
Tile(IVideoDriver *driver, ISceneManager *smgr, int x, int y);

private:
ISceneManager *m_Smgr;
IVideoDriver *m_Driver;
IMeshSceneNode *m_Node;
int m_X, m_Y, m_Z;
vector3df m_Pos;
};


Tile::Tile(IVideoDriver *driver, ISceneManager *smgr, int x, int y) : m_Driver(driver), m_Smgr(smgr), m_X(x), m_Y(y)
{
float posX = m_X * TILE_WIDTH;
float posY = (m_Y *TILE_HEIGHT) + 32*TILE_RATIO/2;
m_Pos = vector3df(posX, posY, [color=#800080]0.0f);

IMesh* m = m_Smgr->getGeometryCreator()->createPlaneMesh(dimension2df(32*TILE_RATIO, 32*TILE_RATIO), dimension2d<u32>(1, 1), 0, dimension2df(1, 1));
m_Node = m_Smgr->addMeshSceneNode(m);
m_Node->setPosition(m_Pos);
m_Node->setRotation(vector3df(270,0,0));
m_Node->setAutomaticCulling(EAC_OFF);
m_Node->setMaterialFlag(EMF_BILINEAR_FILTER , true);
}


int main()
{
SIrrlichtCreationParameters param;
param.DriverType = video::EDT_DIRECT3D9;
param.WindowSize = irr::core::dimension2d<u32>(SCREEN_WIDTH, SCREEN_HEIGHT);
param.Bits = 32;
param.Fullscreen = false;
param.Stencilbuffer = false;
param.Vsync = true;
param.AntiAlias = false;
IrrlichtDevice* device = createDeviceEx(param);

video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();

//#######CAMERA#########
scene::ICameraSceneNode* m_Camera = smgr->addCameraSceneNode();
m_Camera->setTarget(irr::core::vector3df([color=#800080]0.0f,[color=#800080]0.0f,[color=#800080]0.0f));
m_Camera->setPosition(irr::core::vector3df([color=#800080]0.0f, [color=#800080]0.0f, -[color=#800080]500.0f));

irr::core::matrix4 projMat;
projMat.buildProjectionMatrixOrthoLH(SCREEN_WIDTH/11,SCREEN_HEIGHT/11,1,1000);
m_Camera->setProjectionMatrix(projMat);

//#######################

//#######TILES######### (DONT MIND THE MEMORY LEAKS. THIS IS JUST A TEST)
for(int x = -100; x < 100; x++)
{
for(int y = -20; y < 20; y++)
{
Tile* tile = new Tile(driver, smgr, x, y);
}
}

//#######################

int lastFPS = -1;
u32 then = device->getTimer()->getTime();
float movementSpeed = [color=#800080]70.0f;

while(device->run())
{
const u32 now = device->getTimer()->getTime();
const f32 frameDeltaTime = (f32)(now - then) / 1000.f;
then = now;


if(m_Camera->getPosition().X > 190)
movementSpeed = -movementSpeed;
if(m_Camera->getPosition().X < -190)
movementSpeed = -movementSpeed;

m_Camera->setPosition(irr::core::vector3df(m_Camera->getPosition().X+movementSpeed* frameDeltaTime, [color=#800080]0.0f, -[color=#800080]500.0f));
m_Camera->setTarget(irr::core::vector3df(m_Camera->getPosition().X+movementSpeed*frameDeltaTime, [color=#800080]0.0f, [color=#800080]0.0f));

driver->beginScene(true, true, video::SColor(205,205,205,205));

smgr->drawAll();

driver->endScene();

int fps = driver->getFPS();

if (lastFPS != fps)
{
core::stringw tmp(L"tile test fps: ");
tmp += fps;

device->setWindowCaption(tmp.c_str());
lastFPS = fps;
}
}
device->drop();

return 0;
}



I really hope someone could help me with this problem, I'm trying for weeks already.
Thanks a lot!

Share this post


Link to post
Share on other sites
Advertisement
Rounding errors perhaps, since the camera uses floats for position? Try rounding the position or simply take the integer, without the decimal, part of it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!