UNPKG

blaze-2d

Version:

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

56 lines (55 loc) 2.05 kB
import { mat2, vec2 } from "gl-matrix"; import CollisionObject from "../collisionObject"; import Constraint, { ConstraintOptions } from "./constraint"; interface PivotConstraintOptions extends ConstraintOptions { point: vec2; } /** * Represents a pivot joint between two {@link CollisionObject}s or * a {@link CollisionObject} and a point. * * This constraint will keep the object's joined together by their anchor points at the given point. */ export default class PivotConstraint extends Constraint { bias: vec2; jAcc: vec2; k: mat2; /** * Creates a new {@link PivotConstraint} between two bodies. * * @param a The first body * @param b The second body * @param point The point to join the bodies at in world space */ constructor(a: CollisionObject, b: CollisionObject, point: vec2); /** * Creates a new {@link PivotConstraint} with the given options. * * @param opts The constraint options */ constructor(opts: PivotConstraintOptions); /** * Creates a new {@link PivotConstraint} between a body and a point. * * @param a The body to constrain * @param point A point in world space */ constructor(a: CollisionObject, point: vec2); preSolve(dt: number): void; /** * Computes and applies the impulse to keep the bodies at the joint's length. * * @see [Chipmunk2D Pin Joint](https://github.com/slembcke/Chipmunk2D/blob/master/src/cpPinJoint.c) * @see [MatterJS Constraint](https://github.com/liabru/matter-js/blob/master/src/constraint/Constraint.js) * @see [Dyn4j Distance Constraint](https://dyn4j.org/2010/09/distance-constraint/) * @see [Constraints and Solvers](https://research.ncl.ac.uk/game/mastersdegree/gametechnologies/physicstutorials/8constraintsandsolvers/Physics%20-%20Constraints%20and%20Solvers.pdf) * * @param dt The time since the last update */ solve(dt: number): void; /** * Applies the cached impulse. */ postSolve(): void; } export {};