Gaps when using tiled terrain

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Gaps when using tiled terrain

Post by Virror »

I know this has been up here many times : p
I have read through some of the posts but not found a solution to my problems : / I get a gap that looks like its one face wide between all my tiles.

I use heightmaps with the size of 257x257.
Placing of tiles:

Code: Select all

for(i = 0; i < COLUMNS; i++)
		for(j = 0; j < ROWS; j++)
		{
			char name[20];
			sprintf(name, "heightmap%d.bmp", count);
			ITerrainSceneNode* terrain = irrScene->addTerrainSceneNode(
				name,
				0,								// parent node
				-1,								// node id
				vector3df((f32)(j*-12850), 0.f, (f32)(i*-12850)),// position 12800
				vector3df(0.f, 0.f, 0.f),		// rotation
				vector3df(50.f, 15.0f, 50.f),	// scale 50 10 50
				SColor ( 255, 255, 255, 255 ),	// vertexColor
				3,								// maxLOD
				ETPS_17,						// patchSize
				4								// smoothFactor
				);
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

With correct dimensions it shouldn't happen, though. Are you sure there's a face wide gap, not just a problem with different smoothing or LOD levels (which would usually come through as height differences, but not distance differences)
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Post by Virror »

Im not sure its a face-wide cap, but it looks like it. Don't think its a LOD problem, cause its the same no matter how i move around. The reason i think its a row of faces missing is cause its both a difference in gap an a slight different in height. And the height difference varies from face to face.
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Post by Virror »

Anyone?
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

Maybe enable the irr::video::EMF_WIREFRAME flag of the material and post some screenshots.

And a complete compilable example with media files would be nice.
"Whoops..."
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Post by Virror »

Code is coming, but first pictures:
Image
Image
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Post by Virror »

Code:

Code: Select all

int StartMap(IrrlichtDevice * irrDevice, int randomValue)
{
	char temp[15];
	IVideoDriver * irrVideo = irrDevice->getVideoDriver();
	ISceneManager* irrScene = irrDevice->getSceneManager();

	irrVideo->setTextureCreationFlag(ETCF_ALWAYS_32_BIT, true);

	SKeyMap keyMap[5];
	keyMap[0].Action = EKA_MOVE_FORWARD;
	keyMap[0].KeyCode = KEY_KEY_W;

	keyMap[1].Action = EKA_MOVE_BACKWARD;
	keyMap[1].KeyCode = KEY_KEY_S;

	keyMap[2].Action = EKA_STRAFE_LEFT;
	keyMap[2].KeyCode = KEY_KEY_A;

	keyMap[3].Action = EKA_STRAFE_RIGHT;
	keyMap[3].KeyCode = KEY_KEY_D;

	keyMap[4].Action = EKA_JUMP_UP;
	keyMap[4].KeyCode = KEY_SPACE;

	// Add camera
    camera = irrScene->addCameraSceneNodeFPS(0, 100.0f, 1.2f, -1, keyMap, 5, false, 0.5f);
	camera->setPosition(vector3df(-2700*2, 1750*2, -2600*2));
	camera->setTarget(vector3df(2397*2, 343*2, 2700*2));
	camera->setFarValue(42000.0f);

	// Add terrain scene node
	int count = 1, i, j;
	for(i = 0; i < COLUMNS; i++)
		for(j = 0; j < ROWS; j++)
		{
			char name[20];
			sprintf(name, "heightmap%d.bmp", count);
			ITerrainSceneNode* terrain = irrScene->addTerrainSceneNode(
				name,
				0,								// parent node
				-1,								// node id
				vector3df((f32)(j*-12850), 0.f, (f32)(i*-12850)),// position 12800
				vector3df(0.f, 0.f, 0.f),		// rotation
				vector3df(50.f, 15.0f, 50.f),	// scale 50 10 50
				SColor ( 255, 255, 255, 255 ),	// vertexColor
				3,								// maxLOD
				ETPS_17,						// patchSize
				4								// smoothFactor
				);

			terrain->setMaterialFlag(EMF_LIGHTING, false);
			terrain->scaleTexture(1.0f, 20.0f);
			terrain->setMaterialFlag(video::EMF_WIREFRAME,
                                                !terrain->getMaterial(0).Wireframe);
			count++;
		}
    return 0;
}



int main()
{
	srand ( (unsigned int)time(NULL) );

	// Init engine
	irrDevice = createDevice(EDT_DIRECT3D9 , dimension2d<u32>(1024, 768));

	IGUIEnvironment* irrGui = irrDevice->getGUIEnvironment();
	IVideoDriver * irrVideo = irrDevice->getVideoDriver();
	ISceneManager* irrScene = irrDevice->getSceneManager();
	StartMap(irrDevice, randomValue);
	
	while(irrDevice->run()) 
	{
		irrVideo->beginScene(true, true, SColor(0,150,150,150));
		irrScene->drawAll();
		irrGui->drawAll();
                
		irrVideo->endScene();
	}

	//Shut down
	irrDevice->drop();

    return 0;
}
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Post by Virror »

No one can help with this?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Argh, this cost me almost two hours of my life... Next time, post a working code example.
Still, the bug is on your side. You placed the terrain 257 units away from each other. Having a heightmap of 257x257 pixels produces 256x256 tiles only, though. Which makes a gap of exactly one patch on each side :roll:
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Post by Virror »

Ohh, i tested the code before posting ofcourse, it worked for me...
So, i should make a heightmap of 258x258 pixels? That was a stupid mistake : p
CarlS
Posts: 86
Joined: Wed May 09, 2007 1:21 am
Contact:

Post by CarlS »

Virror wrote:Ohh, i tested the code before posting ofcourse, it worked for me...
So, i should make a heightmap of 258x258 pixels? That was a stupid mistake : p
No, the 257x257 pxel heightmap was right size to use. The terrain it makes has 256x256 facets. You need to space the terrain tiles 256 facet lengths apart, not 257.

--Carl
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Post by Virror »

No, that wont work, as you can see on the screenshots the edges wont fit together, it looks like there is some faces missing... Maybe there is something wrong with the terrain generation then, but i dont think so..
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Post by REDDemon »

Are the pixel heights values equals between heightmaps edges?

So let take two adiacent tiles:

A and B

is the last column of A equals to the first column of B?
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

At least for fitting heightmaps, and careful use of smoothing and LOD, you can achieve a perfect fit. But it's indeed quite hard to align all vertices around the border, I guess we have to fix the rendering a little more.
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Post by Virror »

REDDemon wrote:Are the pixel heights values equals between heightmaps edges?

So let take two adiacent tiles:

A and B

is the last column of A equals to the first column of B?
That is a very good question actually : p
I use libnoise to generate my maps, so when i think about it i guess they are not.. Cause if the images align, the edges are not equal : ) Thanx for than one, will try to figure something out here.
Post Reply