Skip to main content
gamedev.net
🔒 Locked

Heightmaps...

Started by Noods 7 replies 1.2k views
Original Post
Noods
Noods
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.
nts
nts
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.

[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 here


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 :)
no one
no one
go Here

There are 4 tutorials going from very basic to detail texturing and fogging.

Good luck and have fun.
~Jason
"Make it a habit to be loyal to the activities that serve the highest part of yourself."
GameOxygen
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.
ngill
ngill
you can easily change the front face of the triangles in OpenGL by using the

glFrontFace(GL_CW); //or GL_CCW


function 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.
GameOxygen
GameOxygen
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?
Roquqkie
Roquqkie
Quote:
Original post by GameOxygen
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?


No...
MGB
MGB
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.
python_regious
python_regious
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.
If at first you don't succeed, redefine success.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.