Skip to content

raycasting

Ray tracing algorithms. Algorithms for identifying visible segments of a pattern from a single cell. This can be used for 'field of view' applications.

Sources:

  • http://www.adammil.net/blog/v125_Roguelike_Vision_Algorithms.html
  • http://www.roguebasin.com/index.php?title=LOS_using_strict_definition

raycasting.cast

Casts a ray from a start to an end cell. Returns true/false if the cast is successful/blocked. Adapted from: http://www.roguebasin.com/index.php?title=LOS_using_strict_definition

Parameters:

Name Type Description
v0 forma.cell starting cell of ray
v1 forma.cell end cell of ray
domain forma.pattern the domain in which we are casting

Returns:

  • boolean — true or false depending on whether the ray was successfully cast

raycasting.cast_octant

Casts rays from a start cell across an octant.

Parameters:

Name Type Description
v0 forma.cell starting cell of ray
domain forma.pattern the domain in which we are casting
oct integer the octant identifier (integer between 1 and 8)
ray_length number the maximum length of the ray

Returns:

  • forma.pattern — the pattern illuminated by the ray casting

raycasting.cast_360

Casts rays from a starting cell in all directions.

local visible = ray.cast_360(cell.new(5, 5), domain, 10)

Parameters:

Name Type Description
v0 forma.cell starting cell of ray
domain forma.pattern the domain in which we are casting
ray_length number the maximum length of the ray

Returns:

  • forma.pattern — the pattern illuminated by the ray casting