Jump to content
  • Advertisement
Sign in to follow this  
ManTis

OpenGL Terrain with cliffs

This topic is 4706 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

Since I am connecting to the net not on the computer i have the code on, I will include only pseudocode from memory, not actual code. I started working on 3d terrain representation, and encountered couple things I can't think how to work around. I decided to use heightmap terrain (pretty obvious and easy choice for outdoors game). Read couple articles and started working on it. Found out that terrain is basically set of triangles with vertices heights based on heightmap. I wanted the texture to be dependant on steepness of terrain (most of the terrain should be grassy, most steep cliffs - rocky). I'm not very good with OpenGL (actually just started working in it, read 'Beginning OpenGL programming' and am currently reading 'more opengl game programming'), so my implementation needs some performance improvement help. I'm not sure how to access (if there is way) normals for each triangle, so I count it myself. Anyway, here's a pseudocode:

// vertex is struct with x y and z float fields
// loading map
int texType[ALLVERTICES*2]; // texture type in every triangle
vertex normal; //temporary vertex for triangle normals
float angle;

for (int verticenumber = 0 ; verticenumber < ALLVERTICES; verticenumber++)
{
// since every vertex(except last row) can be used as a base for two triangles, every loop determines texture for two triangles
normal = detTriNormal(verticenumber, 1); // determines first triangle normal based on vector cross product of vectors that make the triangle
angle = DetYAngle(normal); //determines the angle between vector and Y axis
if (angle < 75)
{
texType[verticenumber*2]=TEX_GRASS;
}
else
{
texType[verticenumber*2]=TEX_ROCK;
}

normal = detTriNormal(verticenumber, 2); // determines second triangle normal based on vector cross product of vectors that make the triangle
angle = DetYAngle(normal); //determines the angle between vector and Y axis
if (angle < 75)
{
texType[verticenumber*2+1]=TEX_GRASS;
}
else
{
texType[verticenumber*2+1]=TEX_ROCK;
}
}

// ok, the texture types are defined, so now i can actualy render the map
void RenderFunction()
{
for (int verticenumber = 0; verticenumber < ALLVERTICES; verticenumber++)
{
int type;
type = DetTriTexture(verticenumber, 1); // determines the texture of first triangle
DrawTriangle(verticenumber, 1, type); // draws triangle with given texture

type = DetTriTexture(verticenumber, 2); // determines the texture of second triangle
DrawTriangle(verticenumber, 2, type); // draws triangle with given texture
}
}

So, here it is. Totally inefficient. If I would use triangle strips based on series of triangles with same texture in a row, concatenated with degenerated triangles, it would be little faster i think. Any other idea? Some LOD algorithm that won't make the terrain change texture as the triangles change steepness? thanks in advance for all suggestions. if I made something unclear in code, please point it out and i will immediatly try to fix it. [Edited by - EliteWarriorManTis on July 24, 2006 6:23:23 AM]

Share this post


Link to post
Share on other sites
Advertisement
FYI you lost your code formatting in the post (which means in general that people will be unlikely to read it); try the [ source ][ /source ] tags instead - you can edit your original post using the 'edit' button.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!