Sign in to follow this  
MrPickle

Trouble rendering a basic map from Multidimensional array [Solved]

Recommended Posts

Basically, I have a multi-dimensional array which loads data from a file. The file may look something like: 4 4 1 2 2 1 2 3 3 2 2 3 3 2 1 2 2 1 The first two are the width & length then the rest are the height, the higher the number the higher it goes. I've got all the data to the array fine but I'm having trouble turning it into a rendered map. I can different layers but I can't get the layers to slope from one to another. Here's what I have so far:
void Terrain::Draw(void){
	int Square = 0, DeltaSquare = 0, Translate;
	for(int i = 0; i < Width; i++){
		for(int j = 0; j < Length; j++){
			DeltaSquare = Square;
			Square = Heights[j][i];
			
			glBegin(GL_QUADS);
			glVertex3f(j, Square-1, i);
			glVertex3f(j, Square-1, -i);
			glVertex3f(-j, Square-1, -i);
			glVertex3f(-j, Square-1, i);
			glEnd();
		}
	}
}


[Edited by - MrPickle on May 11, 2008 4:48:14 AM]

Share this post


Link to post
Share on other sites
Are you trying to render terrain? If so that code will basically just render quads and look like a staircase...

You need to make sure all 4 vertices per quad grab the heights correctly.


void Terrain::Draw(void){
int vertex0 = 0, vertex1 = 0, vertex2 = 0, vertex3 = 0, DeltaSquare = 0, Translate;
for(int i = 0; i < Width-1; i++){
for(int j = 0; j < Length-1; j++){
vertex0 = Heights[i][j];
vertex1 = Heights[i][j+1];
vertex2 = Heights[i+1][j+1];
vertex3 = Heights[i+1][j];

glBegin(GL_QUADS);
glVertex3f(j, vertex0, i);
glVertex3f(j, vertex1, i+1);
glVertex3f(j+1, vertex2, i+1);
glVertex3f(j+1, vertex3, i);
glEnd();
}
}
}



Or something like that. It's been awhile since I have done immediate mode terrain rendering... :)

Share this post


Link to post
Share on other sites
Yey, thank you!

I had to change this:
	glBegin(GL_QUADS);
glVertex3f(j, vertex0, i);
glVertex3f(j, vertex1, i+1);
glVertex3f(j+1, vertex2, i+1);
glVertex3f(j+1, vertex3, i);
glEnd();


to this though:
	glVertex3f(j, vertex0, i);
glVertex3f(j+1, vertex1, i);
glVertex3f(j+1, vertex2, i+1);
glVertex3f(j, vertex3, i+1);

otherwise the squares where at funny angles.

Share this post


Link to post
Share on other sites

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