Landscape height determination

Started by
4 comments, last by microwerx 23 years, 10 months ago
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
- MicrowerxWebsite: http://www.geocities.com/
e-mail:[email=jmetzgar@mfactorgames.com]jmetzgar@mfactorgames.com[/email]
Advertisement
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
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
- MicrowerxWebsite: http://www.geocities.com/
e-mail:[email=jmetzgar@mfactorgames.com]jmetzgar@mfactorgames.com[/email]
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
- MicrowerxWebsite: http://www.geocities.com/
e-mail:[email=jmetzgar@mfactorgames.com]jmetzgar@mfactorgames.com[/email]
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
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
- MicrowerxWebsite: http://www.geocities.com/
e-mail:[email=jmetzgar@mfactorgames.com]jmetzgar@mfactorgames.com[/email]

This topic is closed to new replies.

Advertisement