Terrain Intersections

I finally got busy and wrote the code that was needed to perform a ray-intersection test with the terrain height map data.  Not only will this be useful for determining where projectiles collide with the ground, I can now also keep the 3rd person camera from clipping with the terrain.

I was worried, but the final algorithm turned out to be fairly simple.  I basically generate points to test on the height map using a 2D line drawing algorithm, by projecting the 3D line segment onto the two-dimensional height map data.  Using simple interpolation, I can calculate the height of the 3D line segment at the height map point I’m currently testing.  I then compare this height with the value stored in the height map data.  If the point on the terrain is higher than the line segment at this point, then an intersection was found.

About Eric DeBrosse

Lead developer of the Orion Engine.
This entry was posted in Engine Development. Bookmark the permalink.