Jump to content
  • Advertisement
Sign in to follow this  
moetman

Heightmap Confirmation

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

I've managed to get the texture on the mesh correctly, however I'm not sure about my normal calculations.. In fact I'm not sure about any of it. I'm trying to build Tri Strips and I really need help on calculating the Normals.I need to calculate the face normals first, which can be done using cross product right ? For example (from the code beneath) va.X = u.X - v.X; va.Y = u.Y - v.Y ; va.Z = u.Z - v.Z ; vb.X = u.X - v.X; vb.Y = u.Y - v.Y ; vb.Z = u.Z - v.Z ; face = crossproduct(va,vb); face = Normalize(facet); Once done, each of the vertex normals is the average of the 6 surrounding faces: glNormal3f(face.X/6,face.Y/6,face.Z/6); ???? for each call to glNormal() ? Do I need to take into account boundary values like edges or borders ? Is this correct ? Kind Regards to you all /////////////////////////////////////////////////////////////////////Ter Gen for (int x = 0; x < MAP_SIZE - 1; x++) { // Draw A Triangle Strip For Each Column Of Our Mesh glBegin(MODE); for (int y = 0; y < MAP_SIZE - 1; y++) { glBindTexture(GL_TEXTURE_2D, texture[0]); float_x = (float) x /MAP_SIZE-1; float_y = (float) y /MAP_SIZE-1; float_xb = (float) (x + 1) / MAP_SIZE-1; float_yb = (float) (y + 1) / MAP_SIZE-1; u.X = mesh[x][y][0];//vertex 1 u.Y = mesh[x][y][1]; u.Z = mesh[x][y][2]; v.X = mesh[x+1][y][0];//vertex 2 v.Y = mesh[x+1][y][1]; v.Z = mesh[x+1][y][2]; u.X = mesh[x][y+1][0];//vertex 3 u.Y = mesh[x][y+1][1]; u.Z = mesh[x][y+1][2]; v.X = mesh[x+1][y+1][0];//vertex 4 v.Y = mesh[x+1][y+1][1]; v.Z = mesh[x+1][y+1][2]; n = crossproduct(u,v); n = Normalize(n); glTexCoord2f(float_x, float_y); glNormal3f(n.X,n.Y,n.Z); glVertex3f(mesh[x][y][0], mesh[x][y][1], mesh[x][y][2]); glTexCoord2f(float_xb, float_y); glVertex3f(mesh[x+1][y][0], mesh[x+1][y][1], mesh[x+1][y][2]); glTexCoord2f(float_xb, float_yb); } glEnd(); }

Share this post


Link to post
Share on other sites
Advertisement
Strictly speaking, averaging face normals is not correct because the resulting vector does not have a length of 1. However, it is fast and the results may be good enough. Because a vertex normal is only an approximation, there are several ways to compute it. This article does a good job of explaining and comparing the different methods: Normal Computations for Heightfield Lighting.

There are different ways of handling edges. It may depend on what is beyond the edge.

Finally... for now, while you are drawing brute force using immediate mode, stick with triangle strips. However, once you move to vertex arrays, you should use a single triangle list instead of a bunch of triangle strips until you get everything working well. Triangle lists are easier to deal with and you will find that drawing one big triangle list is faster than drawing MAP_SIZE triangle strips. There is a way to draw a grid using a single triangle strip, but it is complicated so I would hold off on that optimization until you get things working.

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!