Skip to content

Janiczek/elm-raycasting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

elm-raycasting

This package currently hosts a single function: Raycast2D.touchedTiles.

tileSize = 50
from = (25, 75) -- center of tile (0,1)
to = (275, 175) -- center of tile (5,3)

touchedTiles tileSize from to
--> Set.fromList [(0,1),(1,1),(1,2),(2,2),(3,2),(4,2),(4,3),(5,3)]

It is an Elm implementation of the DDA (Digital Differential Analysis) algorithm popularized by OneLoneCoder (Javidx9).

The main idea is that instead of walking the ray by small steps and checking which tile we're in, we instead go all the way to the nearest cell boundary. This uses less CPU and doesn't suffer from inaccuracy (overshooting the finishline, as it were).

Screenshot

You can play with a modified version of this code (such that we can visualize the line segments and seen tiles) in this Ellie.

About

Raycasting in 2D space

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages