Skip to content

legends2k/2d-fov

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Field of View and Line of Sight in 2D

View it in action in your browser!

The idea is to find the field of view from a given point in a 2D world which has buildings. Many resources on the web doing 360° FoV exists; these have their FoV's distance and angle unbound. This is simpler to design; arriving at a fast implementation is easier since -- if rightly done -- there would be no intersection queries every iteration of the loop to eat up performance. However, the FoV here is different; it's limited both by angle and distance. Care is taken to have an optimised solution that avoids unnecessary intersection tests so that it's usable in a game where multiple agents would need their FoV computed every frame.

This implementation is done in HTML5 Canvas/JavaScript for easy viewing but the idea is mathematical and can be implemented in any language. The only library it uses is glMatrix for vector calculations. The code is heavily commented and includes references to articles and books for someone to learn from it.

The design document has all the gory details, again with references for further study.