# terrain

This topic is 3817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
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 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 on other sites

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??

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633704
• Total Posts
3013458
×