Terrain-ish stuff
Let''s say I have a [10][10] array of heights. How can I make a square made up of 100 vertices which have these heights? For example, If all of the values in this array where 0 except [5][5] was 2 then I should have a flat square with a spike in the middle. If I knew this I could do water, terrain etc.
I''m sure some of you people who know opengl really well will say "Use triangle strips" or something but it would be nice if you could give me a example in code of how to make an array into a mesh square thing like this.
November 11, 2000 10:04 PM
Well... firstly perhaps you would like to consider a higher resolution of heights.
Secondly, if all of them were 0''s and the [5][5] was a 2... yes, it''d create a spike... but isn''t that exactly what you want?? If you wanted it more round and terrain-like then perhaps the 2 should be surrounded by 1.5''s, which are surrounded by 1.0''s, and then 0.5''s...?
Secondly, if all of them were 0''s and the [5][5] was a 2... yes, it''d create a spike... but isn''t that exactly what you want?? If you wanted it more round and terrain-like then perhaps the 2 should be surrounded by 1.5''s, which are surrounded by 1.0''s, and then 0.5''s...?
I'm not exactly sure what you're asking for, but I'll let you know how you can turn the matrix of heights into a matrix of vertices. I'm not presenting any cool multi-resolution methods, just a simple height-to-vertex method.
First, make a matrix of undefined vertex var's the same size as the height map.
Then, iterate through all the heights in the matrix.
For each element, evaluate the world-space height based on the multiplier and the base height. Also give each vertex its x and y values based on the element position in the matrix. Using i&j as heightfield pixel specifiers and y as up, here is some very simple code:
You can transform that data into strips, fans, whatever you want, but at least you'll be dealing in world space and not image space anymore.
Edited by - Assassin on November 11, 2000 11:31:24 PM
First, make a matrix of undefined vertex var's the same size as the height map.
Then, iterate through all the heights in the matrix.
For each element, evaluate the world-space height based on the multiplier and the base height. Also give each vertex its x and y values based on the element position in the matrix. Using i&j as heightfield pixel specifiers and y as up, here is some very simple code:
Vertices[j][k].Y = BaseHeight + (Element[j][k] * HeightMultiplier);Vertices[j][k].X = BaseX + (j * XMultiplier);Vertices[j][k].Z = BaseZ + (k * ZMultiplier);
You can transform that data into strips, fans, whatever you want, but at least you'll be dealing in world space and not image space anymore.
Edited by - Assassin on November 11, 2000 11:31:24 PM
Assassin, aka RedBeard. andyc.org
Anonymous Poster, yes if I wanted to make it smoother I would make it higher res and change the surrounding vertices etc. Assassin, how can I make that vertex array into "strips, fans, etc.", I''m not sure how they work...
Thanks!
-David
Thanks!
-David
Well, if you are about to create your own terrain routine you
should really know how they work. Shame on you
Well, it is really straight forward, but i will only describe it
very briefly here since the info can be found in the Blue and Red Book and some tutorials as well.
Triangle strips are made like this...
glBegin( GL_TRIANLGE_STRIPS );
glVertex3f( x, y, z );
glVertex3f( x, y, z );
glVertex3f( x, y, z );
etc...
glEnd();
You must draw them counter clockwize. The first three vertices
form the first triangle, then you will add one more for each
new one you want to create. They will sick sack their way to the
end . Hard to explain like this, but that is the basic. Look
for a tut or one of the obove books that is downloadable from the
net.
GLFans.... glBegin( GL_TRIANGLE_FAN );
Quads... glBegin( GL_QUADS );
Good Luck...
Allmight.
should really know how they work. Shame on you
Well, it is really straight forward, but i will only describe it
very briefly here since the info can be found in the Blue and Red Book and some tutorials as well.
Triangle strips are made like this...
glBegin( GL_TRIANLGE_STRIPS );
glVertex3f( x, y, z );
glVertex3f( x, y, z );
glVertex3f( x, y, z );
etc...
glEnd();
You must draw them counter clockwize. The first three vertices
form the first triangle, then you will add one more for each
new one you want to create. They will sick sack their way to the
end . Hard to explain like this, but that is the basic. Look
for a tut or one of the obove books that is downloadable from the
net.
GLFans.... glBegin( GL_TRIANGLE_FAN );
Quads... glBegin( GL_QUADS );
Good Luck...
Allmight.
-------------------------------------------------Founder and DirectorAllSoft Studios
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement