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

## 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 on other sites
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.

1. 1
2. 2
3. 3
Rutin
22
4. 4
frob
18
5. 5

• 33
• 13
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
632566
• Total Posts
3007112

×