UNPKG

blaze-2d

Version:

A fast and simple WebGL 2 2D game engine written in TypeScript

69 lines (68 loc) 2.42 kB
import { vec2 } from "gl-matrix"; import Shape from "./shape"; /** * Represents a circle in 2D space with a radius and centre. */ export default class Circle extends Shape { private radius; /** * Creates a new {@link Circle} instance with a radius, position and rotation. * * @param radius The radius of the circle * @param centre The circle's centre in world space, default is [0, 0] * @param rotation The circle's rotation, default is 0. */ constructor(radius: number, centre?: vec2, rotation?: number); /** * Calculates the circle'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 circle'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 circle. * * These vertices are the base vertices for a quad, scaled to the diameter of the {@link Circle} instance. * * @returns The circle's base vertices */ getBaseVertices(): vec2[]; /** * Gets the circle's vertex indices for drawing using element arrays. * * @param offset An offset to apply to each index * @returns The circle's vertex indices with the given offset added to each index */ getIndices(offset?: number): Uint16Array; /** * Calculates the circle's UV coords to be used for texture rendering. * * @returns the circle's UV coords */ getUVCoords(): Float32Array; /** * Scales the first vector by the components in the second vector, returning the resultant vector. * * @param v1 The first vector * @param v2 The second vector * @returns A new vector with the scaled components */ private vertexScale; /** * Sets the circle's radius. * * @throws When the provided radius is < 0 * * @param radius The circle's new radius */ setRadius(radius: number): void; /** * Gets the radius of the circle. * * @returns The radius of the circle */ getRadius(): number; }