Global

Methods

beginOverlap(body)

Returns an RxJS observable that emits an OverlapInfo object any time the given body collides with another body.
Parameters:
Name Type Description
body Body
Source:

body() → {Body}

Returns an object that can be added to the scene, built with the given support functions. For each supplied support function, a new support function is created, with an additional `body` field, which points to the returned body.
Parameters:
Name Type Description
props.supports Array.<Support> A set of support functions.
props.isKinematic Boolean Whether the body should move based on the physics simulation or not.
Source:
Returns:
Type
Body

bodyOf(support) → {Body}

Returns the body that the given support is attached too, or null if it is not attached to any body.
Parameters:
Name Type Description
support BodySupport
Source:
Returns:
Type
Body

box() → {Support}

Returns a box support function given the position and size. The box is centered around the given position, and the length of the edges is specified by the size.
Parameters:
Name Type Description
props.position Array.<Number> The position of the box
props.size Array.<Number> The size of the box along each axis
Source:
Returns:
Type
Support

changed(body)

Returns an RxJS observable that emits any time the given body changes.
Parameters:
Name Type Description
body Body
Source:

circle() → {Support}

Returns a circle support function given the position, radius, and axis, where axis is an array representing the normal of the circle.
Parameters:
Name Type Description
props.position Array.<Number> The position of the circle
props.radius Number The radius (default 1.0)
props.axis Array.<Number> The axis around which the circle is placed (default up).
Source:
Returns:
Type
Support

collisionScene() → {CollisionScene}

Returns a scene object. The scene efficiently handles collisions for multiple bodies, and supports the overlap events for bodies. To check for overlaps, call the update() method of the returned scene object. This will then emit the beginOverlap, endOverlap, and stayOverlap subjects for each body that overlaps another body. It also has a `overlapped` subject, which emits an OverlapInfo object when two bodies overlap. This object is emitted only once per pair.
Parameters:
Name Type Description
props.tolerance Number Tolerance for GJK and EPA algorithms. Reduce this number to increase precision (default 0.001)
Source:
Returns:
Type
CollisionScene

createProfiler()

Create a profiler, to be accessed by profiler()
Source:

endOverlap(body)

Returns an RxJS observable that emits an OverlapInfo object when the given body stops colliding with another body.
Parameters:
Name Type Description
body Body
Source:

hull(…supports) → {Support}

Returns a support function that is a combination of the given support functions. Given a vector d, runs each support function with d as an argument, then returns the result with the highest dot product with d.
Parameters:
Name Type Attributes Description
supports Support <repeatable>
The list of support functions.
Source:
Returns:
Type
Support

overlap(scene)

Returns an RxJS observable that emits an OverlapInfo any time two objects in the scene are overlapping.
Parameters:
Name Type Description
scene Scene
Source:

point(x, y, z) → {Support}

Returns a point support function given its position.
Parameters:
Name Type Description
x Number The X position
y Number The Y position
z Number The Z position
Source:
Returns:
Type
Support

profiler() → {Profiler}

Returns the profiler currently in use, or null if none have been created.
Source:
Returns:
Type
Profiler

scene() → {Scene}

Creates a scene with very basic physics.
Parameters:
Name Type Description
props.gravity Array.<Number> Acceleration due to gravity (default [0, -9.8, 0])
props.tolerance Number Tolerance for GJK and EPA algorithms. Reduce this number to increase precision (default 0.001)
Source:
Returns:
Type
Scene

sphere() → {Support}

Returns a sphere support function given the position and radius.
Parameters:
Name Type Description
props.position Array.<Number> The position of the sphere
props.radius Number The radius (default 1.0)
Source:
Returns:
Type
Support

split(a, b, d)

Returns a support function that uses a when the dot product with d is greater than or equal to zero, and b when the dot product is less than zero. This can be used to create shapes such as a hemisphere.
Parameters:
Name Type Description
a Support The "top" support
b Support The "bottom" support
d Array.<Number> The direction (default up)
Source:

stayOverlap(body)

Returns an RxJS observable that emits an OverlapInfo object while the given body is overlapping another body.
Parameters:
Name Type Description
body Body
Source:

sum(…supports) → {Support}

Returns a support function that is the Minkowski sum of the given functions.
Parameters:
Name Type Attributes Description
supports Support <repeatable>
The list of support functions.
Source:
Returns:
Type
Support

transformable(support, transform, inverse) → {Support}

Returns a support function that applys a transformation. It takes two functions as arguments: transform, and inverse. transform takes a vector in object space and transforms it to world space. inverse takes a direction in world space and transforms it to object space. Note that inverse should operate on a direction, and should not apply a translation.
Parameters:
Name Type Description
support Support The support function
transform function A function that transforms a given vector into world space. This should be done in place.
inverse function A function that transforms a given direction into object space. This should be done in place.
Source:
Returns:
Type
Support

Type Definitions

Body

A transformable collection of shapes.
Type:
  • Object
Properties:
Name Type Description
supports Array.<BodySupport> An array of support functions, each with a body field pointing to the returned object
transform Matrix4 The current transformation
update function Updates the objects bounding box in the scene
position Vector3 The current position. Set the position using transform and then calling update()
velocity Vector3 The current velocity
isKinematic Subject Whether the object should be affected by physics
Source:

BodySupport

A Support that is paired with a body.
Type:
Source:

CollisionScene

Properties:
Name Type Description
add function Add a body to the scene
remove function Remove a body from the scene
update function Update the scene, trigger events
getOverlap function Given a support, returns an observable that emits OverlapInfo objects for each object the support is overlapping.
Source:

OverlapInfo

Type:
  • Object
Properties:
Name Type Description
amount Vector3
support BodySupport
other BodySupport
Source:

Profiler

Properties:
Name Type Description
gist function Return a human readable string about the profile
Source:

Scene

Properties:
Name Type Description
add function Add a Body to the scene
remove function Remove a Body from the scene
update function Update the scene given dt, the delta time in seconds
getOverlap function Given a support, returns an observable that emits OverlapInfo objects for each object the support is overlapping.
Source:

Support(d)

A function that returns the point with the highest dot product with the given direction on a shape.
Parameters:
Name Type Description
d Vector3 The normalized input direction. This should be modified in place.
Source: