Jump to content
  • Advertisement
Sign in to follow this  
FoxHunter2

Random terrain generation woes

This topic is 5081 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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!