Problem with heightmap offsets

Started by
8 comments, last by Sheep 21 years, 10 months ago
Hello everbody. I am having some trouble with offsetting my heightmap: Lets say that I have 16 terrain chunks, each one 32x32 verts wide. Now, I am loading a 512x512 heightmap. So this is what it looks like (psuedo-code):
    
for(int z = 0; z <= NumQuadsHigh; z++)
{	  
  for(int x = 0; x <= NumQuadsWide; x++)
  {
    verts->p.y =  pHeightMap[x + (z * 512)];
    verts++;
  }
}     
Now everything is all nice and dandy, except for one thing: Each chunks heights are the same because pHeightMap is returning heights with the same x and y values. Does anybody have any ideas on how to bypass this? I have have tried almost everything, adding offsets, static variables and generally screwing around with different variables, but nothing seems to be working. Any help would be appreciated...I have been banging my head against the wall for almost 3 days now. Thanks. [edited by - Sheep on June 24, 2002 11:57:42 AM]
Advertisement
Anyone?
Assuming that you want the z axis as you width, the x axis as the length and the y axis as you height, wouldn't it look like this:
for(int z = 0; z < NumQuadsWidth; z++){	    for(int x = 0; x < NumQuadsLength; x++)  {    verts->p.y =  pHeightMap[x + (z * NumQuadsLength)];    verts->p.x = x;    verts->p.z = z;    verts++;  }}   

Or something like that?


[edited by - thoooms on June 24, 2002 1:31:21 AM]
Thomas - www.moelhave.dk
Yes, but that isnt the problem. I have already successfully set up the x and z values. And in this case, 512 is the same as NumQuadsLength. My problem is, that the same height values are being repeated over and over again for all the chunks because the x and z values are going to be the same. I am beginning to regret having posted on this forum, but I can''t really move it :\




Are you using this loop once for every chunk or is verts a buffer containing all the chunks?
verts is a pointer to an array of my "vertex" class. That loop is called once per chunk (each chunk has its own vertex buffer).
are you sure you have loaded the heightMap correctly. it seems like you are reading from the map correctly. my guess is that you have loaded it incorrectly. can you post your loadMap function?

also, if you are loading from a file have you checked that file to make sure that it''s not just the same data over and over again?

-me
Hmmm...perhaps I am not explaining myself correctly: I know that the data in the file is correct and is being loaded correctly. That I know is not my problem. My problem is this:
I have 16 cells, each one is 32x32 vertices wide:

[1,1] [2,1] [3,1] [4,1]

[1,2] [2,2] [3,2] [4,2]

[1,3] [2,3] [3,3] [4,3]

[1,4] [2,4] [3,4] [4,4]

Each one has its own vertex buffer, and the vertex buffer''s data is being held in "verts" (from my example).

Now, lets say that the first chunk ([1,1]) is going through that loop. All of its height values will be the correct height values, because it will be reading the first section of the heightmap. However, the second chunk ([2,1]) will have the same height values as the first, because it has its own vertex buffer and will be looping with the same x and z values...Get it? If not, I can try explaining it one more time.
You have just explained where the problem is (still don''t see it?)

Every chunk starts at x = 0, z = 0 (for the heightmap). Of course they will all get the same y-values then. You need to modify the index into the heightmap to account for the current chunk position, e.g.:

// starting pixel in heightmap for this chunk
int nIndex = nChunkPositionZ * 32 * 512 + nChunkPositionX * 32;

// now add current pixel position
nIndex += z * 512 + x;

// use this index instead
verts->p.y = pHeightMap[nIndex];
How would I integrate that into my loop? Thanks.

This topic is closed to new replies.

Advertisement