making terrain's connect together

Started by
12 comments, last by fireking 20 years, 5 months ago
i just got an idea, would there be a simple algorithm i could write that would modify the height values after loading them into the application, this way i could just find the average between each landscape''s neighbor, and they would connect together?

this seems like a more plausible solution to what im trying to accomplish, but i dont know where to start on writing that algorithm
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios
Advertisement
well i started on the algorithm, but it doesnt set the height on the right part of the terrain, im not sure how to set a specific part of a 1d array...

void AverageNeighbor(BYTE *pHeightMap,BYTE *pHeightMap2,int type)//0=h1 is south of h2;1=h1 is east of h2;{	int ix,iz,hm1hv,hm2hv,fv;;	switch(type)	{	case 0:		for(ix=0;ix < MAP_SIZE-1;ix++)		{			hm1hv=Height(pHeightMap,ix,0);			hm2hv=Height(pHeightMap2,ix,MAP_SIZE-1);			fv=(hm1hv+hm2hv)/2;			//pHeightMap[ix]=fv;			//pHeightMap2[ix*(MAP_SIZE-1)]=fv;			pHeightMap[ix]=0;			pHeightMap2[ix*(MAP_SIZE-1)]=0;		}		break;	case 1:		for(iz=0;iz < MAP_SIZE-1;iz++)		{			hm1hv=Height(pHeightMap,0,iz);			hm2hv=Height(pHeightMap2,MAP_SIZE-1,iz);			fv=(hm1hv+hm2hv)/2;			//pHeightMap[iz]=fv;			//pHeightMap2[iz*(MAP_SIZE-1)]=fv;			pHeightMap[iz]=0;			pHeightMap2[iz*(MAP_SIZE-1)]=0;		}		break;	}} 


this baby will work as soon as someone can help me figure out how to set a value at a specific location in the array only by knowing x and z

[edited by - fireking on October 20, 2003 12:58:47 AM]
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios
Ok, let's say you have a 3x3 heightmap stored in a 1D array, it gets stored something like this:
0 1 2
3 4 5
6 7 8

Basically, (0, 0) is heightmap[0], (1, 0) is heightmap[1], (2, 2) is heightmap[8], etc.

Ok, here's the idea:
(z*width)+x

where width is the width of the terrain (3 in the example). So to get (1, 2), it is (2*3)+1 = 7. That's good, because (1, 2) = 7 in my example array at the top, too. Hope that helps.


Ok, I realized that this method works great for how I load in and store my heightmap data, but it may not be how you store your data. Hopefully, this at least gives you an idea how to approach it.

[edited by - Mr Grinch on October 21, 2003 1:29:11 AM]
WOO HOO!!!

I DID IT!!!!!!!!!!!!!!!!!!!!!!

I CONNECTED 3 TERRAINS TOGETHER SEEMLESSLY!!!!!!!! I AM THE MAN!!!!!

oh.... well i couldnt have done it without you guys, of course ...


thanks!

source code!!

//rendering the terrain, using step size for triangle resolution	int ix;	int iz;	for(iz=0;iz < MAP_SIZE-STEP_SIZE;iz+= STEP_SIZE)	{		glBegin(GL_TRIANGLE_STRIP);		for(ix=0;ix < MAP_SIZE;ix+= STEP_SIZE)		{			SetTextureCoord((float)ix,(float)iz);			glNormal3f((float)ix,(float)Height(pHeightMap,ix,iz),iz);			//glNormal3f(0.0f,1.0f,0.0f);			glVertex3f(ix,Height(pHeightMap,ix,iz),iz);			SetTextureCoord((float)ix,(float)iz+STEP_SIZE);			glNormal3f((float)ix,(float)Height(pHeightMap,ix,iz+STEP_SIZE),iz+STEP_SIZE);			//glNormal3f(0.0f,1.0f,0.0f);			glVertex3f(ix,Height(pHeightMap,ix,iz+STEP_SIZE),iz+STEP_SIZE);		}		glEnd();	}//averaging points between neighborsint GetPos(int x,int z){    return (z*MAP_SIZE)+x;}void AverageNeighbor(BYTE *pHeightMap,BYTE *pHeightMap2,int type)//0=h1 is south of h2;1=h1 is east of h2;{	int ix,iz,hm1hv,hm2hv,fv;;	switch(type)	{	case 0:		for(ix=0;ix < MAP_SIZE;ix+=STEP_SIZE)		{			hm1hv=Height(pHeightMap,ix,0);			hm2hv=Height(pHeightMap2,ix,MAP_SIZE-STEP_SIZE);			fv=(hm1hv+hm2hv)/2;			pHeightMap[GetPos(ix,0)]=fv;			pHeightMap2[GetPos(ix,MAP_SIZE-STEP_SIZE)]=fv;		}		break;	case 1:		for(iz=0;iz < MAP_SIZE-1;iz+=STEP_SIZE)		{			hm1hv=Height(pHeightMap,0,iz);			hm2hv=Height(pHeightMap2,MAP_SIZE-STEP_SIZE,iz);			fv=(hm1hv+hm2hv)/2;			pHeightMap[GetPos(0,iz)]=fv;			pHeightMap2[GetPos(MAP_SIZE-STEP_SIZE,iz)]=fv;		}		break;	}}//retreiving the height point at a specified locaiton (x,z)int Height(BYTE *pHeightMap,int X,int Y){		// Make sure we don't go past our array size	if(X < 0 || X > MAP_SIZE-1) return 0;	if(Y < 0 || Y > MAP_SIZE-1) return 0;	//int x = X % MAP_SIZE;					// Error check our x value	//int y = Y % MAP_SIZE;					// Error check our y value	if(!pHeightMap) return 0;				// Make sure our data is valid	// Use the equation: index = (x + (y * arrayWidth) ) to find the current height	return pHeightMap[X+(Y*MAP_SIZE)];	// Index into our height array and return the height}//frame routine	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glLoadIdentity();						//camera routine	glScalef(10,10,10);	RenderHeightMap(g_HeightMap,0);	glTranslatef(1024.0f-STEP_SIZE,0.0f,0.0f);	RenderHeightMap(g_HeightMap2,2);	glTranslatef(-1024.0f+STEP_SIZE,0.0f,1024.0f-STEP_SIZE);	RenderHeightMap(g_HeightMap3,3);	glScalef(-10,-10,-10);	SwapBuffers(g_hDC);  


i hope this helps somebody that's in my place in the future, this was stressful (might miss some work over this, from staying up too late) and very fun at the same time. Terrains = fun..

have a good day, and thanks to all that helped!

last but not least, a little screen shot

Classic Before and After:



the only break you see is the differences in colors between the two textures, cuz im no texture artist, i can assure you that the edges are definately connected together

[edited by - fireking on October 21, 2003 1:59:25 PM]
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios

This topic is closed to new replies.

Advertisement