Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Height calculation on terrain

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know this have been asked before but I have never seen any realy good answers. My terrain consists of a grid. When have the three points on that grid that''s closest to the camera i want to calculate the height on the point where the camera is. point1 = [x1,y1,z1] point2 = [x2,y2,z2] point3 = [x3,y3,z3] camera = [X,Y,Z] What do I do next to calculate the cameras Y coordinate given the cameras X and Z and the three points. Thanks

Share this post

Link to post
Share on other sites
Find the normal of the plane by taking (p2-p1) X (p3-p1) (cross product). Call it vector n=(nx,ny,nz)

Then plug camera X and Z into the equation

nx * X + ny * Y + nz * Z = n * p1 (dot-product)

You get

Y = (n * p1 - nx * cameraX - nz * cameraZ) / ny

I think that''s right.

My vector and plane algebra might be a little rusty.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!