Jump to content
  • Advertisement
Sign in to follow this  

Terrain Following

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

Hi, having a little trouble with terrain following i have a heightmap and i have located the cell and triangle inwhich i am on.
	D3DXVec3Cross(&normA, &(v2-v1), &(v4-v1));
	D3DXVec3Cross(&normB, &(v4-v1),  &(v3-v1));

	if(dx >= dz) {
		//right tri
		yHeight = v1.y + (normB.x * dx + normB.z * dz ) / -normB.y;
	}else if(dx < dz) {
		//left tri
		yHeight = v1.y + (normA.x * dx + normA.z * dz ) / -normA.y;

The quad is layed out like so: V1 ----- v2 | \ | | \ | | \ | v3 ------v4 I get jumping though and it doesnt seem to calculate the point on the triangle at all. Iknow my maths is a bit funky, so please can anyone guide me? Ash.

Share this post

Link to post
Share on other sites

If you have a heightmap and you are using this for terrain following only then you can use the heightmap directly. Find the pixel on the heightmap you are over, and then bilinear interpolate adjacent pixels and you will find the height without having to do point in triangle tests.

Share this post

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

  • Advertisement

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!