Results 1 to 4 of 4

Thread: Line of Sight over a 3D terrain map

  1. #1
    Member Newbie
    Join Date
    Oct 2003
    Posts
    35

    Line of Sight over a 3D terrain map

    How might I give a line of sight to an object that can move? I am working on a 3D map made up of quads between a total of 10000 points (100 by 100), and each point has its own x, y, and z coordinate.
    Please help,

    Andrew
    DirectX: A giant pile of undocumented CRAP

  2. #2
    Guest

    Re: Line of Sight over a 3D terrain map

    Do you want to calculate the angle to the object or test if its visible? Search the net for collision detecting. The code will be faster if your data has a hierarchial structure so that big parts can be culled.

  3. #3
    Member Newbie
    Join Date
    Apr 2000
    Posts
    44

    Re: Line of Sight over a 3D terrain map

    You call it a 3d landscape, but then specify the # of polygons to be 10000 (100x100)
    I'm guessing you're using a heightmap.

    The quick way to check if two points can see each other across a height map is to use some sort of line algorithm to step across the heightmap.
    What I'd do is find the vector (p2(x,y,z) - p1(x,y,z)) between the two points. Find whether the change in x (we'll call it dx) or y (dy) is greater abs(dx) or abs(dy)
    (pseudo/vb code)

    canSeeOtherPoint = true
    if abs(dx)>abs(dy) then
    x=int(p1.x)+Sgn(dx)'setup the first step
    y=p1.y+dy/dx
    z=p1.z+dz/dx
    for x = int(p1.x)+Sgn(dx) to int(p2.x)
    if z<LandscapeArray(int(x),int(y)) then
    canSeeOtherPoint = false
    z=z+dz 'add dz in respect to dx to z
    y=y+dy/dx 'we're adding dy in respect to dx
    x=x+sgn(dx) 'step to the next x position
    loop until (sgn(dx)<0 and x<p2.x) or (sgn(dx)>0 and x>p2.x) or canSeeOtherPoint == false


    And you'd do a similar set of stuff if the primary axis was Y instead of X
    btw, x,y, and z are all floating point values
    if canSeeOtherPoint is true, then... the points can see each other...

    Btw, this is just an approimation, you'd really want to do some linear calculations to check for intersection of the triangles in case the guy was just barely covered up.

    A better approximation would probably to do a linear interpolation along the non-primary axis at each height check, based upon the fractional value of the non-primary axis (so, x, if it were the primary, would always be an integer (ie, no interpolation), but you'd pass y as a float and average the two points nearest to y (int(y) and int(y)+1) based upon their distance from y:

    height = (Landscape(x,int(y))*(1-(y-int(y))+Landscape(x,int(y)+1)*(y-int(y))

    something like that...

    If this isn't what you're wanting... umm, I'll delete my post or something,
    -Michael

    [This message has been edited by Thr33d (edited 10-31-2003).]

  4. #4
    Member Newbie
    Join Date
    Apr 2000
    Posts
    44

    Re: Line of Sight over a 3D terrain map

    By the way, I was using X and Y as the axis if you were looking down on the heightmap as an image. Z would be altitude in the example.


    Here's a picture of what it sounds like you're trying to do, the red is an example of how you might write the above method to do the checking (except it would break early if they couldn't see each other.



    -Michael
    (Yeah, I drew the red in by hand... it should probably be following a slightly different path. You get the picture though.

    [This message has been edited by Thr33d (edited 10-31-2003).]

Similar Threads

  1. Why does my terrain have strange line segments?
    By MysticWizard in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 10-05-2017, 08:59 PM
  2. Line of Sight - Light Shadow from Spotlight..
    By Viker in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 07-24-2010, 07:37 AM
  3. Line-of-Sight algorithms/methods
    By Machiavelli in forum OpenGL: Advanced Coding
    Replies: 15
    Last Post: 07-21-2003, 10:55 AM
  4. don't render the objects not in the sight
    By beginner620824 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-28-2003, 05:00 AM
  5. How can i create 3-D sight on another 3-D sight ?
    By MeadowDreamer in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 10-25-2002, 04:16 AM

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