Jump to content
  • Advertisement
Sign in to follow this  
vpk

terrain

This topic is 3643 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 am trying to build a terrain using a raw file. i have created the height map and the mesh. but i want to render only those triangles which are in the view currently. i dont want to render all the triangles at one go. how do i go about it?

Share this post


Link to post
Share on other sites
Advertisement
Check every triangle one by one if it is inside the view is not efficient.
You should partition your triangles into groups,like patches.
For example if you terrain has 256x256 vertices you can make 32x32 patches that would make 8x8=64 patches.Then you can check if a patch is inside the view and draw it or not.You should calculate the bounding box or sphere of each patch from the vertices in it,also you might want to look into quadtrees.

Share this post


Link to post
Share on other sites
Instead of making one large mesh for the entire height-map, make several smaler meshes.
E.g. if the heightmap is originally 1024x1024, then you could make (a 16*16 grid of small) 65*65 meshes.

You could then organise these smaller meshes into a quad-tree (etc) for easier culling.

[EDIT] Black Knight beat me to it ;)
N.B. If you split the main mesh into sub-meshes, these sub-meshes require the edge vertices to be duplicated. (remember the +1!)
E.g. Width = 1024
NumSubMeshes = 16
SubMeshWidth = 1024/16 + 1

Share this post


Link to post
Share on other sites
thanks for the reply

following is the code which creates the mesh:

void DisplayHeightMap (void) {
int Height;
int numtri=0;

for (mapX = 1; mapX < MapWidth; mapX +=4){
for (mapZ = 1; mapZ < MapHeight*4; mapZ+=4){
numtri++;
glBegin(GL_TRIANGLE_STRIP);

Height = HeightMap[mapX][mapZ];
glTexCoord2f(0,0);
glVertex3f(float(mapX),Height,float(mapZ));

Height = HeightMap[mapX][mapZ+4];
glTexCoord2f(0,1);
glVertex3f(float(mapX),Height,float(mapZ+4));

Height = HeightMap[mapX+4][mapZ];
glTexCoord2f(1,0);
glVertex3f(float(mapX+4),Height,float(mapZ));

Height = HeightMap[mapX+4][mapZ+4];
glTexCoord2f(1,1);
glVertex3f(float(mapX+4),Height,float(mapZ+4));
glEnd();
}
}
}
not able to make out if it is creating a single mesh??

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!