• Advertisement
Sign in to follow this  

Terrain Following

This topic is 3927 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.
	D3DXVECTOR3 normA;
	D3DXVECTOR3 normB;
	D3DXVec3Cross(&normA, &(v2-v1), &(v4-v1));
	D3DXVec3Cross(&normB, &(v4-v1),  &(v3-v1));

	D3DXVec3Normalize(&normA,&normA);
	D3DXVec3Normalize(&normB,&normA);
	
	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
Advertisement
Suggestion:

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