Results 1 to 3 of 3

Thread: Height test question (for terrain)

  1. #1
    Member Contributor
    Join Date
    Mar 2000
    Posts
    94

    Height test question (for terrain)

    I was wondering if anyone could give me a suggestion (or tutorial link) that could help me in finding the correct "y" value anywhere on a given terrain.

    I've loaded a mountain terrain (from 3d studio max)into my opengl program and I'm not sure of a way to calulate the "y" value of what's directly under the "camera" when I move around in first person. Obviously I don't want to walk through a mountain but climb it. Thank you

  2. #2
    Junior Member Newbie
    Join Date
    Nov 2000
    Location
    Rennes, France
    Posts
    7

    Re: Height test question (for terrain)

    I never did it myself, but I see 2 methods... One easy (not efficient actually), and one a bit trickier...

    btw I'm pretty sure they are better methods!

    EASY METHOD :
    --------------
    (1) find the triangle above which you are (work with 2D coords)
    (2) do the calculations depending on your exact position using gradients (in 3D)

    TRICKY METHOD :
    ------------------
    When you move, if you go out of the triangle above which you were, just consider the ones next to the previous triangle. If you can't, you probably moved too quickly (in that case, seek among all the triangles). ** This method require that you keep an array of pointers to a list in which you describe what are the triangles next to another one .. So begin with the first method, and when it works, if it's slow you'll be able to optimize..

  3. #3
    Member Contributor
    Join Date
    Feb 2000
    Location
    Gothenburg, Sweden
    Posts
    68

    Re: Height test question (for terrain)

    Hello Ace_Man!

    Well, if you render your landscape with triangles like this (sorry about the pic) :

    1 ----- 2
    |A /|
    | / |
    |/ B|
    0 ----- 3

    Then if you are above the triangle A use the formula y=(y1-y0)*(z1-Pz)/(z1-z0)-(y2-y0)*(x2-Px)/(x2-x0) and if you are above B then y=(y3-y0)*(x3-Px)/(x3-x0)-(y2-y0)*(x2-Px)/(x2-x0) where Px and Pz are your x and z coordinates respectively. Hope this works, I'm not able to test it right now.

    Cheers Osku

Similar Threads

  1. height field terrain
    By incus in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 04-14-2003, 09:12 AM
  2. Replies: 3
    Last Post: 04-27-2001, 10:14 AM
  3. Terrain Renderer - How to Get Height at [x, y]?
    By Heaven in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-23-2001, 11:32 AM
  4. how to follow the terrain height
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-13-2000, 10:48 PM
  5. Following Terrain Height
    By Phrantik in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 07-01-2000, 07:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean