Results 1 to 6 of 6

Thread: Terrain height

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    11

    Question

    Using OpenGL, I've made a function to construct a terrain from a grayscale picture. Does anyone have a nice small efficient formula to calculate the height of the terrain in any given point-even between vertexes of the terrain

    Here's a very crude diagram:

    I hope it formats correctly...

    +----+----+----+----+----+
    | | | | | |
    +----+----+----+----+----+
    | | | | | |
    +----+----+----+----+----+
    | | | A | | |
    +----+----+----+----+----+
    | | | | | |
    +----+----+----+----+----+

    Each + is a vertex of the terrain with a different height.
    Suppose someone is standing at point A - how do you calculate how high the character is?

    Thanks,
    pollier

  2. #2
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    355
    can't you just store the character's y co-ord?
    buzzwords are the language of fools

  3. #3
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    If you know the position you could check the color of your map to calculate the y-pos...

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    How about averaging the four outer points?
    Code:
    A-------D
    |       |
    |   P   |
    |       |
    B-------C
    P = (A + B + C + D) / 4
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    11

    Not what I meant...

    Thanks for the ideas. You were close, but not enough...

    +--------+
    |..a......|
    |..........|
    |.....b...|
    +--------+

    (Each + is a vertex point, or a pixel of my bitmap of the terrain)

    All the + have different heights. Therefore, point a is going to be at a different height than point b. How can I calculate this?

    Also, can someone tell me how to put formatted text on this forum?

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    It would be a lot easier with hexagonal tiles, since then you have flat tiles and not any complicated formula you use. Of course you could divide the tile into two and use three vertexes.

    Anyway you could calculate the average using the distance as the mass parameter as you do when you calculate central mass point.
    Code:
    _
    \
    /_  h * (Dx^2+Dy^2)^.5
    _______________________
        _
        \
        /_ (Dx^2+Dy^2)^.5
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width