Jump to content
  • Advertisement

Archived

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

md2ge

Line of sight on terrain eng.

This topic is 6908 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

Hello, I''ve implemented a LOS (line of sight) function for my landscape engine, I can''t find any information regarding this subject on the net so I can''t compare my method to anything else, so I will describe what I''m doing here to get some opinions or suggestions. The idea is very simple, the function takes 2 parameters, which are the 2 defining points of a line, we want to know if there''s LOS between them. First thing I do is do a distance check between the points, with this I create an offset value like so offset = 1.0 / distance I then do a for() loop from 0 to 1 incrementing by the offset like so for( float at=0.0; at<= 1.0; at+= offset) then I do a linear interpolation between the 2 points using the "at" value .. newpoint=lerp(start,end,at) then I do a getheight on the terrain at newpoint''s x and z coordinates and compare the getheight''s altitude with the newpoint''s y value if the terrain is higher at this point then there''s no LOS and the function returns NULL It works great, but one thing I don''t really like about it is that say we are checking two points that are very distant and let''s say there''s LOS, this means the function will check a LOT of points in between and since there''s LOS there''s no chance of early quitting out. One way to speed this up would be to sacrifice accuracy by making checks less frequently, like offset *= 4.0 and only check every other 4 points, but then I maybe going about this whole thing wrong, that''s why I''m posting this here hoping to get somebody else''s perspective. =) Thanks, Rick

Share this post


Link to post
Share on other sites
Advertisement
well, here''s some thoughts just off the top of my head.. assuming that the height data is set up with the heights distributed regularly at discrete intervals, here''s what i would do.. "draw" a line between the starting point and the end point (bresenham would be good here, or you could do adaptive constant step interpolation and use bilerp to get the intermediate height values if you want to be really precise), while interpolating the y coordinate and comparing the interpolated value with the height value on the map. if at any point the map value exceeds the interpolated value, the end point can''t be seen from the starting point, and the coordinate you''re at is the occluder.

hope this helps.



--
Float like a butterfly, bite like a crocodile.

Share this post


Link to post
Share on other sites
Hi,

Thanks for the reply, my post was kind of confusing I think, but that''s pretty much what I''m doing now, using linear interpolation so I know where to check for the terrain height and bilinear interpolation to get the actual height, maybe there''s a way to combine this 2 steps into 1, I''m not sure, my problem with this system is that to be sure the result is accurate I have to perform a lot of terrain height checks, thankfully the main reason I need this is for calculating an occlusion map for my quadtree terrain, which can all be pre-done. But I will need a LOS function later on, I want to add a couple ships that will be able to shoot lasers at each other, so I must check for LOS, between the objects, unless I deside this lasers are so powerfull they can penetrate terrain =)

I''ve been thinking about a ray-bounding box check instead, if the ray intersects any boxes between the 2 points then there''s no LOS, this maybe a little faster but will for sure less accurate.

Rick

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!