Sign in to follow this  

Moving Around 3D World

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

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