First of read it into a double or single array, in the latter on you have to remember the width on your own.
Then traverse through it one and set a width of lets say 4.0f. Then use that for all changes in the X, and Z coordinat and use the Y coodinat from the BMP file as the vertices coordinates. Do this back and forth, not starting from the same end everytime. That can cause you problems when you are starting to texture the terrain.
When it comes to texturing you have several options. You can stretch one tecture all over the whole thing. Or you can use one texture for every quad (two triangles) or you can use more then one texture, and blend them togheter, giving each area on the terrain a difrent texture, so you can see gravel, grass, snow, and so on.
Did that answer your vague question? If not, aske again.
I know you explained to me before this whole left right, right left...
I think that just confuse's people as it is not necessary.
On a 128x128 bitmap.
I gather vertices for each point going from left to right, down 1 row, left to right, and so on.
Then I create the indices going from left to right as well, I will show you the snippet and you will notice that textures coords are being calculated correctly.
As you can see it is currently used for a QuadTree but the function was originally used for loading the entire heightmap. Flawlessly.
PHP Code:
//--------------------------
//Fill Vertices of a certain node -- used for leaves
//Can be easily modified to work as one function for a whole heightmap
//--------------------------
void QuadTree::FillVertices(int iNodeId, Vector2D *BoundingCoords)
{
Vector2D vSize = BoundingCoords[3] - BoundingCoords[0];
Halsafar said that using a mesh would be slow because of frustrum culling. Is there a class specifically for showing a terrain?
I don't know how to organise the height values in a way that they can be drawn. i have tried using indexed Trianglelists but I can't get it working (haven't got any code at the moment).
What class is traditionally used to contain a terrain??? I'm sure i'm going about this all wrong.
And if you are not going back and forth as I said, then you have to end every horizontal line of the terrain, before you draw a new one, to not cause artifacts. If you do end it every time, then it will be slower then not ending it for every horizontal line.
Ah, see this is where we are mis communicating.
I use Indexed TriangleLists, not Strips.
As for what class to use: Load a Bmp, Fill a 1D array full the pixel value (GetPixel) (tranverse through the 1D array as shown in my above func, since the 1D array represents a 2D bitmap), Now write a function like the one I posted to read in the vertice, each pixel requires a vertice (top-left corner) all the way from the beginning to the end of each row then column.
The write a function to generate the indices -- now a note to remember -- a 128x128 bmp it is a good idea to make it 129x129 bitmap or (a root of 2, plus 1).
Calculating tileU and tileV coords can be a rather complex process, and complications arise if you want to add cliff textures or different textures but NoteMe covered the idea on that above.
Rendering is easy, render a TRIANGLELIST, or a LINELIST to see the terrain is beautiful wireframe. Use a plain indentity matrix with no rotations.
My function above generates the triangles in Counter-Clockwise order so that works for D3D, but in OpenGL you will need to use CW.
This method is beautiful as writing a function to aid frustum culling is a simple task -- the Quad Tree -- which is what you'll want to touch on once you get your entire heightmap rendered.
Even if you are uses indexes I can't see how you manage to not get the artifacts if you are not:
Going back and fort when you are making the vertex buffer
Or going back and fort when you use the index buffer
Or stop at each end.
Becasuse if you don't you will use the last vertices on the end of one horizontal line on the start of the next one, dragging a triangel all the way back to the start or the next line.
BTW Wooossy, while looking for someting else (don't ask why I just woke up at this time of the night starting too look for soemthing), I triped over a new DX page I have never seen before. Covering your exact topic (guess it isn't in your prefered lanugage though, but they have a PDF too (even if I didn't look at it))
Yes NoteMe, if you are using QUADS then that would be case. If you using a TRIANGLELIST then I em just specifing the triangles and I know it is being specifed properly, every 3 indices is a triangle. the function goes row by row.
Impliment the fnction I posted.
Last edited by Halsafar; Feb 19th, 2005 at 07:28 PM.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama