TS RayCasting
Overview
TS RayCasting is tiny and fast raycast library written in Typescript.
API
castRay(map, x, y, intersection, rayRot)
castRaymap: number, x: number, y: number, intersection: testintersection, rayRot: number: IRay
Will cast ray from position in map, which is two-dimensional world of numbers, where every number means a specific wall. To check if ray already hit a wall, there's intersection callback. If testfunction returns false, then it'll stop casting ray further and it means that wall was hit.
castRays(map, x, y, rot, intersection, config)
castRaysmap: number, x: number, y: number, rot: number, intersection: testintersection, config: IRayConf = defaultConfig: IRay
Will cast several rays from position in map, which is two-dimensional world of numbers, where every number means a specific wall. rot is direction of camera or caster. To check if ray already hit a wall, there's intersection callback. If testfunction returns false, then it'll stop casting ray further and it means that wall was hit.
intersection(row, column, dist, index)
;
It's same callback in both castRay and castRays function, where is put a logic of hitting a wall. If testFunctions returns false, it'll stop casting ray further (specific ray, not all rays in castRays function).
Devs
npm run build
build library, everything will be indist/
foldernpm run build:web
build minified raycast library for browsernpm run build:node
build library with all declaration filesnpm run build:example
build examplesnpm run lint
lint all .ts files