vishull2d
Computes the visible region from a point for a given environment represented by a collection of line segments. Based on Amit Patel's blog post
Use
Just install it using npm:
npm install vishull2d
Then you can use it in your game like this:
var vishull = require("vishull2d")
var lines = [
[[10, 10], [10, -10]]
]
var result = vishull2d(lines, [0,0])
var region = result.region
var ids = result.ids
require("vishull2d")(segments, center)
Computes the visible hull from the point center
segments is a collection of line segments
center is the point from which the visibility is computed
Returns: An object with two properties:
region a counter-clockwise oriented simple polygon representing the visible region.
ids a list of indices into segments representing the walls visible from the region
Credits
(c) 2013 Mikola Lysenko. MIT License