Jump to content
• Advertisement

# Moving Around 3D World

This topic is 4824 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

##### Share on other sites
Advertisement
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 this post

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

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
JoeJ
20
3. 3
4. 4
frob
12
5. 5
• Advertisement

• 13
• 18
• 13
• 20
• 13
• ### Forum Statistics

• Total Topics
632194
• Total Posts
3004681

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!