UNPKG

blaze-2d

Version:

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

68 lines (67 loc) 2.38 kB
import { vec2 } from "gl-matrix"; import CollisionObject from "../collisionObject"; import Constraint, { ConstraintOptions } from "./constraint"; interface SpringConstraintOptions extends ConstraintOptions { length: number; stiffness: number; damping: number; } /** * Represents a damped spring joint between two {@link CollisionObject}s or * a {@link CollisionObject} and a point. */ export default class SpringConstraint extends Constraint { length: number; stiffness: number; angularStiffness: number; damping: number; nDelta: vec2; nMass: number; targetVrn: number; vCoef: number; jAcc: number; /** * Creates a new {@link SpringConstraint} between two bodies. * * @param a The first body * @param b The second body * @param length The resting length of the spring * @param stiffness The stiffness of the spring * @param damping The damping of the spring */ constructor(a: CollisionObject, b: CollisionObject, length: number, stiffness: number, damping?: number); /** * Creates a new {@link SpringConstraint} with the given options. * * @param opts The constraint options */ constructor(opts: SpringConstraintOptions); /** * Creates a new {@link SpringConstraint} between a body and a point. * * @param a The body to constrain * @param point A point in world space * @param length The resting length of the spring. * @param stiffness The stiffness of the spring * @param damping The damping of the spring */ constructor(a: CollisionObject, point: vec2, length: number, stiffness: number, damping?: number); /** * Updates the constraints anchors and prepares for solving. * * @param dt The time since the last update */ preSolve(dt: number): void; /** * Applies the spring forces to the attached bodies. * * @see [Chipmunk2D Damped Spring](https://github.com/slembcke/Chipmunk2D/blob/master/src/cpDampedSpring.c) * @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; postSolve(): void; private calcForce; } export {};