# 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.

## 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 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 );	normal.Normalize();	_float d = -normal * m_A;	_float y =  (-normal.x * p.x - normal.z * p.y - d) / normal.y;	return y;);

roos

##### Share on other sites
this is a very common query. I get filled with joy because this is one of the few algorithms i worked out on my own.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 17
• 14
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634097
• Total Posts
3015505
×