Sign in to follow this  

Random terrain generation woes

This topic is 4869 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

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 this post


Link to post
Share on other sites

This topic is 4869 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this