Terrain Following

Started by
0 comments, last by ldeej 16 years, 11 months ago
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.
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.

This topic is closed to new replies.

Advertisement