UNPKG

blaze-2d

Version:

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

59 lines (58 loc) 2.19 kB
import { vec2 } from "gl-matrix"; import CollisionObject from "../collisionObject"; import Constraint, { ConstraintOptions } from "./constraint"; interface DistanceConstraintOptions extends ConstraintOptions { length: number; } /** * Represents a distance/pin joint between two {@link CollisionObject}s or * a {@link CollisionObject} and a point. * * This constraint will maintain a set distance between the two anchor points. */ export default class DistanceConstraint extends Constraint { length: number; bias: number; nDelta: vec2; nMass: number; jnAcc: number; /** * Creates a new {@link DistanceConstraint} between two bodies. * * @param a The first body * @param b The second body * @param length The distance to maintain between the bodies */ constructor(a: CollisionObject, b: CollisionObject, length: number); /** * Creates a new {@link Constraint} with the given options. * * @param opts The constraint options */ constructor(opts: DistanceConstraintOptions); /** * Creates a new {@link DistanceConstraint} between a body and a point. * * @param a The body to constrain * @param point A point in world space * @param length The distance to maintain between the body and point. */ constructor(a: CollisionObject, point: vec2, length: number); 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 {};