Page 1 of 1

Visibility 2D map

Posted: Sun Feb 15, 2015 9:36 am
by urosidoki
Hi guys,

I am trying to finish a game prototype at home and I haven't been able to solve one problem.

I have implemented a c++ version of the 2d Visibility algorithm to simulate lights but also to simulate enemies perception cone.
This is a link to the algorithm: http://www.redblobgames.com/articles/visibility/

And this is the result I expect to achieve:
[youtube]IHlHHLAIMx8[/youtube]

I got it working perfectly but now I would like to limit the algorithm in distance. I thought it would e easy but it is turning out more complicated than anticipated.

I tried to do it by modifying the algorithm itself but I fail, now I am under the impression I chose the wrong way, since I got the feeling it can be done with a render operation (some kind of intersection between the result of the algorithm and a full perception cone would give me the desired result).

Does anyone have an idea about how to do this? I got the feeling the solution is related with custom shadow mapping but I am not entirely sure.

Any help would be welcome :)

Kind Regards

Re: Visibility 2D map

Posted: Mon Feb 16, 2015 10:39 am
by amartin
The algorithm there appears to be doing wall and object detection. In that case to limit detection range shouldn't you just need to add a false wall. Centre it on the target and line of sight will never exceed the range. Use either a circle or a square you're choice and you should be good to go without a massive rework.

Re: Visibility 2D map

Posted: Fri Feb 20, 2015 11:43 am
by urosidoki
Hi amartin,

Thanks for your answer, but it doesn't work like that.

Think that the borders of the vision cone must be circular.

Kind Regards,

Re: Visibility 2D map

Posted: Mon Feb 23, 2015 10:44 am
by amartin
You'er going to have to enlighten me why does it not work like that. I see nothing in there stopping you from putting a curved line segment in for the edge of the cone. The first image in the article shows it working with a curved line segment so that confirms what I can see from the code.

If you go to http://roy-t.nl/index.php/2014/02/27/2d ... s-preview/ here and download the source code it's in C# but that shouldn't be a problem. It already has a view radius in it and has a method to add occlusion lines which will be the edge of your cone so it is already setup for what you need. The link came from the initial articles source code list and is much more readable than the original c#.