ts-raycasting
TypeScript icon, indicating that this package has built-in type declarations

0.0.14 • Public • Published

TS RayCasting

Travis

Raycast Example

Tutorial

Overview

TS RayCasting is tiny and fast raycast library written in Typescript.

API

castray-example

castRay(map, x, y, intersection, rayRot)

castRay(mapnumber[][], xnumber, ynumber, intersectiontestintersection, rayRotnumber)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)

castRays(mapnumber[][], xnumber, ynumber, rotnumber, intersectiontestintersection, configIRayConf = 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)

type testintersection = (row: number, column: number, dist: number, index: number) => boolean;

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 in dist/ folder
  • npm run build:web build minified raycast library for browser
  • npm run build:node build library with all declaration files
  • npm run build:example build examples
  • npm run lint lint all .ts files

Package Sidebar

Install

npm i ts-raycasting

Weekly Downloads

6

Version

0.0.14

License

MIT

Unpacked Size

1.52 MB

Total Files

87

Last publish

Collaborators

  • dderevjanik