terrain chunking

Posted By: sheefo

terrain chunking - 07/20/08 12:28

Whats the deal with terrain chunk? I have a terrain 256x256 vertices and terrain_chunk set to 32. 256/32 = 8. So I should have 8 chucks with exactly 32x32 vertices.

I end up with 33x33 vertices on all chunks except the last ones in each row, which are 32x32. So the total of vertices is 259x259 instead of 256x256. There is one extra vertex on most chunks... why!?

The math is all wrong when I try to access each vertex on each mesh and write data to a buffer. Is this some sort of technique or is it a bug?
Posted By: sheefo

Re: terrain chunking - 07/22/08 13:50

HELLO... Hello... hello...
Posted By: lostclimate

Re: terrain chunking - 07/22/08 14:57

the only thing i can think of is the fact that when two are next two eachother, the middle vertices are overlapping causing one extra
Posted By: EpsiloN

Re: terrain chunking - 07/22/08 15:55

If your terrain is with even number of verts , it'll have to split it in half. This would mean for example (in a row) 32 / 2 = 16.
Between the 16 and the 17 vert there is a face...Where would this face go smile ?
If your terrain is with odd number of verts , it'll split in half at that 17 vert...33 / 2 = 16 from both sides and the 17 at the middle.
I'm not shure about this smile but this might be the reason why its adding a vert...to save the middle faces.
Posted By: sheefo

Re: terrain chunking - 07/22/08 16:51

Thanks guys. I fixed it when I made my terrain size 257x257. I accessed each vertex like as if it were 2D grid (which it is) so the extra vertices are not read.

Each chunk is 33x33 vertices now, so the math works out.

What I was doing was a little something like this:
Code:
DWORD dwTotalVertices, dwVertices;
D3DVERTEX* pVertices;
...
dwTotalVertices = pMesh->GetNumVertices();
dwVertices = (DWORD)ceil(sqrt((double)dwTotalVertices));
...
pMesh->LockVertexBuffer(0, (LPVOID*)&pVertices);
for (unsigned y = 0; y < 32; ++y) {
	for (unsigned x = 0; x < 32; ++x) {
		float h = pVertices[x+y*dwVertices].y;
	}
}
pMesh->UnlockVertexBuffer();

© 2024 lite-C Forums