Module ROT.FOV.Bresenham
Bresenham Based Ray-Casting FOV calculator.
See http://en.wikipedia.org/wiki/Bresenham's_line_algorithm. Included for sake of having options. Provides three functions for computing FOV
Functions
init (lightPassesCallback, options) | Constructor. |
compute (cx, cy, r, callback) | Compute. |
computeThorough (cx, cy, r, callback) | Compute Thorough. |
computeQuick (cx, cy, r, callback) | Compute Thorough. |
Functions
- init (lightPassesCallback, options)
-
Constructor.
Called with ROT.FOV.Bresenham:new()
Parameters:
- lightPassesCallback function A function with two parameters (x, y) that returns true if a map cell will allow light to pass through
- options Options
- topology int Direction for light movement Accepted values: (4 or 8)
- useDiamond boolean If true, the FOV will be a diamond shape as opposed to a circle shape.
- compute (cx, cy, r, callback)
-
Compute.
Get visibility from a given point.
This method cast's rays from center to points on a circle with a radius 3-units longer than the provided radius.
A list of cell's within the radius is kept. This list is checked at the end to verify that each cell has been passed to the callback.
Parameters:
- cx int x-position of center of FOV
- cy int y-position of center of FOV
- r int radius of FOV (i.e.: At most, I can see for R cells)
- callback A function that is called for every cell in view. Must accept four parameters.
- x int x-position of cell that is in view
- y int y-position of cell that is in view
- r int The cell's distance from center of FOV
- visibility number The cell's visibility rating (from 0-1). How well can you see this cell?
- computeThorough (cx, cy, r, callback)
-
Compute Thorough.
Get visibility from a given point.
This method cast's rays from center to every cell within the given radius.
This method is much slower, but is more likely to not generate any anomalies within the field.
Parameters:
- cx int x-position of center of FOV
- cy int y-position of center of FOV
- r int radius of FOV (i.e.: At most, I can see for R cells)
- callback A function that is called for every cell in view. Must accept four parameters.
- x int x-position of cell that is in view
- y int y-position of cell that is in view
- r int The cell's distance from center of FOV
- visibility number The cell's visibility rating (from 0-1). How well can you see this cell?
- computeQuick (cx, cy, r, callback)
-
Compute Thorough.
Get visibility from a given point. The quickest method provided.
This method cast's rays from center to points on a circle with a radius 3-units longer than the provided radius.
Unlike compute() this method stops at that point. It will likely miss cell's for fields with a large radius.
Parameters:
- cx int x-position of center of FOV
- cy int y-position of center of FOV
- r int radius of FOV (i.e.: At most, I can see for R cells)
- callback A function that is called for every cell in view. Must accept four parameters.
- x int x-position of cell that is in view
- y int y-position of cell that is in view
- r int The cell's distance from center of FOV
- visibility number The cell's visibility rating (from 0-1). How well can you see this cell?