🔒 Locked
Heightmaps...
Advertisement
Original Post
Im getting ready to start working with heightmaps, and I wanted to ask a couple questions. joanusdmentia explained in another post that 2 dimensional arrays are used to create a plane, with the actual value representing the height at each point. With this in mind, how would you sort through the 2D array to break the points up into triangles? I have seen higher detail heightmaps break arrays up into more complex patterns of triangles, but Im just looking to find how to break up a simple array.
Hope this is what your looking for
consider your array 4x2 in this case but u can apply to any other sizes (should be even)
You have the points as follows and from the points 0,1,4,5 you can construct 2 triangles (forming a quad). The math behind this is pretty easy.
That will generate the first triangles y coordinates for you (assuming your array stores the y coords for the map) to get the x and z simply use the offset_x and offset_y's and to generate the rest of the triangles just move the offsets along. I suggest you generate 2 triangles at a time (forming a quad) then you can simply write one nested loop to generate all the data for you.
Hope that helped, hope I didn't make a mistake :) (used to working in 1d arrays :)
consider your array 4x2 in this case but u can apply to any other sizes (should be even)
You have the points as follows and from the points 0,1,4,5 you can construct 2 triangles (forming a quad). The math behind this is pretty easy.
[0]-[1] [2] [3] | \ |[4]-[5] [6] [7]Triangle1_point0.y = array[offset_x + 0][offset_y + 0] ->index[0]Triangle1_point1.y = array[offset_x + 0][offset_y + 1] ->index[4]Triangle1_point2.y = array[offset_x + 1][offset_y + 1] ->index[5].. triangle 2 hereThat will generate the first triangles y coordinates for you (assuming your array stores the y coords for the map) to get the x and z simply use the offset_x and offset_y's and to generate the rest of the triangles just move the offsets along. I suggest you generate 2 triangles at a time (forming a quad) then you can simply write one nested loop to generate all the data for you.
Hope that helped, hope I didn't make a mistake :) (used to working in 1d arrays :)
You also have to think about the ordering of the vertices in a triangle.
if you plan to uee direct3d, the vertices should be ordered clockwise, if you plan to use opengl, the vertices should be ordered anti-clockwise.
if you plan to uee direct3d, the vertices should be ordered clockwise, if you plan to use opengl, the vertices should be ordered anti-clockwise.
you can easily change the front face of the triangles in OpenGL by using the
function call.
glFrontFace(GL_CW); //or GL_CCWfunction call.
Quote:
Original post by GameOxygen
You also have to think about the ordering of the vertices in a triangle.
if you plan to uee direct3d, the vertices should be ordered clockwise, if you plan to use opengl, the vertices should be ordered anti-clockwise.
Ok, I was thinking if he wanted to use triangle strips to render the terrain. The ordering of the vertices should be a little different when comparing opengl to direct3d?
Quote:
Original post by ngill
you can easily change the front face of the triangles in OpenGL by using the glFrontFace() function.
But if you use this and then come to need consistent face winding then you have some rework to do, so generally be consistent with your winding and don't use this function.
Quote:
Original post by Aph3x Quote:
Original post by ngill
you can easily change the front face of the triangles in OpenGL by using the glFrontFace() function.
But if you use this and then come to need consistent face winding then you have some rework to do, so generally be consistent with your winding and don't use this function.
Yes, you should be consistent, but this function allows you to be consistent in both ways.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement