Sign in to follow this  
Lutyo

Terrain height

Recommended Posts

Lutyo    122
Hi! I have a heightmap(from a raw file), and I create a grid-based terrain from it. My problem is that the heightmap's height and the terrain's height are not the same because of the grids. So sometimes the actor just fly through a hill. What can I do? Please, help me. Thanks: Lutyo

Share this post


Link to post
Share on other sites
OrenGL    228
What do you mean by:
"the terrain's height are not the same because of the grids" ?

If you are flying through the terrain even thought you are checking the height at that point, maybe you testing function has a problem. For example you might be scaling the terrain for rendering but not testing the height.

Share this post


Link to post
Share on other sites
Lutyo    122
Thanks for your fast reply, I will try to explain the problem.

Assume my heightmap is:

1 1 9
1 1 9
1 1 9

and the grid size is 3. The grid will be render from points (1,1),
(1,3), (3,3), and (3,1).
When I draw the grid, the terrain will like this:

1 5 9
1 5 9
1 5 9

and my actor position is (2,2), so the actor's height will be heightmap[2,2]=1. But the terrain's height is 5 there.

I hope you can understand my problem.

Akos

Share this post


Link to post
Share on other sites
OrenGL    228
What if you actor was at [1.5,2.4] ?
What you need to do is create a function that will get the height at a certain point as an abstraction and not access the height map directly.

It would something like this:


float GetHeightAt( float x, float z ){
int x_low = (x / (int)grid)*x;
int x_high = x_low + grid;
int z_low = (z / (int)grid)*z;
int z_high = z_low + grid;
int up_left = heightmap[x_low,z_high];
int up_right = heightmap[x_high,z_high];
int down_left = heightmap[x_low,z_low];
int down_right = heightmap[x_high,z_low];
int up_height = (up_left + up_right)/2.0f;
int down_height = (down_left + down_right)/2.0f;
float result = (up_height + down_height)/2.0f;
return result;
}


Share this post


Link to post
Share on other sites
Steve132    433
while OrenGL has a very good point which is something that you need to consider, your implementation as I understand it is MAJORLY flawed for another reason, and this reason definatly needs to be fixed before you move on to OrenGL's solution

[QUOTE]Assume my heightmap is:

1 1 9
1 1 9
1 1 9

and the grid size is 3. The grid will be render from points (1,1),
(1,3), (3,3), and (3,1).
When I draw the grid, the terrain will like this:

1 5 9
1 5 9
1 5 9[/QUOTE]

what I interpret this to mean is that because you are taking your heightmap and "rendering from points (1,1), (1,3, (3,3) and (3,1)", this means you are rendering a big quad from the outer points of your height map, with the height from heightmap[row and column ]. there fore with this example,

you are renderign a quad from row and column (1,1)....(3,1), which would give points (with z as the height from the heightmap) "(1,1,1) , (1,3,9),(3,3,9) and (3,1,1)" this is the root cause of your problem, and it also explains why the actor is going through the rendered hill. when doing terrain mapping, you need to render a quad for EACH section of the grid. if you just do one quad for the whole thing, the terrain you end up rendering will just be the AVERAGE of the total height map, which explains why the render is giving 5 for the height at the middle, ((1 + 9)/2 = 5 . however your actor is positioned at the ACTUAL height in the middle (which according to your real heightmap, is 1!) therefore the "actor" is underneath the heightmap for everywhere except the ends! let me try to illustrate with crude ASCII

[SOURCE]
rendered heightmap
---
---
--- A <-actor is under heightmap
_______
1 5 9
//rendered in straiglt line cause of one quad

actual heightmap

---

--- <U>A</U> <-actor is on heightmap
_______
1 1 9

[/SOURCE]

render ALL of the heightmap quadrents properly, and then do what Oren says to linear interpolate between them, and your problems should be fixed

[Edited by - Steve132 on October 17, 2004 3:33:01 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this