#### Archived

This topic is now archived and is closed to further replies.

# Landscape height determination

This topic is 6661 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I''ve been building a landscape engine in the past few days. I have the rendering engine implemented and have weaned out the bugs for that part of my program. My problem is that I need to know the height for a given point in the landscape because I need to adjust the players "y" position in order to walk on the landscape. Does anyone have any possible solutions for determining the height? Thanks - Microwerx

##### Share on other sites
Well, the easiest solution would probably be to just check the value
in the heightmap at the position your standing, but that wouldn''t look
good when moving around. It''s better to interpolate with the neighbouring
height values.

vec_t CHeightMap::GetInterpolateHeight( vec_t fX, vec_t fY ){    int iX, iY;	vec_t dX, dY;    iX = (int)fX;	iY = (int)fY;    dX = (vec_t)fX - (vec_t)iX;	dY = (vec_t)fY - (vec_t)iY;	vec_t hY, hY2, Height;	hY = m_pHeightMap[ iY * m_iWidth + iX ] + 	( m_pHeightMap[ (iY+1) * m_iWidth + iX ] - m_pHeightMap[ iY * m_iWidth + iX ] ) * (vec_t)dY;	hY2= m_pHeightMap[ iY * m_iWidth + iX + 1 ] + 	( m_pHeightMap[ (iY+1) * m_iWidth + iX + 1 ] - m_pHeightMap[ iY * m_iWidth + iX + 1 ] ) * (vec_t)dY;	Height = hY + ( hY2 - hY ) * (vec_t)dX;	return Height;}

Greets Tobias - http://come.to/polygone

##### Share on other sites
Thanks for the code-snippet. I''m going to try it out tonight(6-21-2000) I did something similar but not quite the same and I got a very choppy appearance (and it was incorrectly determining the height half-the time.) Once again Thanks. I''ll post a message saying if it works.

- Microwerx

##### Share on other sites
Thanks for the code-snippet. I had tried something very similar but now I know where I messed up. I was using a linear interpolation function to determine the height but I must have used the wrong value for it. I''ll try this code out soon and post a message if it works. Once again thanks.

- Microwerx

##### Share on other sites
microwerx,

You can also do it if you know (or calculate) the ''normal'' of the ground surface the player is standing on...

Use X,Y,Z of the first point of the triangle, and its normal (from memory):

PlayerY = Y + ((PlayerX - X) * NormX) + (PlayerZ - Z) * NormZ))

To summerize that equation, we get the absolute distances in x and z, between the player and the first point of the triangle. Multiply each abs distance by the relative normal vector (which has to be a normalized vector) and then add them to the Y height of point 1. I hope that makes sense

Later

Matt

Check out my project at:www.btinternet.com/~Matthew.Bennett

##### Share on other sites
Thank you Tobias for your code snippet. It worked perfectly! I know what I did wrong.

One note: I tried to use mathematical formulas for determining both the landscape and the height at a given point. What I found was quite unusual. You have to be careful with the equations that you use because there might be small, yet undesirable, effects like peaks in the map that don''t exist on the visible map.

- Microwerx

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 35
• ### Forum Statistics

• Total Topics
632634
• Total Posts
3007550
• ### Who's Online (See full list)

There are no registered users currently online

×