# Random terrain generation woes

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

## Recommended Posts

Hi! I'm having problems generating a random terrain for my isometric engine. Actually it's working quite fine, but there's one edge on my terrain (the lower right one) that's freakting out. Here's a screenshot: And this is how I create my terrain:
for(int nIndexY=0; nIndexY<128; nIndexY++)
{
texY=(float)(((float)nIndexY)/(float)128);
for(int nIndexX=0; nIndexX<128; nIndexX++)
{
// Vertice config
//  1_____2
// 4|\    |
//  |  \  |
//  |____\|3
//  6     5
//

int x=nIndexX-128;
texX=(float)(((float)nIndexX)/(float)128);

// Vertice 1
vTerrain[((nIndexY) * 128)+(nIndexX)].x=(float)x;
//			vTerrain[((nIndexY) * 128)+(nIndexX)].y=(float)nHeightArray[nIndexY][nIndexX];
vTerrain[((nIndexY) * 128)+(nIndexX)].y=(float)((rand() % (1*1000))/2000.0f);
vTerrain[((nIndexY) * 128)+(nIndexX)].z=(float)z;

vTerrain[((nIndexY) * 128)+(nIndexX)].tu1=texX;
vTerrain[((nIndexY) * 128)+(nIndexX)].tv1=texY;

//			int col=nHeightArray[nIndexY][nIndexX]*5;
int col=128;
vTerrain[((nIndexY) * 128)+(nIndexX)].dwColour=D3DCOLOR_ARGB(255, col, col, col);
}
z-=1;
}

// Now that we have our vertices, we create an index buffer array for them

for(int nIndexY=0; nIndexY<128; nIndexY++)
{
for(int nIndexX=0; nIndexX<127; nIndexX++)
{
//int nIndexY=0;
sIndices[nArrayIndex]=((nIndexY+1) * 128)+nIndexX;
sIndices[nArrayIndex+1]=(nIndexY * 128)+nIndexX;
sIndices[nArrayIndex+2]=((nIndexY+1) * 128)+nIndexX+1;

sIndices[nArrayIndex+3]=((nIndexY+1) * 128)+nIndexX+1;
sIndices[nArrayIndex+4]=(nIndexY * 128)+nIndexX;
sIndices[nArrayIndex+5]=(nIndexY * 128)+nIndexX+1;

nArrayIndex+=6;
}
}

It's a slightly modified code from a terrain tutorial. The terrain looks as expected, except from the one edge on the screenshot. what's going wrong? thanks in advance!

##### Share on other sites
In the second loop, you may want to use

for(int nIndexY=0; nIndexY<127; nIndexY++)

Since you are referering to nIndexY+1 in the loop.

HTH

##### Share on other sites
Works like a charm, thanks a lot!

regards

##### Share on other sites
I had the exact problem when I did my terrain generation as well! :)

1. 1
Rutin
25
2. 2
3. 3
4. 4
5. 5

• 9
• 10
• 13
• 19
• 14
• ### Forum Statistics

• Total Topics
632945
• Total Posts
3009359
• ### Who's Online (See full list)

There are no registered users currently online

×