blaze-2d
Version:
A fast and simple WebGL 2 2D game engine written in TypeScript
77 lines (76 loc) • 2.65 kB
TypeScript
import { vec2 } from "gl-matrix";
import Shape from "./shape";
/**
* Represents a Cuboid in 3D space with a width, height and depth.
*/
export default class Rect extends Shape {
private height;
private width;
/**
* Creates a new {@link Rect} instance with dimensions, position and rotation.
*
* @param width The width of the cuboid (x size)
* @param height The height of the cuboid (y size)
* @param position The rects position in world space, default is [0, 0]
* @param rotation The rects rotation, default is 0.
*/
constructor(width: number, height: number, position?: vec2, rotation?: number);
/**
* Calculates the rect's vertices relative to the provided origin in world space.
*
* @param origin The origin to calculate the vertices relative to, should be a world position
* @param rotation An optional world space rotation to apply to the vertices
* @param returnVecs Wether or not to return the vertices as vec2s or raw numbers
* @returns The rect's vertices relative to the provided origin in world space
*/
getVerticesWorld(origin: vec2, rotation?: number, returnVecs?: boolean): number[] | vec2[];
/**
* Calculates the base vertices of the rectangle.
*
* These vertices are the base vertices for a quad, scaled to the width and height of the {@link Rectangle} instance.
*
* @returns The rectangles base vertices
*/
getBaseVertices(): vec2[];
/**
* Gets the rect's vertex indices for drawing using element arrays.
*
* @param offset An offset to apply to each index
* @returns The rect's vertex indices with the given offset added to each index
*/
getIndices(offset?: number): Uint16Array;
/**
* Calculates the rects's UV coords to be used for texture rendering.
*
* @returns the rect's UV coords
*/
getUVCoords(): Float32Array;
/**
* Sets the rectangle's width.
*
* @throws When the the provided width is < 0
*
* @param width The rectangle's new width
*/
setWidth(width: number): void;
/**
* Gets the rectangle's width in world space units.
*
* @returns The rectangle's width in world space
*/
getWidth(): number;
/**
* Sets the rectangle's height.
*
* @throws When the the provided height is < 0
*
* @param height The rectangle's new height
*/
setHeight(height: number): void;
/**
* Gets the rectangle's height in world space units.
*
* @returns The rectangle's height in world space
*/
getHeight(): number;
}