UNPKG

blaze-2d

Version:

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

75 lines (74 loc) 2.65 kB
import CollisionObject from "../collisionObject"; import Constraint, { ConstraintOptions } from "./constraint"; interface RotarySpringConstraintOptions extends ConstraintOptions { angle: number; stiffness: number; damping: number; } /** * Represents a damped rotary spring joint between two {@link CollisionObject}s or * a {@link CollisionObject} and itself. * * This joint will aim to maintain the provided angle between the 2 bodies. * * When the joint only consists of one body it will aim to keep that bodies rotation at the specified angle. * * Setting anchor points for this constraint will have no affect. */ export default class RotarySpringConstraint extends Constraint { angle: number; stiffness: number; damping: number; inertiaSum: number; targetWrn: number; wCoef: number; jAcc: number; /** * Creates a new {@link RotarySpringConstraint} between two bodies. * * @param a The first body * @param b The second body * @param angle The resting angle of the spring * @param stiffness The stiffness of the spring * @param damping The damping of the spring */ constructor(a: CollisionObject, b: CollisionObject, angle: number, stiffness: number, damping?: number); /** * Creates a new {@link SpringConstraint} with the given options. * * @param opts The constraint options */ constructor(opts: RotarySpringConstraintOptions); /** * Creates a new {@link RotarySpringConstraint} between a body and a point. * * @param a The body to constrain * @param angle The resting angle of the spring. * @param stiffness The stiffness of the spring * @param damping The damping of the spring */ constructor(a: CollisionObject, angle: number, stiffness: number, damping?: number); /** * Prepares the spring 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; /** * Calculates the torque required to correct the spring. * * @returns The torque required to correct the spring */ private calcTorque; } export {};