Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

guts

Terrain

This topic is 5546 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! at first: sorry for my bad english *g* i tried to do a brute force terrain with vertex arrays(opengl), but it doesn''t work as i should. there are strange lines from on end of the terrain to the other. i guess i do something wrong with my indices.
	for (int y=0; y < nSize; y++) 
	{   
		for (int x=0; x < nSize; x++) 
		{    
			CurrVertex = y * (nSize/1) + x;      
			
			vert.x = (float)x;   		  
			vert.y = (float)(mHeightMap->mData[CurrVertex * 3]/mDivider);    
			vert.z = (float)y ;  
 
			uvcoord.t[0] = ((float)y /nSize), 
			uvcoord.t[1] = ((float)x /nSize);  
			
			vertices[CurrVertex] = vert;   
			texcoords[CurrVertex] = uvcoord;   

			++VerSize;
		}  
	}   

	int idx=0;
	for (y = 0; y < nSize - 1; y++) 
	{   
		for (int x=0; x < nSize - 1; x++) 
		{
			CurrVertex = y * (nSize) + x;  
			indices[idx] = CurrVertex;
			indices[++idx] = CurrVertex + nSize;
			indices[++idx] = CurrVertex + 1;   
			indices[++idx] = CurrVertex + (nSize) +1;
			indices[++idx] = CurrVertex;   
			indices[++idx] = CurrVertex + 1;
			++idx;
			IndSize+=6;				
		}  
	}
[/CODE]

what''s wrong?    

Share this post


Link to post
Share on other sites
Advertisement
I can''t see the vertex array setup, could you please post it?
I noticed that the order you store the triangles in are a little fishy, check it out.

Share this post


Link to post
Share on other sites
here's the rendering code:

glLoadIdentity();
glPopMatrix();
glPushMatrix();
glTranslatef(mPos.x, mPos.y,mPos.z);
glScalef(mScale.x, mScale.y, mScale.z);
glVertexPointer(3, GL_FLOAT, sizeof(CVector3), &vertices[0].x);
glEnableClientState(GL_VERTEX_ARRAY);

glDrawElements(GL_TRIANGLE_STRIP, IndSize, GL_UNSIGNED_INT, &indices[0]);
glDisableClientState(GL_VERTEX_ARRAY);
[/CODE]
(Without the Texture Stuff, because this would be to much to post ... mulittexturing, multipass. support, it's not important anyway)


>>I noticed that the order you store the triangles in are a little fishy, check it out
That's my problem, i don't know how to do it the right way.

@Trienco
I render as triangle strip


[edited by - guts on April 19, 2003 7:24:00 AM]


[edited by - guts on April 19, 2003 7:24:25 AM]

Share this post


Link to post
Share on other sites
without looking at the vertices and indices in detail it seems youre always going left to right with your indices, never begin a new strip and shouldnt be surprised if strange lines appear between the last vertex of a line and the first of the next line. you have to do one line from left to right and the next from right to left, most likely add a dummy-triangle, because strips have a few things to consider.

first: every new point will form a triangle with the last two points.
second: the winding changes with each point (clockwise, counter clockwise)..

and of course third: cache optimized triangles lists cause less headache and are usually as fast or faster.

Share this post


Link to post
Share on other sites
i know it's kind of impertinent, but could you please post the source code that stores the indices in the right way?!

[edited by - guts on April 19, 2003 10:09:17 AM]

Share this post


Link to post
Share on other sites
might not help you much, because i just ripped it out and im going bottom to top, not left to right...

int X=0;
while (X < size) {
for (Y=size; Y >= 0; --Y) {
IdxBuffer[i++]=(X*size)+Y;
IdxBuffer[i++]=((X+1)*size)+Y;
}
IdxBuffer[i++]=(++X)*size;
if (X>=size) break;
for (Y=0; Y<=size; ++Y) {
IdxBuffer[i++]=(X*size)+Y;
IdxBuffer[i++]=((X+1)*size)+Y;
}
IdxBuffer[i++]=((++X)*size)+size;
}

hope i replaced all strt with 0 and end/n with size

[edited by - Trienco on April 19, 2003 11:22:17 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!