[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 356
  • Last Modified:

Fast Height Adjustment in OpenGL

I am loading a height map into a 64x64 array and stretching it out to 1024x1024 when I draw it in OpenGL.  As I walk around the terrain, I want the height of the camera (my first person view) to stay a steady amount from the height of the terrain.  Cant just check the verticies because it will be jerky and you will end up walking THROUGH the terrain until you are actually over the higher vertex.  So how can I check the height of an imaginary point in between two points without having to use sqrt.

I dont want to do 2 sqrts every time I take a step.  I know theres a way to do this with angles...
0
lyleworthington
Asked:
lyleworthington
1 Solution
 
TGGCCommented:
There is no fast way to do this by angles, instead of that you have to use linear interpolation. Your mesh consists of a lot triangles, first find the triangle the at the desired position and its three vertexes.

May look like that:

A--------------B
I............/
I..P....../
I......../
I....../
I..../
I../
I/
C

Height of P is (assuming y-axis is height):

Py= Ay + (By-Ay)*((Px - Ax)/(Bx - Ax)) + (Cy-Ay)*((Pz - Az)/(Cz - Az))
0
 
lyleworthingtonAuthor Commented:
Thats exactly what i was looking for, thanks.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now