https://github.com/dderevjanik/ts-raycasting
:sun_with_face: Raycasting in Typescript
https://github.com/dderevjanik/ts-raycasting
raycast raycaster raycasting typescript-library
Last synced: 3 months ago
JSON representation
:sun_with_face: Raycasting in Typescript
- Host: GitHub
- URL: https://github.com/dderevjanik/ts-raycasting
- Owner: dderevjanik
- License: mit
- Created: 2016-05-05T13:27:23.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-15T22:11:21.000Z (almost 8 years ago)
- Last Synced: 2025-08-29T05:31:14.212Z (5 months ago)
- Topics: raycast, raycaster, raycasting, typescript-library
- Language: TypeScript
- Homepage:
- Size: 1.28 MB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TS RayCasting


[Tutorial](docs/tutorial.md)
## Overview
TS RayCasting is tiny and fast raycast library written in Typescript.
### API

#### castRay(map, x, y, intersection, rayRot)
```typescript
castRay(map: 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)
```typescript
castRays(map: 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)
```typescript
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