# Heightfield

This topic is 1128 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

What kind of interpolation does PhysX or Unity use for heightfields? There is a total paucity of code out there for Heightfields, and I can't quite figure out how to implement one.

##### Share on other sites

Also the question doesn't make sense (just like the older post linked by Lactose). You need to explain what you're asking about.

PhysX defines exactly how it does intersection testing to heightfield triangles in its documentation.

##### Share on other sites

I need to get the height of a nonvertex, and I don't know how to do that.

##### Share on other sites

You sample the 3 vertices from the heightfield that forms a triangle around your position, and then calculate the height of the triangle at that position.

http://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/apireference/files/structPxHeightFieldTessFlag.html

Not sure why you would do that manually when you have PhysX though.. as there's a method to get the height anywhere in the height-field, the getHeight(x, y) method.

I'm sure Unity has similar methods exposed to scripts, a quick Google shows TerrainData.GetHeight(x, y).

If you need to do it manually, you have to do the same triangle-grid as PhysX does. Each triangle forms a plane, the height of which you should be able to easily calculate when you have a position (calculate intersection of the plane along the vertical line at that position).

##### Share on other sites

If you need to do it manually, you have to do the same triangle-grid as PhysX does. Each triangle forms a plane, the height of which you should be able to easily calculate when you have a position (calculate intersection of the plane along the vertical line at that position).

One interesting mathematical trick is using a determinant to check if 4 points in R^3 are coplanar:
   (x1 y1 z1 1)
det(x2 y2 z2 1) = 0
(x3 y3 z3 1)
(x4 y4 z4 1)
In your case, you know everything but z4. So expand that determinant along the last row and you get a formula with this shape:
 x4 * det(...) - y4 * det(...) + z4 * det(...) - det(...) = 0
Now computing the value of z4 is trivial.

##### Share on other sites

PhysX only expose the elevation for the specific posting on the heightfield. You supplied the data to PhysX so you will have to do the work yourself to figure out the inter-post elevation. Interpolating between the posted elevation sample should work. I suppose you could hack it by doing a raycast against the terrain and using the resulting position as a source for your elevation providing, there is no elevation scaling.

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

• 9
• 33
• 13
• 13
• 10
• ### Forum Statistics

• Total Topics
632583
• Total Posts
3007212

×