blaze-2d
Version:
A fast and simple WebGL 2 2D game engine written in TypeScript
50 lines (49 loc) • 2.06 kB
TypeScript
import { vec2 } from "gl-matrix";
import Collider, { CollisionResult } from "./collider";
import Triangle from "../../shapes/triangle";
/**
* Represents a triangle collider in 2D world space with a position and dimensions.
*/
export default class TriangleCollider extends Triangle implements Collider {
/**
* Creates a new {@link TriangleCollider} instance with a position and dimensions.
*
* @param width The width of the box
* @param height The height of the box
* @param position The box's position in world space
*/
constructor(width: number, height: number, position?: vec2);
/**
* Checks if this triangle collider is colliding with another collider.
*
* @param c {@link Collider} to test collisions against
* @returns {@link CollisionResult} with the results of the test
*/
testCollision(c: Collider): CollisionResult;
/**
* Calculates a support point on the minkowski difference in a given direction.
*
* @param c The collider to test against
* @param direction The direction to use when calculating furthest points
* @returns The support point in the given direction for the [Minkowski difference](https://en.wikipedia.org/wiki/Minkowski_addition)
*/
supportPoint(c: Collider, direction: vec2): vec2;
/**
* Calculates the furthest point on the collider in a direction.
*
* @param direction The direction in which to calculate the furthest point
* @returns The furthest point on the collider in the given direction
*/
findFurthestPoint(direction: vec2): vec2;
/**
* Calculates the furthest point on the collider in a direction and it's neighbouring vertices on the collider.
*
* @param direction The direction in which to calculate the furthest point
* @returns The furthest point on the collider in the given direction and its left and right neighbours
*/
findFurthestNeighbours(direction: vec2): {
furthest: vec2;
left: vec2;
right: vec2;
};
}