p2.js

JavaScript 2D physics

p2.Body(options)

A physics body.

Parameters

Object options

Description

Options:
- shape: A {p2.Shape} used for collision detection. If absent the body will not collide.
- mass: A number >= 0. If zero, the body becomes static. Defaults to static [0].
- position (vec2)
- velocity (vec2)
- angle (number)
- angularVelocity (number)
- force (vec2)
- angularForce (number)


p2.Broadphase()

Base class for broadphase implementations.


p2.Circle(radius)

Circle shape class.

Parameters

number radius

p2.ContactEquation(bi, bj)

Non-penetration constraint equation.

Parameters

p2.Body bi
p2.Body bj

p2.Equation(bi, bj, minForce, maxForce)

Base class for constraint equations.

Parameters

p2.Body bi
First body participating in the equation
p2.Body bj
Second body participating in the equation
number minForce
Minimum force to apply. Default: -1e6
number maxForce
Maximum force to apply. Default: 1e6

p2.GSSolver()

Iterative Gauss-Seidel constraint equation solver.


p2.GridBroadphase(xmin, xmax, ymin, ymax, nx, ny)

Broadphase that uses axis-aligned bins.

Parameters

number xmin
Lower x bound of the grid
number xmax
Upper x bound
number ymin
Lower y bound
number ymax
Upper y bound
number nx
Number of bins along x axis
number ny
Number of bins along y axis

p2.NaiveBroadphase()

Naive broadphase implementation. Does N^2 tests.


p2.Particle()

Particle shape class.


p2.Plane()

Plane shape class. The plane is facing in the Y direction.


p2.Shape()

Base class for shapes.


p2.Solver()

Base class for constraint solvers.


p2.Spring(bodyA, bodyB, options)

A spring, connecting two bodies.

Parameters

p2.Body bodyA
p2.Body bodyB
Object options

Description

Options:
- restLength: A number > 0. Default: 1
- stiffness: A number >= 0. Default: 100
- damping: A number >= 0. Default: 1


p2.World(options)

The dynamics world, where all bodies and constraints lives.

Parameters

Object options

Description

Options:
- solver (p2.Solver) Default: {p2.GSSolver}
- gravity (vec2) Default: -9.78
- broadphase (p2.Broadphase) Default: {p2.NaiveBroadphase}