blaze-2d
Version:
A fast and simple WebGL 2 2D game engine written in TypeScript
72 lines (71 loc) • 2.93 kB
TypeScript
import { vec2 } from "gl-matrix";
/**
* Rotates each vector in an array by a rotation angle in radians around an origin point.
*
* @param base The vectors to apply the rotation to
* @param origin The origin to rotate the vectors around
* @param rotation The rotation (in radians) to apply to each vector
* @returns The rotated vectors
*/
export declare function applyRotation(base: vec2[], origin: vec2, rotation: number): vec2[];
/**
* Translates each vector in an array by a given translation vector
*
* @param base The vectors to apply the translation to
* @param translation The translation to apply to each vector
* @returns The translated vectors
*/
export declare function applyTranslation(base: vec2[], translation: vec2): vec2[];
/**
* Calculates the triple product of three 2D vectors.
*
* This is done by:
* - extending each 2D vector into 3D by giving them a Z value of 0.
* - Calculating the cross product of **A** and **B**, storing the result as vector **R₁**.
* **R₁** will be a vector purely in the z axis as the x and y components after the cross product are 0.
* - The cross product of **R₁** and **C** is then calculated, we'll call this **R₂**.
* **R₂** will be a vector that is perpendicular to **C** and pointing in the direction of **B**.
*
* @see [This post for an explanation](https://stackoverflow.com/questions/44797996/triple-product-in-2d-to-construct-perpendicular-line)
*
* @param a Initial vector
* @param b Vector that the result will be in direction of
* @param c Vector that the result will be perpendicular to
*/
export declare function tripleProduct(out: vec2, a: vec2, b: vec2, c: vec2): vec2;
/**
* Calculates the cross product of **a** with a scalar and stores the value in **out**
*
* @param out The vector to output to
* @param a The vector to cross
* @param scalar The scalar to cross a with
* @returns out
*/
export declare function cross2DWithScalar(out: vec2, a: vec2, scalar: number): vec2;
/**
* Calculates the cross product of 2 2D vectors and returns the Z value of the resulting 3D vector.
*
* @param a The vector to cross
* @param b The vector to cross with **a**
* @returns The Z coordinate of the resultant 3D vector
*/
export declare function cross2D(a: vec2, b: vec2): number;
/**
* Calculate the midpoint between two vectors.
*
* @param out The vector to output the result to
* @param a The start vector
* @param b The end vector
* @returns The resultant vector, `out`
*/
export declare function midpoint(out: vec2, a: vec2, b: vec2): vec2;
/**
* Determines wether two vectors are roughly equal to each other.
*
* @param a The first vector
* @param b The second vector
* @param xSlop The allowed x slop
* @param ySlop The allowed y slop
* @returns Wether the vectors are equal or not
*/
export declare function vec2SloppyEquals(a: vec2, b: vec2, xSlop: number, ySlop: number): boolean;