Calculating terrain height
Just don''t seem to work!
My terraing won''t look the way i won''t it to, just because
im not math-genius, and can''t figure out a way of
precalc my heightmap (2D array);
If someone out there can give me a hint, that would be ok!
Source -> http://home.no.net/cybertux/code.txt
- -- ---[XaOs]--- -- -
the terra(th)ing looks really cool!
btw: you have posted this msg 3 times.
maybe set the "mouse clicking sensitivity" a bit back.
btw: you have posted this msg 3 times.
maybe set the "mouse clicking sensitivity" a bit back.
I feel your pain.. what you need to do is this: make up an alogrithm that will go through the points and change them the way you want. For example what I have been doing for testing on my terrain is something like this (from memory
heightmap[MAP_SIZE][MAP_SIZE]
for (i = 1; i < MAP_SIZE; i++)
for (i = 1; i < MAP_SIZE; i++)
{
grab the 8 points height around this point
* * *
* C * where C is the current poin t heightmap[j]
* * *
the others are heightmap[i+1][j+1]...etc
Add them together
Divide by 9
}
This will smooth out the terrain by find out the average heights for each point. It works for me, also if this doesn''t smooth enough, just call this code a couple of more times (more passes in other words).
Hope this helps
Pactuul
"The thing I like about friends in my classes is that they can''t access my private members directly."
heightmap[MAP_SIZE][MAP_SIZE]
for (i = 1; i < MAP_SIZE; i++)
for (i = 1; i < MAP_SIZE; i++)
{
grab the 8 points height around this point
* * *
* C * where C is the current poin t heightmap[j]
* * *
the others are heightmap[i+1][j+1]...etc
Add them together
Divide by 9
}
This will smooth out the terrain by find out the average heights for each point. It works for me, also if this doesn''t smooth enough, just call this code a couple of more times (more passes in other words).
Hope this helps
Pactuul
"The thing I like about friends in my classes is that they can''t access my private members directly."
-Pac "The thing I like about friends in my classes is that they can't access my private members directly." "When listening to some one tell about their problem (whether it's code or not), don't listen to what went right or wrong, but what they assumed....."
I must say....
Things happen to be so easy, that you never would have thougt it could be done that way.
Thank you very much!
ps->It looks better now...
Signing off to bed....z z z z z
- -- ---[XaOs]--- -- -
Things happen to be so easy, that you never would have thougt it could be done that way.
Thank you very much!
ps->It looks better now...
Signing off to bed....z z z z z
- -- ---[XaOs]--- -- -
hey,
I''ve got a similar problem, but not sure how to implement that... not sure how to grab the 8 points around a point and whatnot.
Scott
I''ve got a similar problem, but not sure how to implement that... not sure how to grab the 8 points around a point and whatnot.
Scott
Hey!
It sure helped me the way i did it(probably not the best, but..)
Here is how i did it...
GLvoid smooth()
{
for (x=0; x {
for (z=0; z {
p1 = world[x][z].y //Center point
p2 = world[x-1][z-1].y //Leftmost points
p3 = world[x-1][z].y //
p4 = world[x-1][z+1].y //
p5 = world[x+1][z].y //Rightmost points
p6 = world[x+1][z].y //
p7 = world[x+1][z].y //
p8 = world[x][z+1].y //Front point
p9 = world[x][z-1].y //Back point
height = float((p1+p2+p3+p4+p5+p6+p7+p8+p9)/9);
land[x][z].y = float(height);
}
}
}
Then you do as usual, (random, bumpy heights...), and run
the "smooth();" after the first "bumpy" calc.
If it doesn''t look good after one smooth(), simply do some more of them!! (I use 6 or 7...i think);
Hope this could help, still i think there must be a better way of doing this, but it works!
If you find a better way, let me know ---> tbehrns@c2i.net
- -- ---[XaOs]--- -- -
It sure helped me the way i did it(probably not the best, but..)
Here is how i did it...
GLvoid smooth()
{
for (x=0; x {
for (z=0; z {
p1 = world[x][z].y //Center point
p2 = world[x-1][z-1].y //Leftmost points
p3 = world[x-1][z].y //
p4 = world[x-1][z+1].y //
p5 = world[x+1][z].y //Rightmost points
p6 = world[x+1][z].y //
p7 = world[x+1][z].y //
p8 = world[x][z+1].y //Front point
p9 = world[x][z-1].y //Back point
height = float((p1+p2+p3+p4+p5+p6+p7+p8+p9)/9);
land[x][z].y = float(height);
}
}
}
Then you do as usual, (random, bumpy heights...), and run
the "smooth();" after the first "bumpy" calc.
If it doesn''t look good after one smooth(), simply do some more of them!! (I use 6 or 7...i think);
Hope this could help, still i think there must be a better way of doing this, but it works!
If you find a better way, let me know ---> tbehrns@c2i.net
- -- ---[XaOs]--- -- -
cool! that made my terrain engine really purtty
Thanks!
Scott
Thanks!
Scott
wow.. My post actually helped some one!
btw make sure not to read out of the array, since you will get some very skewed values for the average...To fix do like you have been, but right a getheight() and setheight() function
have them check to see if the point you want is outside the range of the array, if it is just return 0 or some other reasonable number, else you will get a very large positve or negative number that will throw off the heights at the edge of the maps.
Pactuul
btw make sure not to read out of the array, since you will get some very skewed values for the average...To fix do like you have been, but right a getheight() and setheight() function
have them check to see if the point you want is outside the range of the array, if it is just return 0 or some other reasonable number, else you will get a very large positve or negative number that will throw off the heights at the edge of the maps.
Pactuul
-Pac "The thing I like about friends in my classes is that they can't access my private members directly." "When listening to some one tell about their problem (whether it's code or not), don't listen to what went right or wrong, but what they assumed....."
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement