View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Barycentric heightmap

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

### #1polyfrag  Members

Posted 07 March 2013 - 10:01 PM

Given an x and z coordinate how is it possible to check which of two triangles it's over and get the y coordinate (elevation)?

This is for a heightmap.

I was using bilinear interpolation but it doesn't follow the polygons in cases where the two triangles don't follow one plane.

### #2eppo  Members

Posted 08 March 2013 - 04:42 AM

I assume the two triangles lie in a square grid-cell and are connected by a single edge?

If so, first check on which side of the connecting edge the point lies: dot(point - pointOnEdge, cross(float3(0, 1, 0), edge) > 0).

Then plug the x and y values into the overlapping triangle's plane equation. (a*x + b*y + c*z = d) => y = (a*x + c*z - d) / -b.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.