## Visibility 2D map

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
urosidoki
Kobold
Posts: 34
Joined: Mon Sep 27, 2010 9:14 pm

### Visibility 2D map

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:

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

amartin
Halfling
Posts: 87
Joined: Wed Aug 14, 2013 6:55 am
Location: Norway
x 13

### Re: Visibility 2D map

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.

urosidoki
Kobold
Posts: 34
Joined: Mon Sep 27, 2010 9:14 pm

### Re: Visibility 2D map

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,

amartin
Halfling
Posts: 87
Joined: Wed Aug 14, 2013 6:55 am
Location: Norway
x 13

### Re: Visibility 2D map

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#.