@types/matter-js
Version:
TypeScript definitions for matter-js
1,082 lines (1,048 loc) • 165 kB
TypeScript
export = Matter;
export as namespace Matter;
declare namespace Matter {
/**
* Installs the given plugins on the `Matter` namespace.
* This is a short-hand for `Plugin.use`, see it for more information.
* Call this function once at the start of your code, with all of the plugins you wish to install as arguments.
* Avoid calling this function multiple times unless you intend to manually control installation order.
* @method use
* @param ...plugin {Function} The plugin(s) to install on `base` (multi-argument).
*/
export function use(...plugins: Array<Plugin | string>): void;
/**
* The `Matter.Axes` module contains methods for creating and manipulating sets of axes.
*/
export class Axes {
/**
* Creates a new set of axes from the given vertices.
* @method fromVertices
* @param {Vertices} vertices
* @returns {axes} A new axes from the given vertices
*/
static fromVertices(vertices: Vector[]): Vector[];
/**
* Rotates a set of axes by the given angle.
* @method rotate
* @param {axes} axes
* @param {number} angle
*/
static rotate(axes: Vector[], angle: number): void;
}
interface IChamfer {
radius?: number | number[] | undefined;
quality?: number | undefined;
qualityMin?: number | undefined;
qualityMax?: number | undefined;
}
interface IChamferableBodyDefinition extends IBodyDefinition {
chamfer?: IChamfer | undefined;
}
/**
* The `Matter.Bodies` module contains factory methods for creating rigid body models
* with commonly used body configurations (such as rectangles, circles and other polygons).
*
* See the included usage [examples](https://github.com/liabru/matter-js/tree/master/examples).
*/
export class Bodies {
/**
* Creates a new rigid body model with a circle hull.
* The options parameter is an object that specifies any properties you wish to override the defaults.
* See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.
* @method circle
* @param {number} x
* @param {number} y
* @param {number} radius
* @param {any} [options]
* @param {number} [maxSides]
* @returns {Body} A new circle body
*/
static circle(x: number, y: number, radius: number, options?: IBodyDefinition, maxSides?: number): Body;
/**
* Creates a new rigid body model with a regular polygon hull with the given number of sides.
* The options parameter is an object that specifies any properties you wish to override the defaults.
* See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.
* @method polygon
* @param {number} x
* @param {number} y
* @param {number} sides
* @param {number} radius
* @param {any} [options]
* @returns {Body} A new regular polygon body
*/
static polygon(x: number, y: number, sides: number, radius: number, options?: IChamferableBodyDefinition): Body;
/**
* Creates a new rigid body model with a rectangle hull.
* The options parameter is an object that specifies any properties you wish to override the defaults.
* See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.
* @method rectangle
* @param {number} x
* @param {number} y
* @param {number} width
* @param {number} height
* @param {any} [options]
* @returns {Body} A new rectangle body
*/
static rectangle(
x: number,
y: number,
width: number,
height: number,
options?: IChamferableBodyDefinition,
): Body;
/**
* Creates a new rigid body model with a trapezoid hull.
* The options parameter is an object that specifies any properties you wish to override the defaults.
* See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.
* @method trapezoid
* @param {number} x
* @param {number} y
* @param {number} width
* @param {number} height
* @param {number} slope
* @param {any} [options]
* @returns {Body} A new trapezoid body
*/
static trapezoid(
x: number,
y: number,
width: number,
height: number,
slope: number,
options?: IChamferableBodyDefinition,
): Body;
/**
* Creates a body using the supplied vertices (or an array containing multiple sets of vertices).
* If the vertices are convex, they will pass through as supplied.
* Otherwise if the vertices are concave, they will be decomposed if [poly-decomp.js](https://github.com/schteppe/poly-decomp.js) is available.
* Note that this process is not guaranteed to support complex sets of vertices (e.g. those with holes may fail).
* By default the decomposition will discard collinear edges (to improve performance).
* It can also optionally discard any parts that have an area less than `minimumArea`.
* If the vertices can not be decomposed, the result will fall back to using the convex hull.
* The options parameter is an object that specifies any `Matter.Body` properties you wish to override the defaults.
* See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.
* @method fromVertices
* @param {number} x
* @param {number} y
* @param {Vertex[][]} vertexSets
* @param {any} [options]
* @param {boolean} [flagInternal=false]
* @param {number} [removeCollinear=0.01]
* @param {number} [minimumArea=10]
* @param {number} [removeDuplicatePoints=0.01]
* @returns {Body}
*/
static fromVertices(
x: number,
y: number,
vertexSets: Vector[][],
options?: IBodyDefinition,
flagInternal?: boolean,
removeCollinear?: number,
minimumArea?: number,
removeDuplicatePoints?: number,
): Body;
}
export interface IBodyDefinition {
/**
* A `Number` specifying the angle of the body, in radians.
*
* @default 0
*/
angle?: number | undefined;
/**
* A `Number` that _measures_ the current angular speed of the body after the last `Body.update`. It is read-only and always positive (it's the magnitude of `body.angularVelocity`).
*
* @readOnly
* @default 0
*/
angularSpeed?: number | undefined;
/**
* A `Number` that _measures_ the current angular velocity of the body after the last `Body.update`. It is read-only.
* If you need to modify a body's angular velocity directly, you should apply a torque or simply change the body's `angle` (as the engine uses position-Verlet integration).
*
* @readOnly
* @default 0
*/
angularVelocity?: number | undefined;
/**
* A `Number` that _measures_ the area of the body's convex hull, calculated at creation by `Body.create`.
*
* @default
*/
area?: number | undefined;
/**
* An array of unique axis vectors (edge normals) used for collision detection.
* These are automatically calculated from the given convex hull (`vertices` array) in `Body.create`.
* They are constantly updated by `Body.update` during the simulation.
*/
axes?: Vector[] | undefined;
/**
* A `Bounds` object that defines the AABB region for the body.
* It is automatically calculated from the given convex hull (`vertices` array) in `Body.create` and constantly updated by `Body.update` during simulation.
*/
bounds?: Bounds | undefined;
/**
* A `Number` that defines the density of the body, that is its mass per unit area.
* If you pass the density via `Body.create` the `mass` property is automatically calculated for you based on the size (area) of the object.
* This is generally preferable to simply setting mass and allows for more intuitive definition of materials (e.g. rock has a higher density than wood).
*
* @default 0.001
*/
density?: number | undefined;
/**
* A `Vector` that specifies the force to apply in the current step. It is zeroed after every `Body.update`. See also `Body.applyForce`.
*
* @default { x: 0, y: 0 }
*/
force?: Vector | undefined;
/**
* A `Number` that defines the friction of the body. The value is always positive and is in the range `(0, 1)`.
* A value of `0` means that the body may slide indefinitely.
* A value of `1` means the body may come to a stop almost instantly after a force is applied.
*
* The effects of the value may be non-linear.
* High values may be unstable depending on the body.
* The engine uses a Coulomb friction model including static and kinetic friction.
* Note that collision response is based on _pairs_ of bodies, and that `friction` values are _combined_ with the following formula:
*
* Math.min(bodyA.friction, bodyB.friction)
*
* @default 0.1
*/
friction?: number | undefined;
/**
* A `Number` that defines the air friction of the body (air resistance).
* A value of `0` means the body will never slow as it moves through space.
* The higher the value, the faster a body slows when moving through space.
* The effects of the value are non-linear.
*
* @default 0.01
*/
frictionAir?: number | undefined;
/**
* An integer `Number` uniquely identifying number generated in `Body.create` by `Common.nextId`.
*/
id?: number | undefined;
/**
* A `Number` that defines the moment of inertia (i.e. second moment of area) of the body.
* It is automatically calculated from the given convex hull (`vertices` array) and density in `Body.create`.
* If you modify this value, you must also modify the `body.inverseInertia` property (`1 / inertia`).
*/
inertia?: number | undefined;
/**
* A `Number` that defines the inverse moment of inertia of the body (`1 / inertia`).
* If you modify this value, you must also modify the `body.inertia` property.
*/
inverseInertia?: number | undefined;
/**
* A `Number` that defines the inverse mass of the body (`1 / mass`).
* If you modify this value, you must also modify the `body.mass` property.
*/
inverseMass?: number | undefined;
/**
* A flag that indicates whether a body is a sensor. Sensor triggers collision events, but doesn't react with colliding body physically.
*
* @default false
*/
isSensor?: boolean | undefined;
/**
* A flag that indicates whether the body is considered sleeping. A sleeping body acts similar to a static body, except it is only temporary and can be awoken.
* If you need to set a body as sleeping, you should use `Sleeping.set` as this requires more than just setting this flag.
*
* @default false
*/
isSleeping?: boolean | undefined;
/**
* A flag that indicates whether a body is considered static. A static body can never change position or angle and is completely fixed.
* If you need to set a body as static after its creation, you should use `Body.setStatic` as this requires more than just setting this flag.
*
* @default false
*/
isStatic?: boolean | undefined;
/**
* An arbitrary `String` name to help the user identify and manage bodies.
*
* @default "Body"
*/
label?: string | undefined;
/**
* A `Number` that defines the mass of the body, although it may be more appropriate to specify the `density` property instead.
* If you modify this value, you must also modify the `body.inverseMass` property (`1 / mass`).
*/
mass?: number | undefined;
/**
* A `Number` that _measures_ the amount of movement a body currently has (a combination of `speed` and `angularSpeed`). It is read-only and always positive.
* It is used and updated by the `Matter.Sleeping` module during simulation to decide if a body has come to rest.
*
* @readOnly
* @default 0
*/
motion?: number | undefined;
/**
* An object reserved for storing plugin-specific properties.
*/
plugin?: any;
/**
* A `Vector` that specifies the current world-space position of the body.
*
* @default { x: 0, y: 0 }
*/
position?: Vector | undefined;
/**
* An `Object` that defines the rendering properties to be consumed by the module `Matter.Render`.
*/
render?: IBodyRenderOptions | undefined;
/**
* A `Number` that defines the restitution (elasticity) of the body. The value is always positive and is in the range `(0, 1)`.
* A value of `0` means collisions may be perfectly inelastic and no bouncing may occur.
* A value of `0.8` means the body may bounce back with approximately 80% of its kinetic energy.
* Note that collision response is based on _pairs_ of bodies, and that `restitution` values are _combined_ with the following formula:
*
* Math.max(bodyA.restitution, bodyB.restitution)
*
* @default 0
*/
restitution?: number | undefined;
/**
* A `Number` that defines the number of updates in which this body must have near-zero velocity before it is set as sleeping by the `Matter.Sleeping` module (if sleeping is enabled by the engine).
*
* @default 60
*/
sleepThreshold?: number | undefined;
/**
* A `Number` that specifies a tolerance on how far a body is allowed to 'sink' or rotate into other bodies.
* Avoid changing this value unless you understand the purpose of `slop` in physics engines.
* The default should generally suffice, although very large bodies may require larger values for stable stacking.
*
* @default 0.05
*/
slop?: number | undefined;
/**
* A `Number` that _measures_ the current speed of the body after the last `Body.update`. It is read-only and always positive (it's the magnitude of `body.velocity`).
*
* @readOnly
* @default 0
*/
speed?: number | undefined;
/**
* A `Number` that allows per-body time scaling, e.g. a force-field where bodies inside are in slow-motion, while others are at full speed.
*
* @default 1
*/
timeScale?: number | undefined;
/**
* A `Number` that specifies the torque (turning force) to apply in the current step. It is zeroed after every `Body.update`.
*
* @default 0
*/
torque?: number | undefined;
/**
* A `String` denoting the type of object.
*
* @default "body"
*/
type?: string | undefined;
/**
* A `Vector` that _measures_ the current velocity of the body after the last `Body.update`. It is read-only.
* If you need to modify a body's velocity directly, you should either apply a force or simply change the body's `position` (as the engine uses position-Verlet integration).
*
* @readOnly
* @default { x: 0, y: 0 }
*/
velocity?: Vector | undefined;
/**
* An array of `Vector` objects that specify the convex hull of the rigid body.
* These should be provided about the origin `(0, 0)`. E.g.
*
* [{ x: 0, y: 0 }, { x: 25, y: 50 }, { x: 50, y: 0 }]
*
* When passed via `Body.create`, the vertices are translated relative to `body.position` (i.e. world-space, and constantly updated by `Body.update` during simulation).
* The `Vector` objects are also augmented with additional properties required for efficient collision detection.
*
* Other properties such as `inertia` and `bounds` are automatically calculated from the passed vertices (unless provided via `options`).
* Concave hulls are not currently supported. The module `Matter.Vertices` contains useful methods for working with vertices.
*/
vertices?: Vector[] | undefined;
/**
* An array of bodies that make up this body.
* The first body in the array must always be a self reference to the current body instance.
* All bodies in the `parts` array together form a single rigid compound body.
* Parts are allowed to overlap, have gaps or holes or even form concave bodies.
* Parts themselves should never be added to a `World`, only the parent body should be.
* Use `Body.setParts` when setting parts to ensure correct updates of all properties.
*/
parts?: Body[] | undefined;
/**
* A self reference if the body is _not_ a part of another body.
* Otherwise this is a reference to the body that this is a part of.
* See `body.parts`.
*/
parent?: Body | undefined;
/**
* A `Number` that defines the static friction of the body (in the Coulomb friction model).
* A value of `0` means the body will never 'stick' when it is nearly stationary and only dynamic `friction` is used.
* The higher the value (e.g. `10`), the more force it will take to initially get the body moving when nearly stationary.
* This value is multiplied with the `friction` property to make it easier to change `friction` and maintain an appropriate amount of static friction.
*
* @default 0.5
*/
frictionStatic?: number | undefined;
/**
* An `Object` that specifies the collision filtering properties of this body.
*
* Collisions between two bodies will obey the following rules:
* - If the two bodies have the same non-zero value of `collisionFilter.group`,
* they will always collide if the value is positive, and they will never collide
* if the value is negative.
* - If the two bodies have different values of `collisionFilter.group` or if one
* (or both) of the bodies has a value of 0, then the category/mask rules apply as follows:
*
* Each body belongs to a collision category, given by `collisionFilter.category`. This
* value is used as a bit field and the category should have only one bit set, meaning that
* the value of this property is a power of two in the range [1, 2^31]. Thus, there are 32
* different collision categories available.
*
* Each body also defines a collision bitmask, given by `collisionFilter.mask` which specifies
* the categories it collides with (the value is the bitwise AND value of all these categories).
*
* Using the category/mask rules, two bodies `A` and `B` collide if each includes the other's
* category in its mask, i.e. `(categoryA & maskB) !== 0` and `(categoryB & maskA) !== 0`
* are both true.
*/
collisionFilter?: ICollisionFilter | undefined;
}
export interface IBodyRenderOptions {
/**
* A flag that indicates if the body should be rendered.
*
* @default true
*/
visible?: boolean | undefined;
/**
* An `Object` that defines the sprite properties to use when rendering, if any.
*/
sprite?: IBodyRenderOptionsSprite | undefined;
/**
* A String that defines the fill style to use when rendering the body (if a sprite is not defined). It is the same as when using a canvas, so it accepts CSS style property values.
Default: a random colour
*/
fillStyle?: string | undefined;
/**
* A Number that defines the line width to use when rendering the body outline (if a sprite is not defined). A value of 0 means no outline will be rendered.
Default: 1.5
*/
lineWidth?: number | undefined;
/**
* A String that defines the stroke style to use when rendering the body outline (if a sprite is not defined). It is the same as when using a canvas, so it accepts CSS style property values.
Default: a random colour
*/
strokeStyle?: string | undefined;
/*
* Sets the opacity. 1.0 is fully opaque. 0.0 is fully translucent
*/
opacity?: number | undefined;
}
export interface IBodyRenderOptionsSprite {
/**
* A `String` that defines the path to the image to use as the sprite texture, if any.
*/
texture: string;
/**
* A `Number` that defines the scaling in the x-axis for the sprite, if any.
*
* @default 1
*/
xScale: number;
/**
* A `Number` that defines the scaling in the y-axis for the sprite, if any.
*
* @default 1
*/
yScale: number;
}
/**
* The `Matter.Body` module contains methods for creating and manipulating body models.
* A `Matter.Body` is a rigid body that can be simulated by a `Matter.Engine`.
* Factories for commonly used body configurations (such as rectangles, circles and other polygons) can be found in the module `Matter.Bodies`.
*
* See the included usage [examples](https://github.com/liabru/matter-js/tree/master/examples).
*/
export class Body {
/**
* Applies a force to a body from a given world-space position, including resulting torque.
* @method applyForce
* @param {Body} body
* @param {Vector} position
* @param {Vector} force
*/
static applyForce(body: Body, position: Vector, force: Vector): void;
/**
* Creates a new rigid body model. The options parameter is an object that specifies any properties you wish to override the defaults.
* All properties have default values, and many are pre-calculated automatically based on other properties.
* See the properties section below for detailed information on what you can pass via the `options` object.
* @method create
* @param {} options
* @returns {Body} body
*/
static create(options: IBodyDefinition): Body;
/**
* Rotates a body by a given angle relative to its current angle, without imparting any angular velocity.
* @method rotate
* @param {Body} body
* @param {number} rotation
*/
static rotate(body: Body, rotation: number): void;
/**
* Returns the next unique group index for which bodies will collide.
* If `isNonColliding` is `true`, returns the next unique group index for which bodies will _not_ collide.
* See `body.collisionFilter` for more information.
* @method nextGroup
* @param {boolean} [isNonColliding=false]
* @returns {Number} Unique group index
*/
static nextGroup(isNonColliding: boolean): number;
/**
* Returns the next unique category bitfield (starting after the initial default category `0x0001`).
* There are 32 available. See `body.collisionFilter` for more information.
* @method nextCategory
* @returns {Number} Unique category bitfield
*/
static nextCategory(): number;
/**
* Given a property and a value (or map of), sets the property(s) on the body, using the appropriate setter functions if they exist.
* Prefer to use the actual setter functions in performance critical situations.
* @method set
* @param {Body} body
* @param {} settings A property name (or map of properties and values) to set on the body.
* @param {} value The value to set if `settings` is a single property name.
*/
static set(body: Body, settings: any, value?: any): void;
/**
* Sets the mass of the body. Inverse mass and density are automatically updated to reflect the change.
* @method setMass
* @param {Body} body
* @param {number} mass
*/
static setMass(body: Body, mass: number): void;
/**
* Sets the density of the body. Mass is automatically updated to reflect the change.
* @method setDensity
* @param {Body} body
* @param {number} density
*/
static setDensity(body: Body, density: number): void;
/**
* Sets the moment of inertia (i.e. second moment of area) of the body of the body.
* Inverse inertia is automatically updated to reflect the change. Mass is not changed.
* @method setInertia
* @param {Body} body
* @param {number} inertia
*/
static setInertia(body: Body, interna: number): void;
/**
* Sets the body's vertices and updates body properties accordingly, including inertia, area and mass (with respect to `body.density`).
* Vertices will be automatically transformed to be orientated around their centre of mass as the origin.
* They are then automatically translated to world space based on `body.position`.
*
* The `vertices` argument should be passed as an array of `Matter.Vector` points (or a `Matter.Vertices` array).
* Vertices must form a convex hull, concave hulls are not supported.
*
* @method setVertices
* @param {Body} body
* @param {Vector[]} vertices
*/
static setVertices(body: Body, vertices: Vector[]): void;
/**
* Sets the parts of the `body` and updates mass, inertia and centroid.
* Each part will have its parent set to `body`.
* By default the convex hull will be automatically computed and set on `body`, unless `autoHull` is set to `false.`
* Note that this method will ensure that the first part in `body.parts` will always be the `body`.
* @method setParts
* @param {Body} body
* @param [body] parts
* @param {boolean} [autoHull=true]
*/
static setParts(body: Body, parts: Body[], autoHull?: boolean): void;
/**
* Set the centre of mass of the body.
* The `centre` is a vector in world-space unless `relative` is set, in which case it is a translation.
* The centre of mass is the point the body rotates about and can be used to simulate non-uniform density.
* This is equal to moving `body.position` but not the `body.vertices`.
* Invalid if the `centre` falls outside the body's convex hull.
* @method setCentre
* @param body
* @param centre
* @param relative
*/
static setCentre(body: Body, centre: Vector, relative?: boolean): void;
/**
* Sets the position of the body instantly. Velocity, angle, force etc. are unchanged.
* @method setPosition
* @param {Body} body
* @param {Vector} position
*/
static setPosition(body: Body, position: Vector): void;
/**
* Sets the angle of the body instantly. Angular velocity, position, force etc. are unchanged.
* @method setAngle
* @param {Body} body
* @param {number} angle
*/
static setAngle(body: Body, angle: number): void;
/**
* Sets the linear velocity of the body instantly. Position, angle, force etc. are unchanged. See also `Body.applyForce`.
* @method setVelocity
* @param {Body} body
* @param {Vector} velocity
*/
static setVelocity(body: Body, velocity: Vector): void;
/**
* Gets the current linear velocity of the body.
* @method getVelocity
* @param {body} body
* @return {vector} velocity
*/
static getVelocity(body: Body): Vector;
/**
* Sets the angular velocity of the body instantly. Position, angle, force etc. are unchanged. See also `Body.applyForce`.
* @method setAngularVelocity
* @param {Body} body
* @param {number} velocity
*/
static setAngularVelocity(body: Body, velocity: number): void;
/**
* Gets the current rotational velocity of the body.
* @method getAngularVelocity
* @param {body} body
* @return {number} angular velocity
*/
static getAngularVelocity(body: Body): number;
/**
* Sets the current rotational speed of the body.
* Direction is maintained. Affects body angular velocity.
* @method setAngularSpeed
* @param {body} body
* @param {number} speed
*/
static setAngularSpeed(body: Body, speed: number): void;
/**
* Gets the current rotational speed of the body.
* Equivalent to the magnitude of its angular velocity.
* @method getAngularSpeed
* @param {body} body
* @return {number} angular speed
*/
static getAngularSpeed(body: Body): number;
/**
* Updates properties `body.velocity`, `body.speed`, `body.angularVelocity` and `body.angularSpeed` which are normalised in relation to `Body._baseDelta`.
* @method updateVelocities
* @param {body} body
*/
static updateVelocities(body: Body): void;
/**
* Gets the current linear speed of the body.
* Equivalent to the magnitude of its velocity.
* @method getSpeed
* @param {body} body
* @return {number} speed
*/
static getSpeed(body: Body): number;
/**
* Sets the current linear speed of the body.
* Direction is maintained. Affects body velocity.
* @method setSpeed
* @param {body} body
* @param {number} speed
*/
static setSpeed(body: Body, speed: number): void;
/**
* Sets the body as static, including isStatic flag and setting mass and inertia to Infinity.
* @method setStatic
* @param {Body} body
* @param {boolean} isStatic
*/
static setStatic(body: Body, isStatic: boolean): void;
/**
* Scales the body, including updating physical properties (mass, area, axes, inertia), from a world-space point (default is body centre).
* @method scale
* @param {Body} body
* @param {number} scaleX
* @param {number} scaleY
* @param {Vector} [point]
*/
static scale(body: Body, scaleX: number, scaleY: number, point?: Vector): void;
/**
* Moves a body by a given vector relative to its current position, without imparting any velocity.
* @method translate
* @param {Body} body
* @param {Vector} translation
*/
static translate(body: Body, translation: Vector): void;
/**
* Performs a simulation step for the given `body`, including updating position and angle using Verlet integration.
* @method update
* @param {Body} body
* @param {number} deltaTime
* @param {number} timeScale
* @param {number} correction
*/
static update(body: Body, deltaTime: number, timeScale: number, correction: number): void;
/**
* A `Number` specifying the angle of the body, in radians.
*
* @default 0
*/
angle: number;
/**
* A `Number` that _measures_ the current angular speed of the body after the last `Body.update`. It is read-only and always positive (it's the magnitude of `body.angularVelocity`).
*
* @readOnly
* @default 0
*/
readonly angularSpeed: number;
/**
* A `Number` that _measures_ the current angular velocity of the body after the last `Body.update`. It is read-only.
* If you need to modify a body's angular velocity directly, you should apply a torque or simply change the body's `angle` (as the engine uses position-Verlet integration).
*
* @readOnly
* @default 0
*/
readonly angularVelocity: number;
/**
* A `Number` that _measures_ the area of the body's convex hull, calculated at creation by `Body.create`.
*
* @default
*/
area: number;
/**
* An array of unique axis vectors (edge normals) used for collision detection.
* These are automatically calculated from the given convex hull (`vertices` array) in `Body.create`.
* They are constantly updated by `Body.update` during the simulation.
*/
axes: Vector[];
/**
* A `Bounds` object that defines the AABB region for the body.
* It is automatically calculated from the given convex hull (`vertices` array) in `Body.create` and constantly updated by `Body.update` during simulation.
*/
bounds: Bounds;
/**
* A `Number` that is set to the radius of the object if the body was constructed using `Bodies.circle`.
* May have a value of `null` if the body is no longer a circle (i.e. was scaled with a scaleX != scaleY).
*
* @default 0
*/
circleRadius?: number | undefined;
/**
* A `Number` that defines the density of the body, that is its mass per unit area.
* If you pass the density via `Body.create` the `mass` property is automatically calculated for you based on the size (area) of the object.
* This is generally preferable to simply setting mass and allows for more intuitive definition of materials (e.g. rock has a higher density than wood).
*
* @default 0.001
*/
density: number;
/**
* A `Vector` that specifies the force to apply in the current step. It is zeroed after every `Body.update`. See also `Body.applyForce`.
*
* @default { x: 0, y: 0 }
*/
force: Vector;
/**
* A `Number` that defines the friction of the body. The value is always positive and is in the range `(0, 1)`.
* A value of `0` means that the body may slide indefinitely.
* A value of `1` means the body may come to a stop almost instantly after a force is applied.
*
* The effects of the value may be non-linear.
* High values may be unstable depending on the body.
* The engine uses a Coulomb friction model including static and kinetic friction.
* Note that collision response is based on _pairs_ of bodies, and that `friction` values are _combined_ with the following formula:
*
* Math.min(bodyA.friction, bodyB.friction)
*
* @default 0.1
*/
friction: number;
/**
* A `Number` that defines the air friction of the body (air resistance).
* A value of `0` means the body will never slow as it moves through space.
* The higher the value, the faster a body slows when moving through space.
* The effects of the value are non-linear.
*
* @default 0.01
*/
frictionAir: number;
/**
* An integer `Number` uniquely identifying number generated in `Body.create` by `Common.nextId`.
*/
id: number;
/**
* A `Number` that defines the moment of inertia (i.e. second moment of area) of the body.
* It is automatically calculated from the given convex hull (`vertices` array) and density in `Body.create`.
* If you modify this value, you must also modify the `body.inverseInertia` property (`1 / inertia`).
*/
inertia: number;
/**
* A `Number` that defines the inverse moment of inertia of the body (`1 / inertia`).
* If you modify this value, you must also modify the `body.inertia` property.
*/
inverseInertia: number;
/**
* A `Number` that defines the inverse mass of the body (`1 / mass`).
* If you modify this value, you must also modify the `body.mass` property.
*/
inverseMass: number;
/**
* A flag that indicates whether the body is considered sleeping. A sleeping body acts similar to a static body, except it is only temporary and can be awoken.
* If you need to set a body as sleeping, you should use `Sleeping.set` as this requires more than just setting this flag.
*
* @default false
*/
isSleeping: boolean;
/**
* A flag that indicates whether a body is considered static. A static body can never change position or angle and is completely fixed.
* If you need to set a body as static after its creation, you should use `Body.setStatic` as this requires more than just setting this flag.
*
* @default false
*/
isStatic: boolean;
/**
* A flag that indicates whether a body is a sensor. Sensor triggers collision events, but doesn't react with colliding body physically.
*
* @default false
*/
isSensor: boolean;
/**
* An arbitrary `String` name to help the user identify and manage bodies.
*
* @default "Body"
*/
label: string;
/**
* A `Number` that defines the mass of the body, although it may be more appropriate to specify the `density` property instead.
* If you modify this value, you must also modify the `body.inverseMass` property (`1 / mass`).
*/
mass: number;
/**
* A `Number` that _measures_ the amount of movement a body currently has (a combination of `speed` and `angularSpeed`). It is read-only and always positive.
* It is used and updated by the `Matter.Sleeping` module during simulation to decide if a body has come to rest.
*
* @readOnly
* @default 0
*/
readonly motion: number;
/**
* A `Vector` that specifies the current world-space position of the body.
*
* @default { x: 0, y: 0 }
*/
position: Vector;
/**
* An `Object` that defines the rendering properties to be consumed by the module `Matter.Render`.
*/
render: IBodyRenderOptions;
/**
* A `Number` that defines the restitution (elasticity) of the body. The value is always positive and is in the range `(0, 1)`.
* A value of `0` means collisions may be perfectly inelastic and no bouncing may occur.
* A value of `0.8` means the body may bounce back with approximately 80% of its kinetic energy.
* Note that collision response is based on _pairs_ of bodies, and that `restitution` values are _combined_ with the following formula:
*
* Math.max(bodyA.restitution, bodyB.restitution)
*
* @default 0
*/
restitution: number;
/**
* A `Number` that defines the number of updates in which this body must have near-zero velocity before it is set as sleeping by the `Matter.Sleeping` module (if sleeping is enabled by the engine).
*
* @default 60
*/
sleepThreshold: number;
/**
* A `Number` that specifies a tolerance on how far a body is allowed to 'sink' or rotate into other bodies.
* Avoid changing this value unless you understand the purpose of `slop` in physics engines.
* The default should generally suffice, although very large bodies may require larger values for stable stacking.
*
* @default 0.05
*/
slop: number;
/**
* A `Number` that _measures_ the current speed of the body after the last `Body.update`. It is read-only and always positive (it's the magnitude of `body.velocity`).
*
* @readOnly
* @default 0
*/
readonly speed: number;
/**
* A `Number` that allows per-body time scaling, e.g. a force-field where bodies inside are in slow-motion, while others are at full speed.
*
* @default 1
*/
timeScale: number;
/**
* A `Number` that specifies the torque (turning force) to apply in the current step. It is zeroed after every `Body.update`.
*
* @default 0
*/
torque: number;
/**
* A `String` denoting the type of object.
*
* @default "body"
*/
type: string;
/**
* A `Vector` that _measures_ the current velocity of the body after the last `Body.update`. It is read-only.
* If you need to modify a body's velocity directly, you should either apply a force or simply change the body's `position` (as the engine uses position-Verlet integration).
*
* @readOnly
* @default { x: 0, y: 0 }
*/
readonly velocity: Vector;
/**
* An array of `Vector` objects that specify the convex hull of the rigid body.
* These should be provided about the origin `(0, 0)`. E.g.
*
* [{ x: 0, y: 0 }, { x: 25, y: 50 }, { x: 50, y: 0 }]
*
* When passed via `Body.create`, the vertices are translated relative to `body.position` (i.e. world-space, and constantly updated by `Body.update` during simulation).
* The `Vector` objects are also augmented with additional properties required for efficient collision detection.
*
* Other properties such as `inertia` and `bounds` are automatically calculated from the passed vertices (unless provided via `options`).
* Concave hulls are not currently supported. The module `Matter.Vertices` contains useful methods for working with vertices.
*/
vertices: Vector[];
/**
* An array of bodies that make up this body.
* The first body in the array must always be a self reference to the current body instance.
* All bodies in the `parts` array together form a single rigid compound body.
* Parts are allowed to overlap, have gaps or holes or even form concave bodies.
* Parts themselves should never be added to a `World`, only the parent body should be.
* Use `Body.setParts` when setting parts to ensure correct updates of all properties.
*/
parts: Body[];
/**
* A self reference if the body is _not_ a part of another body.
* Otherwise this is a reference to the body that this is a part of.
* See `body.parts`.
*/
parent: Body;
/**
* An object reserved for storing plugin-specific properties.
*/
plugin: any;
/**
* A `Number` that defines the static friction of the body (in the Coulomb friction model).
* A value of `0` means the body will never 'stick' when it is nearly stationary and only dynamic `friction` is used.
* The higher the value (e.g. `10`), the more force it will take to initially get the body moving when nearly stationary.
* This value is multiplied with the `friction` property to make it easier to change `friction` and maintain an appropriate amount of static friction.
*
* @default 0.5
*/
frictionStatic: number;
/**
* An `Object` that specifies the collision filtering properties of this body.
*
* Collisions between two bodies will obey the following rules:
* - If the two bodies have the same non-zero value of `collisionFilter.group`,
* they will always collide if the value is positive, and they will never collide
* if the value is negative.
* - If the two bodies have different values of `collisionFilter.group` or if one
* (or both) of the bodies has a value of 0, then the category/mask rules apply as follows:
*
* Each body belongs to a collision category, given by `collisionFilter.category`. This
* value is used as a bit field and the category should have only one bit set, meaning that
* the value of this property is a power of two in the range [1, 2^31]. Thus, there are 32
* different collision categories available.
*
* Each body also defines a collision bitmask, given by `collisionFilter.mask` which specifies
* the categories it collides with (the value is the bitwise AND value of all these categories).
*
* Using the category/mask rules, two bodies `A` and `B` collide if each includes the other's
* category in its mask, i.e. `(categoryA & maskB) !== 0` and `(categoryB & maskA) !== 0`
* are both true.
*/
collisionFilter: ICollisionFilter;
}
/**
* The `Matter.Bounds` module contains methods for creating and manipulating axis-aligned bounding boxes (AABB).
*/
export class Bounds {
min: Vector;
max: Vector;
/**
* Creates a new axis-aligned bounding box (AABB) for the given vertices.
* @method create
* @param {Vertices} vertices
* @returns {Bounds} A new bounds object
*/
static create(vertices: Vertices): Bounds;
/**
* Updates bounds using the given vertices and extends the bounds given a velocity.
* @method update
* @param {Bounds} bounds
* @param {Vertices} vertices
* @param {Vector} velocity
*/
static update(bounds: Bounds, vertices: Vertices, velocity: Vector): void;
/**
* Returns true if the bounds contains the given point.
* @method contains
* @param {Bounds} bounds
* @param {Vector} point
* @returns {boolean} True if the bounds contain the point, otherwise false
*/
static contains(bounds: Bounds, point: Vector): boolean;
/**
* Returns true if the two bounds intersect.
* @method overlaps
* @param {Bounds} boundsA
* @param {Bounds} boundsB
* @returns {boolean} True if the bounds overlap, otherwise false
*/
static overlaps(boundsA: Bounds, boundsB: Bounds): boolean;
/**
* Translates the bounds by the given vector.
* @method translate
* @param {Bounds} bounds
* @param {Vector} vector
*/
static translate(bounds: Bounds, vector: Vector): void;
/**
* Shifts the bounds to the given position.
* @method shift
* @param {Bounds} bounds
* @param {Vector} position
*/
static shift(bounds: Bounds, position: Vector): void;
}
export interface ICompositeDefinition {
/**
* An array of `Body` that are _direct_ children of this composite.
* To add or remove bodies you should use `Composite.add` and `Composite.remove` methods rather than directly modifying this property.
* If you wish to recursively find all descendants, you should use the `Composite.allBodies` method.
*
* @default []
*/
bodies?: Body[] | undefined;
/**
* An array of `Composite` that are _direct_ children of this composite.
* To add or remove composites you should use `Composite.add` and `Composite.remove` methods rather than directly modifying this property.
* If you wish to recursively find all descendants, you should use the `Composite.allComposites` method.
*
* @default []
*/
composites?: Composite[] | undefined;
/**
* An array of `Constraint` that are _direct_ children of this composite.
* To add or remove constraints you should use `Composite.add` and `Composite.remove` methods rather than directly modifying this property.
* If you wish to recursively find all descendants, you should use the `Composite.allConstraints` method.
*
* @default []
*/
constraints?: Constraint[] | undefined;
/**
* An integer `Number` uniquely identifying number generated in `Composite.create` by `Common.nextId`.
*/
id?: number | undefined;
/**
* A flag that specifies whether the co