Advertisement Jump to content
Sign in to follow this  

Moving Around 3D World

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ive created a terrain using a hieght map using Java and OpenGL. My question is that to get a mode(triangle atm) to walk over the surface is it as simple as getting the hieght at that current x and z position from the terrain height array? Or am i going to find its much more complex, and if so couuld you please point me to or just give me a a couple of hints? Thanks in advance, Cheers, Nick

Share this post

Link to post
Share on other sites
It is more complicated... If you just use the raw height values from the heightmap, then the movement of your dude over the terrain is going to be very bumpy. The thing you need to do is "interpolate" the height values, i.e. smooth them out.

There are different ways to interpolate... The easiest is linear interpolation.. It's not 100% smooth, but for the most part you can't notice.

Here are the steps you need to follow, then:

1. For a given (x,z), figure out which triangle of the terrain that corresponds to
2. Retrieve the y (height) values from the heightmap for the 3 corners of that triangle
3. Now, use a standard formula that interpolates the height of a triangle.

Here is some code from one of my games that accomplishes step #3:

_float P_Triangle3D::GetHeightAtPoint( const P_Point2Df &p )
P_Vector3 m, n;

m = m_B - m_A;
n = m_C - m_A;

P_Vector3 normal;

normal = cross( m, n );

_float d = -normal * m_A;
_float y = (-normal.x * p.x - normal.z * p.y - d) / normal.y;

return y;


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!