Creates a new physics body in the specified world based on the provided body definition. The body is added to the appropriate solver set based on its type and state. The function initializes the body's physical properties including position, rotation, velocities, damping values and other simulation parameters.
(b2WorldId)
The ID of the world to create the body in
(b2BodyDef)
The body definition containing initialization parameters
b2BodyId:
The ID of the newly created body
Destroys a body and all associated joints, contacts, shapes, and chains in the physics world. The function cleans up all resources and removes the body from the simulation system.
(b2BodyId)
The identifier of the body to destroy
void:
Retrieves the current number of contacts associated with the specified body. The function first validates the world reference before accessing the body's contact count.
(b2BodyId)
The identifier for the body to query
number:
The number of contacts associated with the body. Returns 0 if the world is invalid.
Retrieves contact data for a specified body. For each active contact, stores the shape IDs of both bodies involved and the contact manifold. Only stores contacts that have the touching flag set.
(b2BodyId)
The ID of the body to get contact data from
(Array<b2ContactData>)
Array to store the contact data
(number)
Maximum number of contacts to retrieve
number:
The number of contacts stored in contactData
For bodies with no shapes, returns an AABB containing only the body's position. For bodies with shapes, computes the union of AABBs of all shapes attached to the body.
(b2BodyId)
The identifier for the body whose AABB is to be computed.
b2AABB:
An AABB that encompasses the body and all its shapes. Returns an empty AABB if the world is not found.
Retrieves the current position component of a body's transform from the physics world. The position is returned as a b2Vec2 representing the body's location in world space.
(b2BodyId)
The identifier for the body whose position is being queried.
b2Vec2:
The position vector of the body in world coordinates.
Retrieves the rotation component (q) from the body's transform. The returned b2Rot object represents the body's angular orientation in 2D space.
(b2BodyId)
The identifier for the body whose rotation is being queried.
b2Rot:
A rotation object containing the cosine and sine of the body's angle.
Retrieves the current transform (position and rotation) of a physics body from the specified Box2D world using the body's identifier.
Object:
The body's transform containing:
Takes a point given in world coordinates and converts it to the body's local coordinate system by applying the inverse of the body's transform.
b2Vec2:
The point expressed in the body's local coordinates
Takes a point given in body-local coordinates and converts it to world coordinates using the body's current transform (position and rotation).
(b2BodyId)
The identifier for the body.
(b2Vec2)
A point in the body's local coordinates.
b2Vec2:
The point transformed to world coordinates.
Takes a vector defined in world coordinates and transforms it to be relative to the body's local coordinate system by applying the inverse of the body's rotation.
b2Vec2:
The vector transformed into the body's local coordinates
Transforms a vector from the body's local coordinate system to the world coordinate system. This operation only performs rotation (not translation) using the body's current rotation matrix.
(b2BodyId)
The identifier for the body
(b2Vec2)
A vector in local body coordinates
b2Vec2:
The vector transformed into world coordinates
Sets the position and rotation of a body, updating its transform and associated shape AABBs. The function updates the body's center, handles broad-phase movement, and adjusts collision bounds.
(b2BodyId)
The identifier of the body to transform
(b2Vec2)
The new position vector for the body
(b2Rot?)
The new rotation for the body. If undefined, keeps current rotation
void:
Retrieves the current linear velocity of a body from its state in the physics world. If the body state cannot be found, returns a zero vector. Linear velocity is often used for calculations (damping, direction, etc) and must be cloned to avoid unwanted effects in the Physics engine.
(b2BodyId)
The identifier for the body.
b2Vec2:
The linear velocity vector of the body. Returns a zero vector (0,0) if the body state is null.
Retrieves the current angular velocity of a body from its state in the physics world. Angular velocity represents how fast the body is rotating.
(b2BodyId)
The identifier for the body.
number:
The angular velocity in radians per second. Returns 0 if the body state cannot be retrieved.
Sets the linear velocity of a body. If the body is static, the function returns without making changes. If the new velocity has a non-zero magnitude, the body will be awakened. The function will return early if the body state cannot be retrieved.
(b2BodyId)
The identifier of the body to modify.
(b2Vec2)
The new linear velocity vector to set.
void:
Sets the angular velocity of a body. If the body is static or has fixed rotation, the function returns without making changes. The body is woken up if a non-zero angular velocity is set.
(b2BodyId)
The identifier of the body to modify
(number)
The new angular velocity in radians per second
void:
Applies a force at a world point to a body. If the force is not applied at the center of mass, it will generate a torque and affect angular motion.
(b2BodyId)
The identifier of the body to apply the force to
(b2Vec2)
The world force vector
(b2Vec2)
The world position of the point of application
(boolean)
Whether to wake the body if it is sleeping
void:
Applies a force to the center of mass of a body. If the body is sleeping, it can optionally be woken up. The force is only applied if the body is in the awake set.
(b2BodyId)
The identifier of the body to apply the force to
(b2Vec2)
The world force vector to apply to the body's center
(boolean)
Whether to wake the body if it is sleeping
void:
Adds the specified torque to the body's total torque. If the wake parameter is true and the body is sleeping, it will be awakened. The torque is only applied if the body is in the awake set.
(b2BodyId)
The identifier of the body to apply torque to
(number)
The amount of torque to apply
(boolean)
Whether to wake the body if it's sleeping
void:
Applies a linear impulse to a body at a specified world point, affecting both its linear and angular velocities.
(b2BodyId)
The identifier of the body to apply the impulse to
(b2Vec2)
The world impulse vector to apply
(b2Vec2)
The world position where the impulse is applied
(boolean)
Whether to wake the body if it's sleeping
void:
Applies a linear impulse to the center of mass of a body. If the body is sleeping, it can optionally be woken up.
(b2BodyId)
The identifier of the body to apply the impulse to
(b2Vec2)
The linear impulse vector to be applied
(boolean)
Whether to wake the body if it's sleeping
void:
Applies an angular impulse to a body, affecting its angular velocity. The impulse is scaled by the body's inverse inertia.
(b2BodyId)
The identifier of the body to apply the impulse to
(number)
The angular impulse to apply
(boolean)
Whether to wake the body if it's sleeping
void:
Retrieves the body type (static, kinematic, or dynamic) for a given body ID by looking up the body in the physics world using the provided identifier.
(b2BodyId)
The identifier for the body to query.
b2BodyType:
The type of the specified body.
Updates a body's type and handles all necessary simulation changes including:
(b2BodyId)
The ID of the body to modify
(b2BodyType)
The new body type to set (static, kinematic, or dynamic)
void:
Associates arbitrary user data with a physics body. The user data can be retrieved later and can be of any type. The body is located using its world identifier and the user data is stored directly on the body object.
(b2BodyId)
The identifier of the body to modify.
(any)
The user data to associate with the body.
void:
Retrieves the custom user data that was previously attached to the specified body. The function first gets the world from the body ID, then retrieves the full body object, and finally returns its user data.
(b2BodyId)
The identifier for the body.
object:
The user data associated with the body.
Retrieves the mass value from a body's simulation data by accessing the world and body objects using the provided body identifier.
(b2BodyId)
The identifier for the body whose mass is to be retrieved.
number:
The mass of the body in kilograms.
Retrieves the rotational inertia value from a body's simulation data using the body's ID. The inertia tensor represents the body's resistance to rotational acceleration.
(b2BodyId)
The ID of the body to get the inertia tensor from.
number:
The inertia tensor value of the body.
Returns a copy of the body's local center of mass position vector. The local center is expressed in the body's local coordinate system.
(b2BodyId)
The identifier for the body.
b2Vec2:
The local center of mass position vector.
Returns a copy of the body's center of mass position in world coordinates. The returned vector is a clone of the internal state, preventing external modification of the body's actual center position.
(b2BodyId)
The identifier for the body whose center of mass position is being queried.
b2Vec2:
A vector representing the world position of the body's center of mass.
Sets the mass properties of a body including mass, rotational inertia, and center of mass. The function updates both the primary mass properties and derived values like inverse mass.
(b2BodyId)
The identifier for the body to modify
(b2MassData)
An object containing:
void:
Retrieves the mass properties of a body, including its total mass, center of mass position, and rotational inertia.
(b2BodyId)
The identifier for the body whose mass data is being retrieved
b2MassData:
An object containing mass properties:
This function retrieves the body from the world using its ID and updates its mass data properties (mass, center of mass, and rotational inertia) based on the shapes attached to it. If the world cannot be accessed, the function returns without performing any operations.
(b2BodyId)
The identifier for the body whose mass properties need to be updated.
void:
Sets the linear damping coefficient for a body, which reduces its linear velocity over time. Linear damping is used to simulate air resistance or fluid friction.
(b2BodyId)
The identifier for the body to modify.
(number)
The new linear damping value. Must be non-negative.
void:
Returns the linear damping coefficient that reduces the body's linear velocity. Linear damping is used to reduce the linear velocity of the body in the absence of forces. The damping parameter can be used to simulate fluid/air resistance.
(b2BodyId)
The identifier for the body.
number:
The linear damping coefficient of the body.
Sets the angular damping coefficient for a body, which reduces its angular velocity over time. Angular damping is a value between 0 and infinity that reduces the body's angular velocity.
(b2BodyId)
The identifier for the target body.
(number)
The new angular damping value. Must be non-negative.
void:
Returns the angular damping coefficient that reduces the body's angular velocity over time. Angular damping is specified in the range [0,1].
(b2BodyId)
The identifier for the body.
number:
The angular damping coefficient of the body.
Sets a scale factor that modifies the effect of gravity on a specific body. A value of 1.0 indicates normal gravity, 0.0 indicates no gravity, and negative values reverse the effect of gravity on the body.
(b2BodyId)
The identifier for the body to modify.
(number)
The scaling factor to apply to gravity for this body.
void:
Gets the gravity scale of a body.
(b2BodyId)
The identifier of the body to query.
number:
The gravity scale factor of the body.
Determines if a body is currently in the awake set by checking its set index against the b2_awakeSet type. Bodies in the awake set are actively participating in the simulation.
(b2BodyId)
The identifier for the body to check.
boolean:
True if the body is in the awake set, false otherwise.
Controls whether a physics body is awake (active) or asleep (inactive). When setting a body to sleep, it will split islands if there are pending constraint removals. When waking a body, it will be moved from the sleeping set to the awake set.
(b2BodyId)
The ID of the body to modify
(boolean)
True to wake the body, false to put it to sleep
void:
Determines if a physics body is enabled by checking if it belongs to the disabled set. A disabled body does not participate in collision detection or dynamics simulation.
(b2BodyId)
The identifier for the body to check.
boolean:
True if the body is enabled, false if disabled.
Returns whether the specified body has sleep enabled. When sleep is enabled, the body can automatically enter a sleep state when it becomes inactive.
(b2BodyId)
The identifier for the body to check.
boolean:
True if sleep is enabled for the body, false otherwise.
Sets the minimum velocity threshold that determines when a body can transition to a sleeping state. When a body's velocity falls below this threshold, it becomes eligible for sleeping.
(b2BodyId)
The identifier for the body to modify.
(number)
The velocity threshold below which the body can sleep.
void:
Returns the minimum speed threshold below which a body can be put to sleep to optimize simulation performance.
(b2BodyId)
The identifier for the body.
number:
The sleep threshold value for the body.
Enables or disables sleep capability for a specific body. When sleep is disabled, the body will be woken if it was sleeping.
(b2BodyId)
The identifier for the body to modify
(boolean)
True to enable sleep capability, false to disable it
void:
Disables a body in the physics simulation by removing it from its current solver set and moving it to the disabled set. The function removes all contacts associated with the body, removes it from any island it belongs to, destroys shape proxies in the broad phase, and transfers associated joints to the disabled set.
(b2BodyId)
The identifier of the body to disable
void:
Enables a previously disabled body in the physics world. When enabled, the body's shapes are added to the broad-phase collision system, and its joints are reconnected to the simulation. The body is moved from the disabled set to either the static set or awake set based on its type.
(b2BodyId)
The identifier of the body to enable
void:
Sets the fixed rotation state of a body. When enabled, the body will not rotate and any existing angular velocity is cleared. The body's mass data is updated to reflect the change in rotational constraints.
(b2BodyId)
The identifier for the body to modify
(boolean)
True to fix the rotation, false to allow rotation
void:
Checks whether a body has fixed rotation enabled. When fixed rotation is enabled, the body will not rotate in response to torques or collisions.
(b2BodyId)
The identifier for the body to check
boolean:
True if the body has fixed rotation enabled, false otherwise
Sets whether a body should be treated as a bullet for continuous collision detection. Bullet bodies are designed for fast moving objects that require more precise collision detection.
(b2BodyId)
The identifier for the physics body.
(boolean)
True to enable bullet mode, false to disable it.
void:
Retrieves the bullet status of a body from the physics simulation. Bullet bodies undergo continuous collision detection for improved accuracy with fast-moving objects.
(b2BodyId)
The identifier for the body to check.
boolean:
True if the body is a bullet, false otherwise.
Enables or disables hit event detection for all shapes attached to a body.
(b2BodyId)
The identifier of the body to modify
(boolean)
Whether to enable or disable hit events
void:
Returns the total count of shapes currently attached to the specified body in the physics world.
(b2BodyId)
The identifier for the body to query.
number:
The number of shapes attached to the body.
Retrieves all shapes attached to the specified body by traversing the linked list of shapes starting from the body's headShapeId. Each shape ID is stored in the provided shapeArray and the total count is returned. If shapeArray is already large enough we can avoid the overhead of growing the array.
(b2BodyId)
The identifier of the body to get shapes from.
number:
The number of shapes found on the body.
Returns the total count of joints that are connected to the specified body.
(b2BodyId)
The identifier for the body to query.
number:
The number of joints connected to the body.
Retrieves the IDs of all joints connected to the specified body, up to the given capacity. The joint IDs are stored in the provided jointArray. The function traverses the body's joint list and copies each joint's ID information including the index, world ID and revision.
(b2BodyId)
The ID of the body to get joints for
(number)
Maximum number of joints to retrieve
number:
The number of joints found and stored in jointArray
Sets the global scaling factor that defines how many length units in the physics simulation correspond to one meter in the real world. This affects all subsequent physics calculations in the Box2D engine.
(number)
The number of length units that represent one meter.
void:
Returns the value of b2_lengthUnitsPerMeter, which defines the conversion factor between physics simulation units and real-world meters.
number:
The number of length units per meter used in the physics simulation.
This function sets the global assertion handler used by Box2D for runtime checks. The assertion handler is called when a Box2D assertion fails.
((Function | null))
The assertion function to handle Box2D assertions.
If null, assertions will be disabled.
void:
This function creates and returns a new b2Version object initialized with Box2D version 3.0.0
b2Version:
A b2Version object containing major version 3, minor version 0, and revision 0
This function is intended to set custom memory allocation and deallocation functions for Box2D. However, in the Phaser Box2D JS implementation, this functionality is not supported and will only generate a warning message.
(Function)
Memory allocation function pointer
(Function)
Memory deallocation function pointer
void:
This function is a stub that warns users that byte count tracking is not supported in the JavaScript implementation of Box2D for Phaser.
number:
An integer representing the total bytes used by Box2D.
This function creates a timer object but is not supported in the Phaser Box2D JS implementation. When called, it issues a console warning about lack of support.
b2Timer:
A timer object for measuring elapsed time.
This is a stub function that exists for compatibility with Box2D but is not implemented in the Phaser Box2D JS port. It logs a warning when called.
number:
Returns 0 since this function not supported
This function is a stub that warns that millisecond timing is not supported in the Phaser Box2D JS implementation.
number:
The elapsed time in milliseconds.
This function returns the elapsed milliseconds from a Box2D timer object and resets it. In the JavaScript implementation for Phaser Box2D, this functionality is not supported and will trigger a warning.
(b2Timer)
The Box2D timer object to query and reset
number:
The elapsed time in milliseconds
This function is a stub that issues a warning message when called, as the sleep functionality is not supported in the Phaser Box2D JS implementation.
(number)
The number of milliseconds to sleep
void:
This function serves as a placeholder for Box2D's b2Yield functionality, which is not supported in the Phaser Box2D JS implementation. When called, it emits a warning to the console.
void:
Creates a debug drawing interface for Box2D that renders shapes to a canvas context.
The canvas is automatically sized to 1280x720 or 720x1280 based on window orientation.
All coordinates are transformed from Box2D world space to screen space.
This feature isn't meant for production. It is purely for debugging and testing. The code
is not optimized, stable or extensible. Implement your own drawing code for production.
(HTMLCanvasElement)
The canvas element to draw on
(CanvasRenderingContext2D)
The 2D rendering context for the canvas
(number
= 20)
The scale factor to convert Box2D coordinates to pixels
b2DebugDraw:
A debug draw instance with methods for rendering Box2D shapes
The debug draw instance includes methods for drawing:
Creates an animation loop using requestAnimationFrame that tracks timing information and FPS. The callback is invoked each frame with the time delta, total time, and current FPS. Frame delta time is capped at 100ms to avoid large time steps.
(function)
Function to call each frame with signature (deltaTime, totalTime, currentFps)
| Name | Description |
|---|---|
callback.deltaTime number
|
Time elapsed since last frame in seconds, capped at 0.1s |
callback.totalTime number
|
Total accumulated time in seconds |
callback.currentFps number
|
Current frames per second, updated once per second |
Attaches an image to the last shape of a Box2D body. The function loads a PNG image asynchronously and sets up drawing parameters including offset, scale, and source rectangle coordinates. The image is stored in the shape's properties for later rendering.
(number)
The ID of the Box2D world
(number)
The ID of the body to attach the image to
(string)
Directory path where the image is located
(string)
Name of the image file
(b2Vec2
= null)
Offset vector for drawing the image
(b2Vec2
= null)
Scale vector for drawing the image
(b2Vec2
= null)
Position in the source image to start drawing from
(b2Vec2
= null)
Size of the region to draw from the source image
Object:
The modified shape object with attached image properties
Converts screen/canvas coordinates to world space coordinates in the Box2D physics system.
(HTMLCanvasElement)
The canvas element being used for rendering
(number)
The scale factor between screen and world coordinates
(Object)
The screen position coordinates
b2Vec2:
A vector containing the world space coordinates
// Convert mouse click position to world coordinates
const worldPos = ConvertScreenToWorld(myCanvas, 30, mousePos);
Transforms a position from world space to screen space, taking into account the canvas dimensions, aspect ratio, and zoom level. The function maps the world coordinates to normalized coordinates (0-1) and then scales them to screen pixels.
(HTMLCanvasElement)
The canvas element used for rendering
(number)
The scale factor for converting world units to pixels
(b2Vec2)
The world position to convert
b2Vec2:
The converted screen coordinates as a b2Vec2
Calculates an intermediate transform by linearly interpolating between two states defined in a sweep motion. The resulting transform accounts for both translation and rotation, adjusted by the local center offset.
(b2Sweep)
A sweep object containing initial (c1, q1) and final (c2, q2)
positions and rotations, along with a local center offset.
(number)
Interpolation factor between 0 and 1, where 0 represents the initial
state and 1 represents the final state.
b2Transform:
A transform object containing the interpolated position (p) and
rotation (q) at the specified time.
Calculates the minimum distance between two line segments defined by their endpoints.
(number)
X coordinate of the first point of segment 1
(number)
Y coordinate of the first point of segment 1
(number)
X coordinate of the second point of segment 1
(number)
Y coordinate of the second point of segment 1
(number)
X coordinate of the first point of segment 2
(number)
Y coordinate of the first point of segment 2
(number)
X coordinate of the second point of segment 2
(number)
Y coordinate of the second point of segment 2
b2SegmentDistanceResult:
An object containing:
(number)
Number of vertices to process (max B2_MAX_POLYGON_VERTICES)
(number)
Radius value for the proxy
b2DistanceProxy:
A new distance proxy containing the processed vertices
This file includes code that is:
Computes the distance between two convex shapes using the GJK (Gilbert-Johnson-Keerthi) algorithm.
(b2DistanceCache)
Cache object to store and retrieve simplex data between calls
(b2DistanceInput)
Input parameters containing:
(number)
Maximum number of simplexes to store
b2DistanceOutput:
Output containing:
Uses an iterative algorithm to determine if and when two convex shapes will collide during a linear motion. Shape B is translated while shape A remains stationary. The algorithm uses support points and simplexes to determine the closest points between the shapes.
(b2ShapeCastPairInput)
Contains:
proxyA - First shape proxy
proxyB - Second shape proxy
transformA - Transform of first shape
transformB - Transform of second shape
translationB - Translation vector for second shape
maxFraction - Maximum fraction of motion to check
b2CastOutput:
Contains:
fraction - Time of impact fraction [0,maxFraction]
point - Point of impact
normal - Surface normal at impact
iterations - Number of iterations used
hit - Whether a collision was detected
Computes when two moving shapes first collide during their motion sweeps. Uses conservative advancement and binary search to find the first time of impact or determine that no impact occurs during the time interval.
(b2TOIInput)
Input parameters containing:
b2TOIOutput:
Output containing:
Sets the target length of a distance joint. The length value is automatically clamped between b2_linearSlop and B2_HUGE. After setting the length, the joint's impulse values are reset to zero.
(b2JointId)
The identifier of the distance joint to modify.
(number)
The desired length of the joint, clamped between b2_linearSlop and B2_HUGE.
void:
This file includes code that is:
Returns the current length of a distance joint. The joint must be of type b2_distanceJoint.
(b2JointId)
The identifier for the distance joint.
number:
The current length of the distance joint.
Sets the enable/disable state of the limit constraint for a distance joint. The joint must be of type b2_distanceJoint or an error will occur.
(b2JointId)
The identifier for the distance joint to modify.
(boolean)
True to enable the joint's limit, false to disable it.
void:
(b2JointId)
The identifier for the distance joint to check.
boolean:
True if the limit is enabled, false otherwise.
Sets the minimum and maximum length constraints for a distance joint. The values are clamped between b2_linearSlop and B2_HUGE. The function resets all impulse values to zero after updating the length range.
(b2JointId)
The identifier for the distance joint
(number)
The minimum allowed length of the joint
(number)
The maximum allowed length of the joint
void:
Gets the minimum length of a distance joint.
(b2JointId)
The identifier for the distance joint.
number:
The minimum length value of the distance joint.
Gets the maximum length of a distance joint.
(b2JointId)
The identifier for the distance joint.
number:
The maximum length value of the distance joint.
Calculates the current distance between the two anchor points of a distance joint in world coordinates. The function transforms the local anchor points of both bodies to world coordinates and computes the distance between them.
(b2JointId)
The identifier for the distance joint
number:
The current length between the two anchor points of the distance joint
Sets the spring behavior state of a distance joint. When enabled, the joint acts like a spring between two bodies. When disabled, the joint maintains a fixed distance between the connected bodies.
(b2JointId)
The identifier of the distance joint to modify.
(boolean)
True to enable spring behavior, false to disable it.
void:
Returns the state of the spring enable flag for the specified distance joint. The function validates that the joint is of type b2_distanceJoint before accessing the spring enable property.
(b2JointId)
The identifier for the distance joint to check.
boolean:
True if the spring mechanism is enabled, false otherwise.
Sets the spring oscillation frequency for a distance joint. The frequency determines how quickly the spring oscillates when disturbed from equilibrium.
(b2JointId)
The identifier for the distance joint to modify.
(number)
The spring frequency in Hertz (oscillations per second).
void:
Sets the damping ratio parameter for a distance joint's spring mechanism. The joint must be of type b2_distanceJoint.
(b2JointId)
The identifier for the distance joint to modify
(number)
The damping ratio for the spring (0 = no damping, 1 = critical damping)
void:
Gets the hertz frequency parameter of a distance joint.
(number)
The identifier for the distance joint.
number:
The hertz frequency value of the distance joint.
Gets the damping ratio of a distance joint.
(number)
The identifier for the distance joint.
number:
The damping ratio of the distance joint.
Enables or disables the motor on a distance joint. When the motor state changes, the motor impulse is reset to zero.
(b2JointId)
The identifier for the distance joint
(boolean)
True to enable the motor, false to disable it
void:
(b2JointId)
The identifier for the distance joint to check.
boolean:
True if the motor is enabled, false otherwise.
Sets the motor speed for a distance joint.
(b2JointId)
The identifier for the distance joint to modify.
(number)
The new motor speed value to set.
void:
Gets the motor speed of a distance joint.
(b2JointId)
The identifier for the distance joint.
number:
The current motor speed of the distance joint in radians per second.
Calculates the motor force by dividing the joint's motor impulse by the inverse time step (inv_h). The joint must be of type b2_distanceJoint.
(b2JointId)
The identifier for the distance joint.
number:
The current motor force in Newtons, calculated as the motor impulse divided by the step time.
Sets the maximum motor force for a distance joint.
(b2JointId)
The identifier for the distance joint to modify.
(number)
The maximum force the motor can generate.
void:
Gets the maximum motor force of a distance joint.
(b2JointId)
The identifier for the distance joint.
number:
The maximum force that can be applied by the joint's motor.
Creates a b2DynamicTree data structure used for efficient spatial partitioning. The tree is initialized with a pre-allocated pool of nodes linked in a free list.
b2DynamicTree:
A new dynamic tree with:
Clears the nodes, leaf indices, and leaf centers arrays of the dynamic tree, effectively destroying the tree's data structure.
(b2DynamicTree)
The dynamic tree to destroy.
void:
Creates a proxy in a dynamic tree for collision detection. The proxy is added as a leaf node.
(b2DynamicTree)
The dynamic tree to add the proxy to
(b2AABB)
The axis-aligned bounding box for the proxy
(number)
The collision category bits for filtering
(number)
User data associated with this proxy
number:
The ID of the created proxy node
Removes a leaf node from the tree, frees the node's memory, and decrements the proxy count. The proxy must be a valid leaf node in the tree.
(b2DynamicTree)
The dynamic tree containing the proxy
(number)
The ID of the proxy to destroy (must be >= 0 and < nodeCapacity)
void:
Returns the number of proxies currently stored in the dynamic tree by accessing the proxyCount property.
(b2DynamicTree)
The dynamic tree to query.
number:
The total count of proxies in the tree.
Updates the position of a proxy in the dynamic tree by removing and reinserting it with a new AABB.
(b2DynamicTree)
The dynamic tree containing the proxy
(number)
The ID of the proxy to move (must be within tree.nodeCapacity)
(b2AABB)
The new axis-aligned bounding box for the proxy
void:
Updates a proxy's AABB in the dynamic tree and rebalances the tree structure by enlarging parent nodes' AABBs as needed.
(b2DynamicTree)
The dynamic tree containing the proxy
(number)
The ID of the proxy to enlarge
(b2AABB)
The new axis-aligned bounding box for the proxy
void:
Returns the height of the specified dynamic tree by accessing the height property of the root node. The height represents the maximum number of levels from the root to any leaf node.
(b2DynamicTree)
The dynamic tree to measure
number:
The height of the tree. Returns 0 if the tree is empty (root is null)
Computes the sum of all internal node perimeters (excluding leaves and root) divided by the root node perimeter. This ratio provides a measure of the tree's spatial organization.
(b2DynamicTree)
The dynamic tree structure to analyze
number:
The ratio of total internal node perimeter to root perimeter. Returns 0 if the tree is empty.
Performs validation checks on a b2DynamicTree data structure to ensure its internal state is consistent. This is typically used for debugging and testing purposes.
(b2DynamicTree)
The dynamic tree to validate
void:
Iterates through all non-leaf nodes in the tree and calculates the absolute height difference between their child nodes. Returns the largest height difference found.
(b2DynamicTree)
The dynamic tree to analyze
number:
The maximum balance value (height difference) found between any pair of sibling nodes
Rebuilds a dynamic tree from the bottom up by iteratively combining nodes with the lowest perimeter cost. The function first identifies all leaf nodes, then pairs them based on minimum combined AABB perimeter, creating parent nodes until a single root node remains.
(b2DynamicTree)
The dynamic tree to rebuild
void:
Updates the axis-aligned bounding boxes (AABBs) of all nodes in the tree by subtracting the newOrigin vector from both their lower and upper bounds.
(b2DynamicTree)
The dynamic tree whose nodes will be shifted
(b2Vec2)
The vector to subtract from all node boundaries
void:
Calculates the memory footprint by summing:
(b2DynamicTree)
The dynamic tree instance to measure.
number:
The estimated memory usage in bytes.
Queries a dynamic tree to find all nodes that overlap with the given AABB and match the category mask bits. Uses a stack-based traversal to efficiently search the tree structure.
(b2DynamicTree)
The dynamic tree to query
(b2AABB)
The axis-aligned bounding box to test for overlaps
(number)
Category bits used to filter nodes
(function)
Function called for each overlapping leaf node.
Return false to terminate early, true to continue.
(any)
User context data passed to the callback function
void:
Traverses the dynamic tree and finds all leaf nodes that intersect with the input ray. For each intersection, calls the callback function which can control continuation of the search. Uses an AABB overlap test and separating axis test to efficiently cull branches.
(b2DynamicTree)
The dynamic tree to query
(b2RayCastInput)
Input parameters for the ray cast including:
(number)
Bit mask to filter nodes by category
(Function)
Function called for each leaf node intersection
(any)
User context passed to callback
Performs a shape cast query against nodes in a dynamic tree, testing for overlaps between a moving shape and static shapes in the tree.
(b2DynamicTree)
The dynamic tree to query against
(b2ShapeCastInput)
Contains the shape definition, translation vector,
radius, and maximum fraction for the cast
(number)
Bit mask to filter tree nodes by category
(Function)
Function called when potential overlaps are found.
Returns a fraction value to continue or terminate the cast
(any)
User data passed to the callback function
void:
The callback function should have the signature:
function(input: b2ShapeCastInput, nodeId: number, userData: any, context: any): number
It should return 0 to terminate the cast, or a fraction between 0 and 1 to update the cast distance
Rebuilds a dynamic tree by collecting all leaf nodes and reconstructing the tree structure. The function deallocates internal nodes during traversal and builds a new balanced tree from the collected leaf nodes.
(b2DynamicTree)
The dynamic tree to rebuild
number:
The number of leaf nodes in the rebuilt tree
(Array<b2TreeNode>)
: The tree nodes
(number)
: The root index
(number)
: The number of nodes
(number)
: The allocated node space
(number)
: Node free list
(number)
: Number of proxies created
(number)
: Allocated space for rebuilding
Checks if a ray cast input is valid by verifying:
(b2RayCastInput)
The ray cast input to validate, containing:
boolean:
True if the ray cast input is valid, false otherwise.
Creates a b2Polygon from a convex hull. If the hull has fewer than 3 points, returns a square shape. The function computes the polygon's vertices, edge normals, and centroid. Each edge normal is a unit vector perpendicular to the corresponding edge.
(b2Hull)
A convex hull structure containing points that define the polygon vertices
(number)
The radius used to round the corners of the polygon
(boolean
= true)
Whether to enforce hull validation
b2Polygon:
A new polygon shape with computed vertices, normals, and centroid
Creates a polygon shape from a hull with specified radius and transform
(b2Hull)
The input hull to create the polygon from
(number)
The radius to offset the polygon vertices
(b2Transform)
Transform to apply to the hull points
(boolean
= true)
Whether to force validation check of the hull
b2Polygon:
A new polygon shape with transformed vertices, computed normals and centroid
Creates a square polygon by calling b2MakeBox with equal dimensions. The square is centered at the origin with sides of length 2h.
(number)
The half-width and half-height of the square.
b2Polygon:
A polygon object representing a square centered at the origin.
This file includes code that is:
Creates a rectangular polygon shape centered at the origin with specified half-widths. The vertices are arranged counter-clockwise starting from the bottom-left corner. The shape includes pre-computed normals for each edge.
(number)
Half-width of the box in the x-direction (must be positive)
(number)
Half-height of the box in the y-direction (must be positive)
b2Polygon:
A polygon shape representing a rectangle with:
Creates a rounded box shape by generating a box with specified dimensions and corner radius.
(number)
Half-width of the box along the x-axis
(number)
Half-height of the box along the y-axis
(number)
Radius of the rounded corners
b2Polygon:
A polygon shape representing a rounded box
Creates a b2Polygon representing a rectangle with the given dimensions. The box is centered at the specified position and rotated by the given angle. The resulting polygon includes 4 vertices, 4 normals, and has its centroid set to the center position.
(number)
Half-width of the box along the x-axis
(number)
Half-height of the box along the y-axis
(b2Vec2)
The center position of the box
(number)
The rotation angle of the box in radians
b2Polygon:
A polygon shape representing the box with 4 vertices and normals
Applies a rigid body transformation to a polygon by:
(b2Transform)
The transformation to apply, consisting of a position vector and rotation.
(b2Polygon)
The polygon to transform, containing vertices, normals and centroid.
b2Polygon:
The transformed polygon with updated vertices, normals and centroid.
Calculates the mass, center of mass, and rotational inertia for a circle shape with given density. The rotational inertia is computed about the center of mass using the parallel axis theorem when the circle's center is offset from the origin.
(b2Circle)
A circle shape object containing radius and center properties
(number)
The density of the circle in mass per unit area
b2MassData:
An object containing:
Computes mass properties for a capsule shape, including total mass, center of mass, and rotational inertia. A capsule consists of a rectangle with semicircles at both ends.
(b2Capsule)
A capsule shape defined by two centers (center1, center2) and a radius
(number)
The density of the capsule in mass per unit area
b2MassData:
An object containing:
Computes mass properties for a polygon shape, including mass, center of mass, and rotational inertia. Handles special cases for 1-vertex (circle) and 2-vertex (capsule) polygons. For polygons with 3 or more vertices, calculates properties using triangulation.
(b2Polygon)
The polygon shape containing vertices, normals, count, and radius
(number)
The density of the shape in mass per unit area
b2MassData:
Object containing:
Calculates the AABB by transforming the circle's center point using the provided transform and extending the bounds by the circle's radius in each direction.
(b2Circle)
The circle shape containing center point and radius.
(b2Transform)
The transform to be applied, consisting of a position (p) and rotation (q).
b2AABB:
An AABB object defined by minimum and maximum points that bound the transformed circle.
Calculates the minimum and maximum bounds of a capsule after applying a transform. The AABB is computed by transforming the capsule's center points and extending the bounds by the capsule's radius in all directions.
(b2Capsule)
A capsule shape defined by two centers and a radius.
(b2Transform)
A transform containing position and rotation to be applied to the capsule.
b2AABB:
An AABB that encompasses the transformed capsule shape.
Computes the Axis-Aligned Bounding Box (AABB) for a polygon shape after applying a transform. The AABB includes the polygon's radius in its calculations.
(b2Polygon)
The polygon shape containing vertices and radius
(b2Transform)
The transform to apply, consisting of position (p) and rotation (q)
b2AABB:
An AABB object with lower and upper bounds that encompass the transformed polygon
Transforms the segment's endpoints using the provided transform, then creates an AABB that encompasses the transformed segment by finding the minimum and maximum coordinates of the transformed endpoints.
(b2Segment)
A line segment defined by two points (point1 and point2)
(b2Transform)
A transform containing position and rotation to be applied to the segment
b2AABB:
An AABB that contains the transformed line segment
Tests if a point lies within a circle by comparing the squared distance between the point and circle's center against the circle's squared radius.
(b2Vec2)
The point to test, represented as a 2D vector.
(b2Circle)
The circle to test against, containing center and radius properties.
boolean:
True if the point lies within or on the circle's boundary, false otherwise.
A capsule is defined by two end centers (center1 and center2) and a radius. The function calculates if the given point lies within the capsule by:
(b2Vec2)
The point to test
(b2Capsule)
The capsule shape defined by two centers and a radius
boolean:
True if the point lies inside or on the capsule, false otherwise
Tests if a point lies inside a polygon shape by calculating the minimum distance between the point and the polygon.
boolean:
True if the point is inside or on the polygon (within shape.radius), false otherwise
Calculates the intersection point between a ray and a circle shape. Returns early with no hit if the ray length is 0 or if the ray passes outside the circle radius.
(b2RayCastInput)
The ray cast input parameters containing:
(b2Circle)
The circle shape to test against, containing:
b2CastOutput:
The ray cast results containing:
Performs a ray cast against a capsule shape. A capsule is defined by two centers and a radius. If the capsule length is near zero, it degrades to a circle ray cast.
(b2RayCastInput)
Contains ray cast parameters including:
(b2Capsule)
The capsule to test against, containing:
b2CastOutput:
Contains the ray cast results:
Performs a ray cast against a line segment, determining if and where the ray intersects the segment. For one-sided segments, intersections are only detected from one side based on a cross product test.
(b2RayCastInput)
Contains origin point, translation vector, and max fraction for the ray
(b2Segment)
The line segment defined by two points (point1 and point2)
(boolean)
Whether to treat the segment as one-sided
b2CastOutput:
Contains hit status, intersection point, normal, and fraction along the ray
Performs a ray cast against a polygon shape, detecting intersection points and normals. For non-zero radius polygons, converts the ray cast into a shape cast operation.
(b2RayCastInput)
Contains origin point, translation vector, and max fraction
(b2Polygon)
The polygon to test against, containing vertices, normals, count and radius
b2CastOutput:
Contains:
Performs shape casting between a circle and a set of points with radius.
(b2ShapeCastInput)
Contains points array, count, radius, translation and maxFraction
(b2Circle)
Circle shape with center point and radius
b2CastOutput:
The shape cast result containing intersection details
Performs shape casting for a capsule shape against a set of points.
(b2ShapeCastInput)
Contains the target points, count, radius,
translation, and maxFraction for the shape cast
(b2Capsule)
The capsule shape defined by two centers and a radius
b2CastOutput:
The result of the shape cast operation
Performs a shape cast operation between a segment and another shape. The function creates proxies for both shapes, sets up their initial transforms, and performs the cast operation using the specified translation and maximum fraction.
(b2ShapeCastInput)
Contains shape points, count, radius, translation, and maxFraction
(b2Segment)
A segment defined by two points (point1 and point2)
b2CastOutput:
The result of the shape cast operation
Performs shape casting between a polygon shape and a set of points, checking for collisions along a translation path.
(b2ShapeCastInput)
Contains the points, count, radius, translation, and maxFraction for the cast
(b2Polygon)
The polygon shape to test against, containing vertices, count, and radius
b2CastOutput:
The result of the shape cast operation
Computes the convex hull of a set of 2D points. The function:
(number)
Number of points in the array
b2Hull:
A hull object containing the computed convex hull vertices
This file includes code that is:
Validates that a hull meets the requirements for a valid convex polygon:
(b2Hull)
The hull to validate, containing points array and count
boolean:
True if the hull is valid, false otherwise
Creates and returns a new b2DistanceJointDef object initialized with specific default values. The length is set to 1 unit and the maxLength is set to B2_HUGE. All other properties of the joint definition retain their default values from the b2DistanceJointDef constructor.
b2DistanceJointDef:
A distance joint definition with:
Initializes a new b2MotorJointDef with common default values. The joint definition includes preset values for maximum force, maximum torque, and correction factor while using default values for linear and angular offsets.
b2MotorJointDef:
A motor joint definition with:
Creates and returns a new b2MouseJointDef object initialized with default values for frequency (hertz), damping ratio, and maximum force parameters.
b2MouseJointDef:
A mouse joint definition with:
Creates and returns a new b2PrismaticJointDef instance with localAxisA initialized to a unit vector pointing along the x-axis (1,0). All other properties retain their default values from the b2PrismaticJointDef constructor.
b2PrismaticJointDef:
A prismatic joint definition with localAxisA set to (1,0)
Creates and initializes a new b2RevoluteJointDef with default values. Sets the drawSize property to 0.25 for visualization purposes.
b2RevoluteJointDef:
A new revolution joint definition with drawSize set to 0.25
Creates and returns a new b2WeldJointDef object initialized with default values. A weld joint essentially glues two bodies together at a reference point.
b2WeldJointDef:
A new weld joint definition with default configuration:
Creates and returns a new b2WheelJointDef with common default values. The joint's local axis is set to point upward, and spring behavior is enabled with standard frequency and damping values.
b2WheelJointDef:
A wheel joint definition with:
(b2WorldId)
The ID of the Box2D world
(b2DistanceJointDef)
The joint definition containing:
b2JointId:
The ID of the created distance joint
(b2WorldId)
The ID of the Box2D world
(b2MotorJointDef)
The joint definition containing:
b2JointId:
The ID of the created motor joint
Creates a mouse joint between two bodies at a specified target point. The joint transforms the target point into local coordinates for both bodies and initializes the joint properties including frequency, damping ratio, and maximum force.
(b2WorldId)
The ID of the Box2D world where the joint will be created
(b2MouseJointDef)
The mouse joint definition containing:
b2JointId:
The ID of the created mouse joint
(b2WorldId)
The ID of the Box2D world
(b2RevoluteJointDef)
The joint definition containing properties like:
b2JointId:
ID of the created revolute joint
Creates a prismatic joint between two bodies in a Box2D world. A prismatic joint constrains two bodies to move relative to each other along a specified axis.
(b2WorldId)
The identifier of the Box2D world
(b2PrismaticJointDef)
The joint definition containing:
b2JointId:
The identifier for the created prismatic joint
Creates a weld joint between two bodies in a Box2D world.
(b2WorldId)
The identifier of the Box2D world
(b2WeldJointDef)
The weld joint definition containing:
b2JointId:
The identifier of the created weld joint
Creates a wheel joint between two bodies in a Box2D world. A wheel joint provides two degrees of freedom: translation along a specified axis and rotation about an orthogonal axis. The joint can be configured with a spring and damper mechanism, translation limits, and a motor.
(b2WorldId)
The identifier of the Box2D world
(b2WheelJointDef)
The wheel joint definition containing configuration parameters
b2JointId:
The identifier of the created wheel joint
Destroys a joint in the physics world. If the world is locked (e.g. during collision detection or integration), the function will return without destroying the joint. The function internally calls b2DestroyJointInternal to handle the actual joint destruction.
(b2JointId)
The identifier of the joint to be destroyed
void:
Retrieves the joint type from the world using the provided joint ID. The function first gets the world reference from the joint ID, then retrieves the full joint object to access its type property.
(b2JointId)
The ID of the joint to query.
b2JointType:
The type of the specified joint.
This function retrieves the identifier of the first body (body A) that is connected to the specified joint. The joint must exist in the world referenced by the jointId.
(b2JointId)
The identifier of the joint.
b2BodyId:
The identifier of the first body connected to the joint.
This function retrieves the identifier of the second body (body B) that is connected to the specified joint. The joint must exist in the world referenced by the jointId.
(b2JointId)
The identifier of the joint.
b2BodyId:
The identifier of body B connected to the joint.
Retrieves the local anchor point A from a joint's simulation data. The anchor point is expressed in the local coordinate system of body A.
(b2JointId)
The identifier for the joint.
b2Vec2:
The local anchor point A in the body A frame.
Retrieves the local anchor point B of a joint, which represents the connection point on the second body (body B) in that body's local coordinate system.
(b2JointId)
The identifier for the joint.
b2Vec2:
The local anchor point B in the body's local coordinates.
When enabled, the bodies connected by the joint can collide with each other. When disabled, collisions between the connected bodies are filtered out. The function updates the broadphase when enabling collisions and destroys existing contacts between the bodies when disabling collisions.
(b2JointId)
The identifier for the joint to modify.
(boolean)
True to enable collision between connected bodies, false to disable.
void:
Gets the collideConnected flag for the specified joint. This flag determines if the two bodies connected by this joint are allowed to collide with each other.
(b2JointId)
The ID of the joint to query
boolean:
Whether the connected bodies can collide with each other
Associates arbitrary user data with a specified joint in the physics world. The joint is located using its world and joint identifiers, and its user data property is updated with the provided value.
(b2JointId)
The identifier for the joint to modify.
(any)
The user data to associate with the joint.
void:
Retrieves the user data that was previously attached to the specified joint. The function first gets the world object from the joint ID, then retrieves the joint using the full joint ID, and finally returns the userData property of that joint.
(b2JointId)
The identifier for the joint.
void:
The user data associated with the joint.
Wakes up both bodies connected by a joint in the physics simulation.
(b2JointId)
The identifier for the joint whose connected bodies should be awakened.
void:
Returns the constraint force for different joint types including distance, motor, mouse, prismatic, revolute, weld, and wheel joints. The force is retrieved from the corresponding joint-specific force getter function.
(b2JointId)
The identifier for the joint.
b2Vec2:
The constraint force vector. Returns (0,0) for unknown joint types.
Returns the constraint torque for different joint types including motor, mouse, prismatic, revolute, weld and wheel joints. For distance joints, it always returns 0.
(b2JointId)
The ID of the joint to get the constraint torque from.
number:
The constraint torque value. Returns 0 for distance joints or if joint type is invalid.
This file includes code that is:
Computes collision information between two circles transformed by their respective transforms.
(b2Circle)
The first circle
(b2Transform)
Transform for the first circle
(b2Circle)
The second circle
(b2Transform)
Transform for the second circle
(b2Manifold)
The output collision manifold
b2Manifold:
The collision manifold containing contact points, normal, and separation
information. If no collision is detected, returns a cleared manifold.
Computes collision information between a capsule shape and a circle shape.
(b2Capsule)
The capsule shape A with properties center1, center2, and radius
(b2Transform)
Transform for shape A containing position (p) and rotation (q)
(b2Circle)
The circle shape B with properties center and radius
(b2Transform)
Transform for shape B containing position (p) and rotation (q)
(b2Manifold)
Output collision manifold to be populated
b2Manifold:
The populated collision manifold containing contact points,
normal, separation, and other collision data
Computes collision information between a polygon and a circle.
(b2Polygon)
The polygon shape
(b2Transform)
Transform for polygon A
(b2Circle)
The circle shape
(b2Transform)
Transform for circle B
(b2Manifold)
Output collision manifold
b2Manifold:
The collision manifold containing contact points, normal, and separation
Computes the collision manifold between two capsule shapes in 2D space. A capsule is defined by two endpoints and a radius.
(b2Capsule)
The first capsule shape
(b2Transform)
Transform for the first capsule
(b2Capsule)
The second capsule shape
(b2Transform)
Transform for the second capsule
(b2Manifold)
Output collision manifold
void:
Modifies the manifold parameter with collision data:
Converts the segment to a zero-radius capsule and delegates to b2CollideCapsules for the actual collision computation.
(b2Segment)
A line segment defined by two points (point1, point2)
(b2Transform)
Transform for segmentA containing position and rotation
(b2Capsule)
A capsule shape defined by two points and a radius
(b2Transform)
Transform for capsuleB containing position and rotation
b2Manifold:
Collision manifold containing contact points and normal
Computes collision manifold between a polygon and a capsule by converting the capsule to a polygon and using polygon-polygon collision detection.
(b2Polygon)
The first collision shape (polygon)
(b2Transform)
Transform for polygon A, containing position and rotation
(b2Capsule)
The second collision shape (capsule) defined by two centers and a radius
(b2Transform)
Transform for capsule B, containing position and rotation
(b2Manifold)
The output collision manifold to be populated
b2Manifold:
The collision manifold containing contact points and normal
Detects collision between two polygons and generates contact information. Transforms the polygons into a common frame, finds the separating axes, and generates contact points. The manifold includes contact points with anchor positions, separation distance, contact IDs and collision normal.
(b2Polygon)
First polygon
(b2Transform)
Transform for first polygon containing position (p) and rotation (q)
(b2Polygon)
Second polygon
(b2Transform)
Transform for second polygon containing position (p) and rotation (q)
(b2Manifold)
Output manifold to store collision data
b2Manifold:
The collision manifold containing contact points, normal and separation
Computes collision detection between a line segment and a circle by converting the segment to a zero-radius capsule and using capsule-circle collision.
(b2Segment)
The line segment shape
(b2Transform)
Transform for segmentA
(b2Circle)
The circle shape
(b2Transform)
Transform for circleB
(b2Manifold)
The collision manifold to populate
b2Manifold:
The collision manifold containing contact information
Computes collision manifold between a line segment and a polygon by converting the segment into a zero-width capsule and using polygon collision detection.
(b2Segment)
The line segment
(b2Transform)
Transform for segmentA
(b2Polygon)
The polygon to test collision against
(b2Transform)
Transform for polygonB
(b2Manifold)
The manifold to populate with collision data
b2Manifold:
Collision manifold containing contact points and normal
Computes collision detection between a chain segment and a circle.
(Object)
A chain segment with properties segment (containing point1 and point2) and ghost points (ghost1, ghost2)
(Object)
Transform for chain segment containing position (p) and rotation (q)
(Object)
Circle object with center point and radius
(Object)
Transform for circle containing position (p) and rotation (q)
(Object)
Contact manifold to store collision results
Object:
The manifold object containing collision data:
Computes collision between a chain segment and a capsule by converting the capsule to a polygon and delegating to the segment-polygon collision function.
(b2ChainSegment)
The chain segment shape
(b2Transform)
Transform for segmentA
(b2Capsule)
The capsule shape defined by two centers and a radius
(b2Transform)
Transform for capsuleB
(b2SimplexCache)
Simplex cache for persistent contact information
(b2Manifold)
Contact manifold to store collision results
void:
Computes the collision manifold between a chain segment (a segment with rounded corners) and a polygon. The function handles edge cases including convex/concave corners and determines contact points and normals. The manifold is populated with contact points and can contain 0, 1 or 2 contact points depending on the collision configuration.
(b2ChainSegment)
The chain segment shape A
(b2Transform)
Transform for shape A
(b2Polygon)
The polygon shape B
(b2Transform)
Transform for shape B
(b2DistanceCache)
Cache for distance calculations
(b2Manifold)
The contact manifold to populate
b2Manifold:
The populated contact manifold
This file includes code that is:
Calculates the length of a vector and returns its normalized form.
(b2Vec2)
The input vector to normalize
{length: number, normal: b2Vec2}:
An object containing:
This file includes code that is:
This file includes code that is:
(b2Vec2)
: Matrix columns
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
number:
The smaller of the two input numbers
FUNCTIONS
FUNCTIONS
number:
The maximum value between a and b
An implementation of absolute value that returns the positive magnitude of the input number.
(number)
The input number
number:
The absolute value of the input
Returns lower if a < lower, upper if a > upper, otherwise returns a.
number:
The clamped value between lower and upper bounds
A comparison function that returns the minimum value between two integers using a ternary operator.
number:
The smaller of the two input integers
number:
The larger of the two input integers
Computes the absolute value of an integer using conditional logic rather than Math.abs().
(number)
The integer input value.
number:
The absolute value of the input.
Returns lower if a < lower, upper if a > upper, otherwise returns a.
(number)
The integer value to clamp
(number)
The lower bound (inclusive)
(number)
The upper bound (inclusive)
number:
The clamped integer value
Computes the dot product (scalar product) of two 2D vectors using the formula: dot = a.x * b.x + a.y * b.y
number:
The dot product of vectors a and b.
Calculates the cross product between two 2D vectors, which represents the signed area of the parallelogram formed by these vectors.
number:
The cross product (a.x * b.y - a.y * b.x)
Computes the cross product of a vector and scalar, returning a new vector that is perpendicular to the input vector and scaled by the scalar value.
b2Vec2:
A new vector where x = s * v.y and y = -s * v.x
Computes s × v, where × denotes the cross product. The result is a new vector (-s * v.y, s * v.x).
b2Vec2:
A new vector perpendicular to the input vector, scaled by s
Creates a new vector that is perpendicular to the input vector by rotating it 90 degrees counter-clockwise. The new vector is computed by setting the x component to the negative y component of the input, and the y component to the x component of the input.
(b2Vec2)
The input vector to rotate.
b2Vec2:
A new vector perpendicular to the input, rotated 90 degrees counter-clockwise.
Creates a new vector that is perpendicular (rotated 90 degrees clockwise) to the input vector. For a vector (x,y), returns (y,-x).
(b2Vec2)
The input vector to rotate.
b2Vec2:
A new vector perpendicular to the input, rotated 90 degrees clockwise.
Creates a new b2Vec2 where the x and y components are the sums of the corresponding components of the input vectors.
b2Vec2:
A new vector representing the sum of the input vectors (a + b).
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
Creates a new 2D vector by subtracting the components of vector b from vector a. The resulting vector has coordinates (a.x - b.x, a.y - b.y).
b2Vec2:
A new vector representing (a - b).
Creates a new b2Vec2 with the negated x and y components of the input vector.
(b2Vec2)
The input vector to negate.
b2Vec2:
A new vector with components (-a.x, -a.y).
Calculates a point that lies on the straight line between vectors a and b, where t=0 returns a, t=1 returns b, and values in between return proportionally interpolated points.
(b2Vec2)
The starting vector
(b2Vec2)
The ending vector
(number)
The interpolation parameter between 0 and 1
b2Vec2:
A new vector representing the interpolated point
Multiplies the x components of both vectors together and the y components of both vectors together, returning a new b2Vec2 with these products as its components.
(b2Vec2)
First 2D vector with x and y components.
(b2Vec2)
Second 2D vector with x and y components.
b2Vec2:
A new vector where each component is the product of the corresponding components of a and b.
Performs scalar multiplication on a 2D vector, where each component of the vector is multiplied by the scalar value.
b2Vec2:
A new b2Vec2 representing the scaled vector (s * v).
b2Vec2:
A new vector representing the result of a + s * b
(b2Vec2)
The first vector operand
(number)
The scalar multiplier
(b2Vec2)
The second vector operand
b2Vec2:
A new vector representing the result of a - s * b
Returns a new b2Vec2 with the absolute values of the input vector's components.
(b2Vec2)
The input vector whose components will be converted to absolute values.
b2Vec2:
A new vector containing the absolute values of the input vector's x and y components.
b2Vec2:
A new vector with x = min(a.x, b.x) and y = min(a.y, b.y)
Creates a new b2Vec2 where:
b2Vec2:
A new vector where each component is the maximum of the corresponding components from vectors a and b
Creates a new 2D vector where each component (x,y) is clamped between the corresponding components of vectors a and b. Uses b2ClampFloat internally to clamp individual components.
(b2Vec2)
The vector to clamp
(b2Vec2)
The minimum bounds vector
(b2Vec2)
The maximum bounds vector
b2Vec2:
A new vector with components clamped between a and b
Computes the Euclidean length of a 2D vector using the formula sqrt(x² + y²).
(b2Vec2)
A 2D vector with x and y components.
number:
The scalar length of the vector.
Computes the dot product of a vector with itself, which gives the squared length of the vector without performing a square root operation.
(b2Vec2)
A 2D vector with x and y components.
number:
The squared length of the vector (x² + y²).
Computes the straight-line distance between two points using the Pythagorean theorem.
number:
The distance between points a and b
Computes the squared Euclidean distance between two points without taking the square root. The calculation is (b.x - a.x)² + (b.y - a.y)²
number:
The squared distance between points a and b
Constructs a b2Rot object by computing the cosine and sine of the provided angle. The resulting b2Rot contains these values as its 'c' and 's' components respectively.
(number)
The rotation angle in radians
b2Rot:
A new b2Rot object containing the cosine and sine of the input angle
Computes the magnitude of the rotation vector and divides both components by it to create a normalized rotation. If the magnitude is 0, returns a default rotation.
(b2Rot)
A rotation object containing cosine (c) and sine (s) components
b2Rot:
A new normalized b2Rot object where the components form a unit vector
Verifies that the sum of squares of the sine and cosine components equals 1 within a tolerance of ±6e-4, which indicates a valid rotation.
(b2Rot)
A rotation object containing sine (s) and cosine (c) components
boolean:
True if the rotation is normalized within a tolerance of 6e-4
This file includes code that is:
Linearly interpolates between two rotations and normalizes the result. When t=0 returns q12, when t=1 returns q22.
(b2Rot)
The first rotation
(b2Rot)
The second rotation
(number)
Interpolation factor between 0 and 1
b2Rot:
The normalized interpolated rotation
Performs rotation integration while ensuring the resulting rotation remains normalized through magnitude scaling. The function handles the case where magnitude could be zero by returning a default rotation.
b2Rot:
A new normalized rotation after applying the integration.
Calculates the angular velocity by comparing two rotations and dividing by the time step. Uses the formula (θ2 - θ1)/dt where θ is extracted from the rotations using their sine and cosine components.
(b2Rot)
The first rotation
(b2Rot)
The second rotation
(number)
The inverse of the time step (1/dt)
number:
The computed angular velocity in radians per second
Calculates the angle of a rotation by computing the arctangent of the sine component divided by the cosine component using Math.atan2.
(b2Rot)
A rotation object containing cosine (c) and sine (s) components.
number:
The angle in radians, calculated using arctangent of s/c.
Extracts the x-axis direction vector from a rotation matrix by returning a vector containing the cosine component in x and sine component in y.
(b2Rot)
A rotation matrix containing cosine (c) and sine (s) components
b2Vec2:
A 2D vector representing the x-axis direction (c, s)
Extracts the Y axis vector from a rotation matrix by returning the vector (-sin, cos). This represents the vertical basis vector of the rotated coordinate system.
(b2Rot)
A rotation matrix containing cosine (c) and sine (s) components
b2Vec2:
A 2D vector (-sin, cos) representing the Y axis of the rotation
Performs rotation multiplication by combining the cosine and sine components of two b2Rot objects using the formula: result.c = q4.c * r.c - q4.s * r.s result.s = q4.s * r.c + q4.c * r.s
b2Rot:
A new rotation representing the product of the two input rotations
Computes the product of the inverse of rotation q with rotation r. For rotations, the inverse multiplication is equivalent to using the transpose of the rotation matrix.
b2Rot:
A new rotation representing q^-1 * r
Computes the angle between two rotations by using their sine and cosine components. The result is the angle needed to rotate from rotation 'a' to rotation 'b'.
number:
The relative angle in radians between the two rotations
This function takes an angle in radians and ensures it falls within the range [-π, π] by adding or subtracting 2π as needed. If the input angle is already within the valid range, it is returned unchanged.
(number)
The input angle in radians to normalize.
number:
The normalized angle in radians within the range [-π, π].
Applies a 2D rotation to a vector using the formula: x' = cx - sy y' = sx + cy where (x,y) is the input vector and (c,s) represents the rotation
(b2Rot)
A rotation object containing cosine (c) and sine (s) components
(b2Vec2)
The vector to rotate
b2Vec2:
A new vector representing the rotated result
Applies the inverse of the rotation defined by q4 to vector v. The operation is equivalent to multiplying the vector by the transpose of the rotation matrix represented by q4.
(b2Rot)
A rotation matrix containing cosine (c) and sine (s) components
(b2Vec2)
The vector to be inversely rotated
b2Vec2:
A new vector representing the inverse rotation of v by q4
Applies a rigid body transformation to a 2D point. The transformation consists of a rotation followed by a translation. The rotation is applied using the rotation matrix stored in t.q (cosine and sine components), and the translation is applied using the position vector stored in t.p.
(b2Transform)
A transform containing position (p) and rotation (q) components
(b2Vec2)
The point to transform
b2Vec2:
The transformed point
Computes the inverse transform of a point by first translating relative to the transform's position, then applying the inverse rotation. The rotation inverse is computed using the transpose of the rotation matrix.
(b2Transform)
A transform containing position (p) and rotation (q) components
(b2Vec2)
The point to transform
b2Vec2:
The inverse transformed point
Combines two transforms by first multiplying their rotations (q components), then rotating B's position vector by A's rotation and adding it to A's position. The result represents the combined transformation of first applying B, then A.
(b2Transform)
The first transform
(b2Transform)
The second transform
b2Transform:
A new transform C that represents the multiplication of A and B
Calculates A^-1 * B, where A^-1 is the inverse of transform A. The result combines both the rotational and translational components of the transforms using their quaternion and position vectors.
(b2Transform)
The first transform
(b2Transform)
The second transform
b2Transform:
A new transform representing the inverse multiplication of A and B
Performs matrix-vector multiplication of the form Av, where A is a 2x2 matrix and v is a 2D vector. The result is a new 2D vector.
(b2Mat22)
A 2x2 matrix with components cx and cy, each containing x and y values
(b2Vec2)
A 2D vector with x and y components
b2Vec2:
The resulting 2D vector from the matrix-vector multiplication
Computes the inverse of a 2x2 matrix using the formula: For matrix [[a,b],[c,d]], inverse = (1/det) * [[d,-c],[-b,a]] where det = ad-bc
(b2Mat22)
The input 2x2 matrix to invert
b2Mat22:
The inverse of matrix A. If the determinant is 0, returns a matrix with undefined values
Solves the system using the formula: x = (1/det) * [a22 -a12] * [b.x] [-a21 a11] [b.y] where det = a11a22 - a12a21
(b2Mat22)
A 2x2 matrix represented as two column vectors (cx, cy)
(b2Vec2)
A 2D vector representing the right-hand side of the equation
b2Vec2:
The solution vector x that satisfies Ax = b. Returns a zero vector if the system is singular (det = 0)
Tests if AABB 'b' is completely contained within AABB 'a' by comparing their bounds. An AABB contains another if its lower bounds are less than or equal to the other's lower bounds and its upper bounds are greater than or equal to the other's upper bounds.
boolean:
True if AABB 'a' completely contains AABB 'b', false otherwise
Computes the center point of an AABB by averaging its lower and upper bounds in both X and Y dimensions.
(b2AABB)
The AABB object containing lowerBound and upperBound coordinates.
b2Vec2:
A 2D vector representing the center point of the AABB.
Computes the extents of an AABB by calculating half the difference between its upper and lower bounds in both x and y dimensions.
(b2AABB)
The AABB to calculate extents for
b2Vec2:
A vector containing the half-width and half-height of the AABB
Computes the union of two axis-aligned bounding boxes by creating a new AABB with a lower bound at the minimum coordinates and an upper bound at the maximum coordinates of both input boxes.
b2AABB:
A new AABB that encompasses both input boxes
This function performs a validation check on a number by ensuring it is both finite and not NaN (Not a Number).
(number)
The number to validate.
boolean:
True if the number is valid (finite and not NaN), false otherwise.
This function performs a validation check on a number by ensuring it is both finite and not NaN (Not a Number).
(number)
The number to validate.
boolean:
True if the number is valid (finite and not NaN), false otherwise.
Validates a b2Vec2 object by checking if it exists and its components are valid numbers.
(b2Vec2)
The vector to validate, containing x and y components.
boolean:
True if the vector exists and both x and y components are valid numbers.
Validates a b2Vec2 object by checking if it exists and its components are valid numbers.
(b2Vec2)
The vector to validate, containing x and y components.
boolean:
True if the vector exists and both x and y components are valid numbers.
Checks if a b2Rot object is valid by verifying:
(b2Rot)
A rotation object containing sine (s) and cosine (c) components
boolean:
True if the rotation is valid, false otherwise
Checks if a b2Rot object is valid by verifying:
(b2Rot)
A rotation object containing sine (s) and cosine (c) components
boolean:
True if the rotation is valid, false otherwise
Checks if an AABB is valid by verifying:
(b2AABB)
The AABB to validate
boolean:
True if the AABB exists and has valid dimensions and coordinates
Checks if an AABB is valid by verifying:
(b2AABB)
The AABB to validate
boolean:
True if the AABB exists and has valid dimensions and coordinates
Normalizes the input vector by dividing its components by its length. If the vector's length is greater than the epsilon value, the function returns a new vector with the same direction but unit length.
(b2Vec2)
The vector to normalize.
b2Vec2:
Returns a new normalized b2Vec2 if successful.
If the vector length is less than epsilon, returns a zero vector (0,0).
Normalizes the input vector by dividing its components by its length. If the vector's length is greater than the epsilon value, the function returns a new vector with the same direction but unit length.
(b2Vec2)
The vector to normalize.
(b2Vec2 | boolean):
Returns a new normalized b2Vec2 if successful, or false if the input is null.
If the vector length is less than epsilon, returns a zero vector (0,0).
Normalizes a 2D vector and performs length validation.
(b2Vec2)
The vector to normalize.
b2Vec2:
A new normalized vector with unit length.
Normalizes a 2D vector and performs length validation.
(b2Vec2)
The vector to normalize.
b2Vec2:
A new normalized vector with unit length.
Updates the target linear offset of a motor joint. The linear offset represents the desired translation between the two bodies connected by the joint.
(b2JointId)
The identifier for the motor joint to modify.
(b2Vec2)
The desired linear offset in local coordinates.
void:
Gets the linear offset of a motor joint.
(b2JointId)
The identifier of the motor joint.
b2Vec2:
The linear offset vector of the motor joint.
Sets the target angular offset for a motor joint, which defines the desired relative rotation between the connected bodies. The input angle is automatically clamped to the range [-π, π].
(b2JointId)
The identifier for the motor joint to modify.
(number)
The desired angular offset in radians, clamped between -π and π.
void:
(b2JointId)
The identifier of the motor joint.
number:
The angular offset value of the motor joint in radians.
Sets the maximum force that can be applied by a motor joint.
(b2JointId)
The identifier for the motor joint
(number)
The maximum force value to set. Will be clamped to non-negative values.
void:
Gets the maximum force value from a motor joint.
(b2JointId)
The identifier for the motor joint.
number:
The maximum force value of the motor joint.
Sets the maximum torque that can be applied by a motor joint.
(b2JointId)
The identifier for the motor joint.
(number)
The maximum torque value. Will be clamped to non-negative values.
void:
Gets the maximum torque value for a motor joint.
(b2JointId)
The identifier for the motor joint.
number:
The maximum torque value of the motor joint.
Sets the position correction factor for a motor joint, which determines how much position error is corrected each time step. The correction factor is automatically clamped between 0 and 1.
(b2JointId)
The identifier for the motor joint.
(number)
The correction factor value, clamped between 0 and 1.
void:
Gets the correction factor of a motor joint.
(b2JointId)
The identifier for the motor joint.
number:
The correction factor value of the motor joint.
Updates the target position of a mouse joint by cloning the provided target vector. The joint must be of type b2_mouseJoint.
(b2JointId)
The identifier of the mouse joint to modify.
(b2Vec2)
The new target position vector to set.
void:
(b2JointId)
The identifier of the mouse joint.
b2Vec2:
The target point of the mouse joint.
(b2JointId)
The identifier for the mouse joint to modify.
(number)
The spring frequency in Hertz (Hz).
void:
Gets the spring frequency in Hertz from a mouse joint.
(b2JointId)
The identifier for the mouse joint.
number:
The spring frequency in Hertz.
Sets the damping ratio for a mouse joint.
(b2JointId)
The identifier for the mouse joint to modify.
(number)
The damping ratio value to set.
void:
Gets the spring damping ratio of a mouse joint.
(b2JointId)
The identifier of the mouse joint.
number:
The spring damping ratio value of the mouse joint.
Sets the maximum force that can be applied by the mouse joint to maintain its constraint.
(b2JointId)
The identifier for the mouse joint to modify.
(number)
The maximum force value to set for the joint.
void:
Gets the maximum force value from a mouse joint.
(b2JointId)
The identifier for the mouse joint.
number:
The maximum force value of the mouse joint.
This file includes code that is:
Sets the spring state of a prismatic joint. When the spring state changes, the spring impulse is reset to zero. If the state doesn't change, no action is taken.
(b2JointId)
The identifier of the prismatic joint to modify.
(boolean)
Whether to enable (true) or disable (false) the spring.
void:
(b2JointId)
The identifier for the prismatic joint to check.
boolean:
True if the spring mechanism is enabled, false otherwise.
Updates the spring frequency of a prismatic joint. The joint must be of type b2_prismaticJoint.
(b2JointId)
The identifier for the prismatic joint to modify.
(number)
The spring frequency in Hertz.
void:
Gets the spring frequency in Hertz for a prismatic joint.
(b2JointId)
The identifier for the prismatic joint.
number:
The spring frequency in Hertz.
Sets the spring damping ratio for a prismatic joint. The joint must be of type b2_prismaticJoint.
(b2JointId)
The identifier for the prismatic joint.
(number)
The damping ratio for the spring.
void:
Gets the spring damping ratio of a prismatic joint.
(b2JointId)
The identifier for the prismatic joint.
number:
The spring damping ratio value.
Enables or disables the translation limits on a prismatic joint. When the limit is disabled, the joint's limit impulses are reset to zero.
(b2JointId)
The identifier for the prismatic joint
(boolean)
True to enable the translation limit, false to disable it
void:
(b2JointId)
The identifier for the prismatic joint to check.
boolean:
True if the limit is enabled for the joint, false otherwise.
(b2JointId)
The identifier for the prismatic joint.
number:
The lower translation limit of the prismatic joint.
(b2JointId)
The identifier for the prismatic joint.
number:
The upper translation limit of the prismatic joint.
Sets new translation limits for a prismatic joint. The function automatically orders the limits so that the lower value is always less than or equal to the upper value. When the limits change, the joint's impulses are reset to zero.
(b2JointId)
The identifier for the prismatic joint.
(number)
The lower translation limit.
(number)
The upper translation limit.
void:
Enables or disables the motor on a prismatic joint. When the motor is disabled, the motor impulse is reset to zero.
(b2JointId)
The identifier for the prismatic joint
(boolean)
True to enable the motor, false to disable it
void:
(b2JointId)
The identifier for the prismatic joint to check.
boolean:
True if the motor is enabled, false otherwise.
(b2JointId)
The identifier for the prismatic joint to modify.
(number)
The desired motor speed in radians per second.
void:
Gets the motor speed of a prismatic joint.
(b2JointId)
The identifier for the prismatic joint.
number:
The current motor speed of the prismatic joint.
Gets the current motor force of a prismatic joint. The force is calculated by multiplying the joint's motor impulse by the inverse of the world's time step.
(b2JointId)
The ID of the prismatic joint
number:
The current motor force in Newtons
Sets the maximum motor force for a prismatic joint.
(b2JointId)
The identifier for the prismatic joint.
(number)
The maximum force the motor can apply.
void:
Gets the maximum motor force of a prismatic joint.
(b2JointId)
The identifier for the prismatic joint.
number:
The maximum force that can be applied by the joint's motor.
Enables or disables the spring functionality of a revolute joint. When the spring state changes, the spring impulse is reset to zero.
(b2JointId)
The identifier of the revolute joint to modify
(boolean)
True to enable the spring, false to disable it
void:
(b2JointId)
The identifier for the revolute joint to check.
boolean:
True if spring functionality is enabled, false otherwise.
Sets the spring oscillation frequency for a revolute joint. The joint must be of type b2_revoluteJoint.
(b2JointId)
The identifier for the revolute joint to modify.
(number)
The spring frequency in Hertz (Hz).
void:
Gets the spring frequency in Hertz for a revolute joint.
(b2JointId)
The identifier for the revolute joint.
number:
The spring frequency in Hertz.
Sets the damping ratio for a revolute joint's spring.
(b2JointId)
The identifier for the revolute joint.
(number)
The damping ratio for the spring.
void:
Gets the spring damping ratio of a revolute joint.
(b2JointId)
The identifier of the revolute joint.
number:
The spring damping ratio value of the revolute joint.
Calculates the relative angle between two bodies connected by a revolute joint by comparing their transforms and subtracting the joint's reference angle. The result is unwound to ensure consistent angle representation.
(b2JointId)
The identifier for the revolute joint.
number:
The current angle in radians between the two connected bodies,
relative to the reference angle.
When enabled, the joint will restrict rotation to be between its upper and lower angle limits. When the limit state changes, the joint's limit impulses are reset to zero.
(b2JointId)
The identifier for the revolute joint.
(boolean)
True to enable the joint limits, false to disable them.
void:
(b2JointId)
The identifier for the revolute joint to check.
boolean:
True if the joint's limit is enabled, false otherwise.
Gets the lower angle limit of a revolute joint.
(b2JointId)
The identifier for the revolute joint.
number:
The lower angle limit in radians.
Gets the upper angle limit of a revolute joint.
(b2JointId)
The identifier for the revolute joint.
number:
The upper angle limit in radians.
Sets the lower and upper angle limits for a revolute joint. The function automatically orders the limits so that the lower value is always less than or equal to the upper value. When the limits change, the joint impulses are reset to zero.
(b2JointId)
The identifier for the revolute joint to modify
(number)
The lower angle limit in radians
(number)
The upper angle limit in radians
void:
Enables or disables the motor on a revolute joint. When the motor is disabled, its accumulated impulse is reset to zero.
(b2JointId)
The identifier for the revolute joint
(boolean)
True to enable the joint's motor, false to disable it
void:
(b2JointId)
The identifier for the revolute joint to check.
boolean:
True if the motor is enabled, false otherwise.
Sets the angular velocity for the motor of a revolute joint. A positive velocity means the joint will rotate counterclockwise.
(b2JointId)
The identifier for the revolute joint.
(number)
The desired motor speed in radians per second.
void:
Gets the motor speed of a revolute joint.
(b2JointId)
The identifier of the revolute joint.
number:
The current motor speed in radians per second.
Calculates the motor torque by multiplying the motor impulse by the inverse of the time step. The joint must be of type b2_revoluteJoint.
(b2JointId)
The identifier for the revolute joint.
number:
The current motor torque in Newton-meters.
Sets the maximum motor torque for a revolute joint.
(b2JointId)
The identifier for the revolute joint.
(number)
The maximum motor torque value to set.
void:
Gets the maximum motor torque of a revolute joint.
(b2JointId)
The identifier for the revolute joint.
number:
The maximum motor torque value.
Creates a circle shape and attaches it to a body.
(b2BodyId)
The identifier of the body to attach the shape to
(b2ShapeDef)
The shape definition containing properties like friction and density
(b2Circle)
The circle geometry definition
b2ShapeId:
The identifier of the created circle shape
Creates a capsule shape if the distance between centers is greater than b2_linearSlop. If centers are closer than b2_linearSlop, creates a circle shape instead with radius equal to the capsule radius and center at the midpoint between capsule centers.
(b2BodyId)
The body ID to attach the shape to
(b2ShapeDef)
The shape definition parameters
(b2Capsule)
The capsule geometry containing center1, center2 and radius
b2ShapeId:
The ID of the created shape
Creates a polygon shape and attaches it to a body.
(b2BodyId)
The identifier of the body to attach the shape to
(b2ShapeDef)
The shape definition containing common shape properties
(b2Polygon)
The polygon data including vertices and radius
b2ShapeId:
The identifier of the created polygon shape
Creates a segment shape between two points and attaches it to the specified body. The function validates that the segment length is greater than b2_linearSlop before creating the shape.
(b2BodyId)
The ID of the body to attach the shape to
(b2ShapeDef)
The shape definition parameters
(b2Segment)
The segment geometry defined by point1 and point2
b2ShapeId:
The ID of the created segment shape
Removes a shape from the physics world. If the parent body has automatic mass calculation enabled, the body's mass properties are recalculated after the shape is destroyed. The function performs the following operations:
(b2ShapeId)
The identifier of the shape to destroy.
Creates a chain shape composed of connected line segments attached to a body. The chain can be either a closed loop or an open chain.
(b2BodyId)
The ID of the body to attach the chain to
(b2ChainDef)
The chain definition containing:
b2ChainId:
The ID of the created chain shape
Destroys a chain of shapes attached to a body in a Box2D world. The function removes all shapes associated with the chain and frees the chain ID from the world's chain ID pool.
(b2ChainId)
The identifier for the chain to be destroyed, containing world and index information
void:
Retrieves the body ID for a given shape by first accessing the world object, then getting the shape from the world, and finally creating a body ID from the shape's stored body reference.
(b2ShapeId)
The ID of the shape to query.
b2BodyId:
The ID of the body that owns the shape.
Associates arbitrary user data with a shape identified by shapeId. The shape must exist in the world referenced by the shapeId. The function retrieves the shape from the world and updates its userData property.
(b2ShapeId)
The identifier of the shape to modify.
(any)
The user data to associate with the shape.
void:
This function retrieves the user data that was previously attached to a shape by looking up the shape in the world using the provided shape ID.
(b2ShapeId)
The identifier for the shape.
void:
The user data associated with the shape.
Retrieves a shape from the physics world using its ID and returns whether it is configured as a sensor. Sensor shapes detect collisions but do not generate physical responses.
(b2ShapeId)
The identifier for the shape to check.
boolean:
True if the shape is a sensor, false otherwise.
Transforms the test point into the shape's local space and performs point-in-shape testing based on the shape type (capsule, circle, or polygon). Returns false for unrecognized shape types.
(b2ShapeId)
The identifier for the shape to test against
(b2Vec2)
The world space point to test
boolean:
True if the point is inside the shape, false otherwise
Performs a ray cast against a shape in world space, transforming the input/output between local and world coordinates.
(b2ShapeId)
The identifier for the shape to test
(b2Vec2)
The starting point of the ray in world coordinates
(b2Vec2)
The direction and length of the ray in world coordinates
b2CastOutput:
The ray cast results containing:
Sets a new density value for the specified shape. If the new density matches the current density, no changes are made. The function performs validation to ensure the density is a valid non-negative number.
(b2ShapeId)
The identifier of the shape to modify.
(number)
The new density value. Must be non-negative.
void:
Retrieves the density property of a shape by first accessing the world object using the world identifier stored in the shapeId, then accessing the specific shape within that world.
(b2ShapeId)
The identifier for the shape within a Box2D world.
number:
The density value of the specified shape.
Sets a new friction value for the specified shape. The operation will not proceed if the physics world is locked. The friction parameter must be a valid number greater than or equal to zero.
(b2ShapeId)
The identifier for the shape to modify
(number)
The friction coefficient value (must be >= 0)
void:
Retrieves the friction value from a shape object in the Box2D physics world using the provided shape identifier.
(b2ShapeId)
The identifier for the shape in the physics world.
number:
The friction coefficient of the shape.
Sets the restitution (bounciness) value for a shape.
(b2ShapeId)
The identifier for the shape to modify.
(number)
The restitution value to set. Must be non-negative.
void:
Retrieves the restitution (bounciness) value associated with the specified shape from the physics world.
(b2ShapeId)
The identifier for the shape in the physics world.
number:
The restitution coefficient of the shape.
Retrieves the collision filtering data from a shape by first accessing the world object using the world identifier stored in the shapeId, then accessing the shape within that world using the shapeId.
(b2ShapeId)
The identifier for the shape.
b2Filter:
The collision filter data associated with the shape.
Updates the collision filter properties of a shape. If the new filter settings match the existing ones, no changes are made. When the categoryBits change, the shape's broad-phase proxy is destroyed and recreated. The function also wakes connected bodies when the filter changes.
(b2ShapeId)
The identifier for the shape to modify.
(b2Filter)
The new collision filter settings to apply.
void:
Sets the enableSensorEvents property of a shape in the physics world. The shape must exist in a valid world context for the operation to succeed.
(b2ShapeId)
The identifier of the shape to modify.
(boolean)
True to enable sensor events, false to disable them.
void:
This function retrieves a shape from the physics world using its ID and returns the state of its sensor events flag.
(b2ShapeId)
The identifier for the shape to check.
boolean:
True if sensor events are enabled for the shape, false otherwise.
Sets whether a shape should generate contact events during collision detection. The shape must belong to a valid world, otherwise the function returns without effect.
(b2ShapeId)
The identifier for the shape.
(boolean)
True to enable contact events, false to disable.
void:
This function retrieves a shape from the physics world using its ID and checks the enableContactEvents property of that shape.
(b2ShapeId)
The identifier for the shape to check.
boolean:
True if contact events are enabled for the shape, false otherwise.
Enables or disables pre-solve events for a specific shape in the physics simulation. The function first validates the world reference and returns if invalid. If valid, it updates the shape's pre-solve events setting according to the flag parameter.
(b2ShapeId)
The identifier for the shape in the physics world
(boolean)
Boolean value to enable or disable pre-solve events for the shape
void:
This function retrieves a shape from the physics world using its ID and checks the enablePreSolveEvents property of that shape.
(b2ShapeId)
The identifier for the shape to check.
boolean:
True if pre-solve events are enabled for the shape, false otherwise.
Sets whether a shape should generate hit events during collision detection. The shape must belong to a valid world, otherwise the function returns without effect.
(b2ShapeId)
The identifier of the shape to modify.
(boolean)
True to enable hit events, false to disable.
void:
This function retrieves a shape from the physics world using its ID and checks if hit events are enabled for that shape by accessing the enableHitEvents property.
(b2ShapeId)
The identifier for the shape to check.
boolean:
True if hit events are enabled for the shape, false otherwise.
Retrieves a shape from the physics world using the provided shape ID and returns its type classification.
(b2ShapeId)
The ID of the shape to query
b2ShapeType:
The type of the specified shape
Retrieves a circle shape from the physics world using the provided shape identifier.
(b2ShapeId)
A shape identifier containing world and shape reference
b2Circle:
The circle shape object
Retrieves the segment data from a shape in the physics world. The shape must be of type b2_segmentShape.
(b2ShapeId)
A shape identifier containing world and shape reference
b2Segment:
The segment data from the specified shape
Gets the chain segment data from a shape identified by its ID.
Object:
The chain segment data associated with the shape.
Retrieves the capsule shape data from a shape in the physics world using the provided shape ID.
(b2ShapeId)
A shape identifier containing world and shape reference information
b2Capsule:
The capsule shape data associated with the given shape ID
Gets a polygon shape from a shape ID.
(b2ShapeId)
The ID of the shape to retrieve.
b2Polygon:
The polygon shape associated with the given shape ID.
Sets a shape's type to circle and updates its properties. The function updates the shape's proxy in the broad-phase collision system and can wake connected bodies. If the world is locked or invalid, the function returns without making changes.
(b2ShapeId)
The identifier for the shape to be modified
(b2Circle)
The circle shape configuration to set
void:
Sets a shape's type to capsule and updates its configuration. The function resets the shape's proxy in the broad-phase collision system, optionally waking connected bodies and destroying the existing proxy.
(b2ShapeId)
The identifier for the shape to be modified
(b2Capsule)
The capsule shape configuration to set
void:
Sets a shape's type to segment and updates its segment data. After updating, it resets the shape's collision proxy in the physics world. The function requires a valid world lock to execute successfully.
(b2ShapeId)
The identifier for the shape to be modified
(b2Segment)
The segment data to assign to the shape
void:
Sets a shape's type to polygon and assigns polygon data to it. The function updates the shape's proxy in the broad-phase collision system and can wake connected bodies.
(b2ShapeId)
The identifier for the shape to be modified
(b2Polygon)
The polygon data to assign to the shape
void:
Retrieves the parent chain identifier for a given shape if it is a chain segment shape and has an associated chain. The function checks if the shape is of type b2_chainSegmentShape and has a valid chain reference before returning the chain identifier.
(b2ShapeId)
The identifier of the shape to check for parent chain
b2ChainId:
A b2ChainId object. Returns an empty b2ChainId (default values) if the shape
is not a chain segment shape or has no parent chain
Updates the friction property of each shape within the specified chain. The function retrieves the chain shape from the world, then iterates through all shapes in the chain and sets their friction to the specified value.
(b2ChainId)
The identifier for the chain whose friction will be modified
(number)
The friction value to set for all shapes in the chain
void:
Sets the restitution coefficient for all shapes that make up the specified chain. If the world is not found using the provided chainId, the function returns without making changes.
(b2ChainId)
The identifier for the chain whose restitution will be set
(number)
The restitution value to apply to all shapes in the chain
void:
Retrieves the number of contacts associated with the body that owns the specified shape. If the shape is a sensor or the world reference is invalid, the function returns 0.
(b2ShapeId)
The identifier for the shape to check
number:
The number of contacts for the shape's body. Returns 0 if the world is invalid,
or if the shape is a sensor.
Retrieves contact data for a specified shape. For each valid contact involving the shape, stores the shape IDs of both bodies in contact and their contact manifold. Only stores contacts where the touching flag is set and ignores sensor shapes.
(b2ShapeId)
The identifier of the shape to get contact data for
(Array<{shapeIdA: b2ShapeId, shapeIdB: b2ShapeId, manifold: b2Manifold}>)
Array to store the contact data
(number)
Maximum number of contacts to retrieve
number:
The number of contacts found and stored in contactData
Retrieves the Axis-Aligned Bounding Box (AABB) associated with a shape in the physics world. If the world reference is invalid, returns a default AABB with zero dimensions.
(b2ShapeId)
The identifier for the shape.
b2AABB:
The AABB of the shape. Returns an empty AABB if the world is null.
Calculates the closest point on a shape to a given target point, taking into account the shape's position and rotation in world space. Uses the distance calculation algorithm with shape proxies and transforms.
(b2ShapeId)
ID of the shape to query
(b2Vec2)
The target point to find the closest point to
b2Vec2:
The closest point on the shape to the target point. Returns (0,0) if the world is invalid.
Initializes a new b2WorldDef with default values suitable for standard physics simulations. All distance-based values are scaled by b2_lengthUnitsPerMeter2.
b2WorldDef:
A world definition object with the following properties:
Creates a new b2BodyDef with default values.
b2BodyDef:
A body definition object with the following default properties:
Creates and returns a new b2Filter object initialized with default values for collision filtering. The categoryBits determine what collision category this object belongs to, the maskBits determine what categories this object can collide with, and the groupIndex determines collision groups (negative values mean never collide, positive values mean always collide with same group).
b2Filter:
A filter object with categoryBits=1, maskBits=4294967295 (0xFFFFFFFF), and groupIndex=0
This function instantiates a new b2QueryFilter with default collision filtering settings. The categoryBits value of 1 represents the default category, while the maskBits value of 4294967295 allows collision with all categories.
b2QueryFilter:
A query filter object with categoryBits set to 1 and
maskBits set to 4294967295 (0xFFFFFFFF).
This function initializes a new b2ShapeDef object with commonly used physics properties. The shape definition can be used to create various types of physics shapes in Box2D.
b2ShapeDef:
A shape definition object with the following default values:
Initializes a new chain definition with common default values. The chain shape represents a series of connected line segments.
b2ChainDef:
A chain definition object with:
Result from b2World_RayCastClosest
(b2ShapeId)
: The shape that was hit
(b2Vec2)
: The hit point
(b2Vec2)
: The hit normal
(number)
: The hit fraction along the ray
(number)
: Number of tree nodes visited
(number)
: Number of tree leaves visited
(boolean)
: Whether the ray hit anything
TYPES
TYPES
(b2Vec2)
: Gravity vector. Box2D has no up-vector defined.
(number)
: Restitution velocity threshold, usually in m/s. Collisions above this speed have restitution applied (will bounce).
(number)
: This parameter controls how fast overlap is resolved and has units of meters per second
(number)
: Threshold velocity for hit events. Usually meters per second.
(number)
: Contact stiffness. Cycles per second.
(number)
: Contact bounciness. Non-dimensional.
(number)
: Joint stiffness. Cycles per second.
(number)
: Joint bounciness. Non-dimensional.
(number)
: Maximum linear velocity. Usually meters per second.
(b2MixingRule)
: Mixing rule for friction. Default is b2_mixGeometricMean.
(b2MixingRule)
: Mixing rule for restitution. Default is b2_mixMaximum.
(boolean)
: Can bodies go to sleep to improve performance
(boolean)
: Enable continuous collision
(number)
: Number of workers to use with the provided task system.
(Function)
: Function to spawn tasks
(Function)
: Function to finish a task
(any)
: User context that is provided to enqueueTask and finishTask
(any)
: User data
(number)
: Used internally to detect a valid definition. DO NOT SET.
This file includes code that is:
(b2BodyType)
: The body type: static, kinematic, or dynamic
(b2Vec2)
: The initial world position of the body
(b2Rot)
: The initial world rotation of the body
(b2Vec2)
: The initial linear velocity in meters per second
(number)
: The initial angular velocity in radians per second
(number)
: Linear damping to reduce linear velocity
(number)
: Angular damping to reduce angular velocity
(number)
: Scale factor applied to gravity for this body
(number)
: Sleep velocity threshold, default 0.05 m/s
(any)
: Application specific body data
(boolean)
: Whether this body can fall asleep
(boolean)
: Whether body starts awake or sleeping
(boolean)
: Whether to prevent rotation
(boolean)
: Whether to use continuous collision detection
(boolean)
: Whether body can move and collide
(boolean)
: Whether to bypass rotation speed limits
(number)
: Internal validation flag
(any)
: Use this to store application specific shape data
(number)
: The Coulomb (dry) friction coefficient, usually in the range [0,1]
(number)
: The restitution (bounce) usually in the range [0,1]
(number)
: The density, usually in kg/m^2
(b2Filter)
: Collision filtering data
(number)
: Custom debug draw color
(boolean)
: A sensor shape generates overlap events but never generates a collision response
(boolean)
: Enable sensor events for this shape. Only applies to kinematic and dynamic bodies
(boolean)
: Enable contact events for this shape. Only applies to kinematic and dynamic bodies
(boolean)
: Enable hit events for this shape. Only applies to kinematic and dynamic bodies
(boolean)
: Enable pre-solve contact events for this shape. Only applies to dynamic bodies
(boolean)
: Override static body behavior to force contact creation
(boolean)
: Should the body update mass properties when shape is created
(number)
: Used internally to detect a valid definition. DO NOT SET
(void)
: Use this to store application specific shape data
(number)
: The point count, must be 4 or more
(number)
: The friction coefficient, usually in the range [0,1]
(number)
: The restitution (elasticity) usually in the range [0,1]
(b2Filter)
: Contact filtering data
(number)
: Custom debug draw color
(boolean)
: Indicates a closed chain formed by connecting first and last points
(number)
: Used internally to detect valid definition. DO NOT SET
This requires defining an anchor point on both bodies and the non-zero distance of the distance joint. The definition uses local anchor points so that the initial configuration can violate the constraint slightly. This helps when saving and loading a game.
(b2BodyId)
: The first attached body
(b2BodyId)
: The second attached body
(b2Vec2)
: The local anchor point relative to bodyA's origin
(b2Vec2)
: The local anchor point relative to bodyB's origin
(number)
: The rest length of this joint. Clamped to a stable minimum value.
(boolean)
: Enable the distance constraint to behave like a spring. If false then the distance joint will be rigid, overriding the limit and motor.
(number)
: The spring linear stiffness Hertz, cycles per second
(number)
: The spring linear damping ratio, non-dimensional
(boolean)
: Enable/disable the joint limit
(number)
: Minimum length. Clamped to a stable minimum value.
(number)
: Maximum length. Must be greater than or equal to the minimum length.
(boolean)
: Enable/disable the joint motor
(number)
: The maximum motor force, usually in newtons
(number)
: The desired motor speed, usually in meters per second
(boolean)
: Set this flag to true if the attached bodies should collide
(any)
: User data pointer
(number)
: Used internally to detect a valid definition. DO NOT SET.
(b2BodyId)
: The first attached body
(b2BodyId)
: The second attached body
(b2Vec2)
: Position of bodyB minus the position of bodyA, in bodyA's frame
(number)
: The bodyB angle minus bodyA angle in radians
(number)
: The maximum motor force in newtons
(number)
: The maximum motor torque in newton-meters
(number)
: Position correction factor in the range [0,1]
(boolean)
: Set this flag to true if the attached bodies should collide
(any)
: User data pointer
(number)
: Used internally to detect a valid definition. DO NOT SET.
(b2BodyId)
: The first attached body
(b2BodyId)
: The second attached body
(b2Vec2)
: The initial target point in world space
(number)
: Stiffness in hertz
(number)
: Damping ratio, non-dimensional
(number)
: Maximum force, typically in newtons
(boolean)
: Set this flag to true if the attached bodies should collide
(any)
: User data pointer
(number)
: Used internally to detect a valid definition. DO NOT SET.
(b2BodyId)
: The first attached body
(b2BodyId)
: The second attached body
(b2Vec2)
: The local anchor point relative to bodyA's origin
(b2Vec2)
: The local anchor point relative to bodyB's origin
(b2Vec2)
: The local translation unit axis in bodyA
(number)
: The constrained angle between the bodies: bodyB_angle - bodyA_angle
(boolean)
: Enable a linear spring along the prismatic joint axis
(number)
: The spring stiffness Hertz, cycles per second
(number)
: The spring damping ratio, non-dimensional
(boolean)
: Enable/disable the joint limit
(number)
: The lower translation limit
(number)
: The upper translation limit
(boolean)
: Enable/disable the joint motor
(number)
: The maximum motor force, typically in newtons
(number)
: The desired motor speed, typically in meters per second
(boolean)
: Set this flag to true if the attached bodies should collide
(any)
: User data pointer
(number)
: Used internally to detect a valid definition. DO NOT SET.
(b2BodyId)
: The first attached body
(b2BodyId)
: The second attached body
(b2Vec2)
: The local anchor point relative to bodyA's origin
(b2Vec2)
: The local anchor point relative to bodyB's origin
(number)
: The bodyB angle minus bodyA angle in the reference state (radians)
(boolean)
: Enable a rotational spring on the revolute hinge axis
(number)
: The spring stiffness Hertz, cycles per second
(number)
: The spring damping ratio, non-dimensional
(boolean)
: A flag to enable joint limits
(number)
: The lower angle for the joint limit in radians
(number)
: The upper angle for the joint limit in radians
(boolean)
: A flag to enable the joint motor
(number)
: The maximum motor torque, typically in newton-meters
(number)
: The desired motor speed in radians per second
(number)
: Scale the debug draw
(boolean)
: Set this flag to true if the attached bodies should collide
(any)
: User data pointer
(number)
: Used internally to detect a valid definition. DO NOT SET.
(b2BodyId)
: The first attached body
(b2BodyId)
: The second attached body
(b2Vec2)
: The local anchor point relative to bodyA's origin
(b2Vec2)
: The local anchor point relative to bodyB's origin
(number)
: The bodyB angle minus bodyA angle in the reference state (radians)
(number)
: Linear stiffness expressed as Hertz (cycles per second). Use zero for maximum stiffness.
(number)
: Angular stiffness as Hertz (cycles per second). Use zero for maximum stiffness.
(number)
: Linear damping ratio, non-dimensional. Use 1 for critical damping.
(number)
: Linear damping ratio, non-dimensional. Use 1 for critical damping.
(boolean)
: Set this flag to true if the attached bodies should collide
(any)
: User data pointer
(number)
: Used internally to detect a valid definition. DO NOT SET.
(b2BodyId)
: The first attached body
(b2BodyId)
: The second attached body
(b2Vec2)
: The local anchor point relative to bodyA's origin
(b2Vec2)
: The local anchor point relative to bodyB's origin
(b2Vec2)
: The local translation unit axis in bodyA
(boolean)
: Enable a linear spring along the local axis
(number)
: Spring stiffness in Hertz
(number)
: Spring damping ratio, non-dimensional
(boolean)
: Enable/disable the joint linear limit
(number)
: The lower translation limit
(number)
: The upper translation limit
(boolean)
: Enable/disable the joint rotational motor
(number)
: The maximum motor torque, typically in newton-meters
(number)
: The desired motor speed in radians per second
(boolean)
: Set this flag to true if the attached bodies should collide
(any)
: User data pointer
(number)
: Used internally to detect a valid definition. DO NOT SET.
(Array<b2SensorBeginTouchEvent>)
: Array of sensor begin touch events
(Array<b2SensorEndTouchEvent>)
: Array of sensor end touch events
(number)
: The number of begin touch events
(number)
: The number of end touch events
(b2ShapeId)
: Id of the first shape
(b2ShapeId)
: Id of the second shape
(b2Manifold)
: The initial contact manifold
(b2ShapeId)
: Id of the first shape
(b2ShapeId)
: Id of the second shape
(b2Vec2)
: Point where the shapes hit
(b2Vec2)
: Normal vector pointing from shape A to shape B
(number)
: The speed the shapes are approaching. Always positive. Typically in meters per second.
(Array<b2ContactBeginTouchEvent>)
: Array of begin touch events
(Array<b2ContactEndTouchEvent>)
: Array of end touch events
(Array<b2ContactHitEvent>)
: Array of hit events
(number)
: Number of begin touch events
(number)
: Number of end touch events
(number)
: Number of hit events
(b2Transform)
: The new transform of the moved body
(b2BodyId)
: The identifier of the moved body
(void)
: User data associated with the body
(boolean)
: Indicates if the body transitioned to sleep state
(Array<b2BodyMoveEvent>)
: Array of move events
(number)
: Number of move events
(b2ShapeId)
: The identifier for the first shape
(b2ShapeId)
: The identifier for the second shape
(b2Manifold)
: The contact manifold between the shapes
(b2AABB)
: Bounds to use if restricting drawing to a rectangular region
(boolean)
: Option to restrict drawing to a rectangular region. May suffer from unstable depth sorting
(boolean)
: Option to draw shapes
(boolean)
: Option to draw joints
(boolean)
: Option to draw additional information for joints
(boolean)
: Option to draw the bounding boxes for shapes
(boolean)
: Option to draw the mass and center of mass of dynamic bodies
(boolean)
: Option to draw contact points
(boolean)
: Option to visualize the graph coloring used for contacts and joints
(boolean)
: Option to draw contact normals
(boolean)
: Option to draw contact normal impulses
(boolean)
: Option to draw contact friction impulses
(any)
: User context that is passed as an argument to drawing callback functions
(number)
: The collision category bits. Normally you would just set one bit.
The category bits should represent your application object types.
(number)
: The collision mask bits. States the categories that this shape would
accept for collision.
(number)
: Collision groups allow a certain group of objects to never collide
(negative) or always collide (positive). Zero has no effect. Non-zero group filtering always wins
against the mask bits.
Sets the linear frequency (hertz) for a weld joint.
(b2JointId)
The identifier for the weld joint to modify
(number)
The frequency in hertz (must be >= 0)
void:
Gets the linear Hertz value from a weld joint.
(b2JointId)
The identifier for the weld joint.
number:
The linear Hertz value of the weld joint.
Sets the linear damping ratio for a weld joint.
(b2JointId)
The identifier for the weld joint to modify.
(number)
The damping ratio value. Must be non-negative.
void:
Gets the linear damping ratio of a weld joint.
(b2JointId)
The identifier for the weld joint.
number:
The linear damping ratio of the weld joint.
Sets the angular frequency (hertz) for a weld joint's angular spring-damper.
(b2JointId)
The identifier for the weld joint to modify.
(number)
The angular frequency in Hertz (must be >= 0).
void:
Gets the angular frequency (hertz) of a weld joint.
(b2JointId)
The identifier for the weld joint.
number:
The angular frequency in hertz.
Sets the angular damping ratio for a weld joint.
(b2JointId)
The identifier for the weld joint to modify.
(number)
The angular damping ratio. Must be non-negative.
void:
Gets the angular damping ratio of a weld joint.
(b2JointId)
The identifier of the weld joint.
number:
The angular damping ratio of the weld joint.
Enables or disables the spring functionality of a wheel joint. When the spring state changes, the spring impulse is reset to zero.
(b2JointId)
The identifier for the wheel joint to modify
(boolean)
True to enable the spring, false to disable it
void:
(b2JointId)
The identifier for the wheel joint to check.
boolean:
True if the spring is enabled, false otherwise.
Sets the spring frequency for a wheel joint's oscillation. The frequency is specified in Hertz (Hz). The joint must be of type b2_wheelJoint.
(b2JointId)
The identifier for the wheel joint to modify.
(number)
The spring frequency in Hertz (Hz).
void:
Gets the spring frequency in Hertz for a wheel joint.
(b2JointId)
The identifier for the wheel joint.
number:
The spring frequency in Hertz.
Sets the damping ratio for a wheel joint's spring.
(b2JointId)
The identifier for the wheel joint to modify
(number)
The damping ratio for the spring (0 = no damping, 1 = critical damping)
void:
Gets the damping ratio of a wheel joint's spring.
(b2JointId)
The identifier for the wheel joint.
number:
The spring damping ratio value.
Sets whether the wheel joint's translation limit is active. When the limit is enabled, the joint's translation will be constrained. When the limit state changes, the joint's lower and upper impulses are reset to zero.
(b2JointId)
The identifier for the wheel joint.
(boolean)
True to enable the translation limit, false to disable it.
void:
(b2JointId)
The identifier for the wheel joint to check.
boolean:
True if the limit is enabled, false otherwise.
Gets the lower translation limit of a wheel joint.
(b2JointId)
The identifier for the wheel joint.
number:
The lower translation limit of the wheel joint.
Gets the upper translation limit of a wheel joint.
(b2JointId)
The identifier for the wheel joint.
number:
The upper translation limit of the wheel joint.
Sets new translation limits for a wheel joint. The function automatically orders the limits so that the lower value is always less than or equal to the upper value. When the limits change, the joint's impulses are reset to zero.
(b2JointId)
The identifier for the wheel joint.
(number)
The lower translation limit.
(number)
The upper translation limit.
void:
Enables or disables the motor on a wheel joint. When the motor state changes, the motor impulse is reset to zero.
(b2JointId)
The identifier for the wheel joint
(boolean)
True to enable the motor, false to disable it
void:
(b2JointId)
The identifier for the wheel joint to check.
boolean:
True if the motor is enabled, false otherwise.
(b2JointId)
The identifier for the wheel joint to modify.
(number)
The desired motor speed in radians per second.
void:
Gets the motor speed of a wheel joint.
(b2JointId)
The identifier for the wheel joint.
number:
The current motor speed of the wheel joint in radians per second.
Calculates the motor torque by multiplying the motor impulse by the inverse of the time step. The joint must be of type b2_wheelJoint.
(b2JointId)
The identifier for the wheel joint.
number:
The current motor torque normalized by the step time (Nâ‹…m).
Sets the maximum torque that can be applied by the wheel joint's motor. The joint must be of type b2_wheelJoint.
(b2JointId)
The identifier for the wheel joint.
(number)
The maximum motor torque value to set.
void:
Gets the maximum motor torque of a wheel joint.
(b2JointId)
The identifier for the wheel joint.
number:
The maximum motor torque value.
Initializes a global array of Box2D world instances if it hasn't been created yet. Creates B2_MAX_WORLDS number of world instances and marks them as not in use. If the array already exists, the function returns without doing anything.
void:
Creates and initializes a new Box2D physics world with the specified parameters. The function allocates memory for physics entities (bodies, joints, contacts), initializes contact registers, creates necessary pools and arrays, and sets up the world properties according to the provided definition.
(b2WorldDef)
World definition object containing initialization parameters including:
gravity, hitEventThreshold, restitutionThreshold, maximumLinearVelocity,
contactPushoutVelocity, contactHertz, contactDampingRatio, jointHertz,
jointDampingRatio, enableSleep, enableContinuous
b2WorldId:
A world identifier object containing:
Destroys a Box2D world instance and all its associated resources, including debug sets, task contexts, event arrays, chains, bodies, shapes, contacts, joints, islands, solver sets, constraint graph, broad phase, ID pools, and stack allocator. Creates a new empty world instance with an incremented revision number.
(b2WorldId)
The ID of the world to destroy
void:
Performs one step of physics simulation by updating broad phase pairs, handling collisions, and solving the physics constraints. The function manages contact events, sensor events, and body movement events during the simulation step. It also handles warm starting and enforces velocity limits based on world settings.
(b2WorldId)
The identifier of the physics world to step
(number)
The time increment to advance the simulation (in seconds)
(number)
The number of sub-steps to use for the iteration
void:
Renders debug visualization of a Box2D world, including shapes, joints, AABBs, mass centers, and contact points based on the debug draw flags.
(b2WorldId)
ID of the Box2D world to render
(b2DebugDraw)
Debug drawing context with rendering flags and methods
void:
Retrieves the body movement events from a Box2D world. Returns an empty events object if the world is locked. The function copies the world's body move event array and count into a new b2BodyEvents object.
(b2WorldId)
The identifier for the Box2D world instance
b2BodyEvents:
An object containing an array of body move events and their count
Retrieves the sensor events from a Box2D world. The function returns both begin and end sensor events that occurred during the simulation step. If the world is locked, it returns an empty events object.
(b2WorldId)
The identifier of the Box2D world
b2SensorEvents:
An object containing arrays of sensor begin and end events
Returns a b2ContactEvents object containing three arrays: contactBeginArray, contactEndArray, and contactHitArray, representing different types of contact events that occurred in the physics simulation. The object also includes count values for each type of event.
(b2WorldId)
The identifier of the Box2D world.
b2ContactEvents:
An object containing arrays of begin, end, and hit contact events,
along with their respective counts.
Checks if a world ID is valid by verifying:
(b2WorldId)
The world identifier to validate, containing index1 and revision properties
boolean:
True if the world ID is valid and matches the stored world revision, false otherwise
Performs validation checks on a body ID including:
(b2BodyId)
The body ID to validate
boolean:
True if the ID is valid and references an existing body, false otherwise
Checks if a shape ID is valid by verifying:
(b2ShapeId)
The shape ID to validate, containing world0, index1, and revision properties
boolean:
True if the shape ID is valid and references an existing shape, false otherwise
Checks if a chain ID is valid by verifying:
(b2ChainId)
The chain identifier containing world0 (world index),
index1 (chain index), and revision properties
boolean:
Returns true if the chain ID is valid and matches the current revision,
false otherwise
Checks if a joint ID is valid by verifying:
(b2JointId)
The joint ID to validate, containing world0 (world index),
index1 (joint index), and revision properties
boolean:
True if the joint ID is valid and references an existing joint,
false otherwise
Enables or disables the sleep management system for the specified Box2D world. When sleep is disabled, all sleeping bodies are awakened. The function has no effect if the world is locked or if the requested sleep state matches the current state.
(b2WorldId)
The identifier of the Box2D world.
(boolean)
When true, enables sleep management. When false, wakes all sleeping bodies.
void:
Enables or disables warm starting for the specified Box2D world. Warm starting cannot be modified while the world is locked. If the world is locked when this function is called, the function will return without making any changes.
(b2WorldId)
The identifier for the Box2D world instance
(boolean)
Boolean value to enable or disable warm starting
void:
Sets the continuous collision detection state for the specified Box2D world. The function will not execute if the world is currently locked.
(b2WorldId)
The identifier of the Box2D world.
(boolean)
True to enable continuous collision detection, false to disable it.
void:
Sets the restitution threshold for collision response in the specified Box2D world. The value is clamped between 0 and Number.MAX_VALUE. The function will not execute if the world is locked.
(b2WorldId)
The identifier for the Box2D world.
(number)
The restitution threshold value to set.
void:
Sets the hit event threshold for a Box2D world. The value is clamped between 0 and Number.MAX_VALUE. The function will not execute if the world is locked.
(b2WorldId)
The identifier for the Box2D world instance
(number)
The new hit event threshold value to set
void:
Sets three contact-related parameters for physics simulation: the constraint frequency (hertz), damping ratio, and push-out velocity. All input parameters are clamped between 0 and MAX_VALUE. The function will not execute if the world is locked.
(b2WorldId)
The identifier for the Box2D world.
(number)
The frequency for contact constraint solving.
(number)
The damping ratio for contact constraint solving.
(number)
The velocity used for contact separation.
void:
Performs a broadphase query using the world's dynamic tree to find all fixtures that overlap with the given AABB. For each overlapping fixture that passes the filter, the callback function is invoked.
(b2WorldId)
The ID of the physics world to query
(b2AABB)
The axis-aligned bounding box defining the query region
(b2QueryFilter)
Filter settings to control which fixtures are included
(b2OverlapResultFcn)
Callback function that receives each overlapping fixture
(any)
User context data passed to the callback function
Performs broad-phase AABB queries to find potential overlaps between the given circle and all shapes in the world that match the filter criteria. For each potential overlap, the callback function is invoked with the overlap details.
(b2WorldId)
The ID of the physics world
(b2Circle)
The circle shape to test for overlaps
(b2Transform)
The position and rotation transform of the circle
(b2QueryFilter)
Filtering options for the overlap test
(function)
Callback function that handles overlap results
(any)
User context data passed to the callback function
Tests a capsule shape against all shapes in the world that pass the filter criteria. For each potential overlap, calls the provided callback function. Uses a broad phase tree structure to efficiently find potential overlaps.
(b2WorldId)
The ID of the physics world
(b2Capsule)
The capsule shape to test for overlaps
(b2Transform)
The position and rotation of the capsule
(b2QueryFilter)
Filtering options for the query
(b2OverlapResultFcn)
Callback function that handles overlap results
(any)
User context data passed to the callback function
Performs overlap queries for a polygon shape against all shapes in the physics world that match the provided filter criteria.
(b2WorldId)
The identifier for the physics world
(b2Polygon)
The polygon shape to test for overlaps
(b2Transform)
The position and rotation of the polygon
(b2QueryFilter)
Filtering criteria for the overlap test
(b2OverlapResultFcn)
Callback function to handle overlap results
(void)
User data passed to the callback function
Performs a ray cast operation in the physics world to detect intersections between a ray and physics bodies.
(b2WorldId)
The ID of the physics world
(b2Vec2)
The starting point of the ray
(b2Vec2)
The direction and length of the ray
(b2QueryFilter)
Filtering options for the ray cast
(b2CastResultFcn)
Callback function to handle ray cast results
(void)
User context data passed to the callback
b2TreeStats:
Casts a ray through the physics world and returns information about the closest intersection. The ray is defined by an origin point and a translation vector. The operation checks all body types in the broad phase using a dynamic tree structure.
(b2WorldId)
The identifier for the physics world
(b2Vec2)
The starting point of the ray
(b2Vec2)
The direction and length of the ray
(b2QueryFilter)
Filter settings for the ray cast
b2RayResult:
Information about the closest intersection found
Casts a circle shape through the physics world from its initial position along a translation vector, detecting collisions with other shapes. The cast is performed against all body types in the broad phase, stopping if a collision occurs at fraction 0.
(b2WorldId)
The identifier for the physics world
(b2Circle)
The circle shape to cast
(b2Transform)
The initial transform of the circle
(b2Vec2)
The displacement vector for the cast
(b2QueryFilter)
Filtering options for the cast
(b2CastResultFcn)
Callback function to handle cast results
(void)
User data passed to the callback function
Performs a shape cast of a capsule through the physics world, detecting collisions along the specified translation path.
(b2WorldId)
The identifier for the physics world
(b2Capsule)
The capsule shape to cast
(b2Transform)
The initial transform of the capsule, containing position (p) and rotation (q)
(b2Vec2)
The translation vector defining the cast path
(b2QueryFilter)
Filter settings for the cast operation
(b2CastResultFcn)
Callback function to handle cast results
(void)
User context data passed to the callback function
Performs a shape cast of a polygon through the physics world, detecting collisions along the way.
(b2WorldId)
ID of the physics world
(b2Polygon)
The polygon shape to cast
(b2Transform)
Initial transform of the polygon, containing position and rotation
(b2Vec2)
The displacement vector to cast the polygon along
(b2QueryFilter)
Filter to determine which fixtures to check against
(b2CastResultFcn)
Callback function to handle cast results
(any)
User context data passed to the callback function
Sets a callback function that is invoked before the physics solver runs. The callback receives the provided context pointer when executed.
(b2WorldId)
The identifier for the Box2D world instance
(b2PreSolveFcn)
The pre-solve callback function to be executed
(void)
User data pointer passed to the callback function
void:
Sets a custom filter callback function for a Box2D world instance. The callback can be used to implement custom collision filtering logic. The context parameter allows passing additional data to the callback function.
(b2WorldId)
The identifier for the Box2D world instance.
(b2CustomFilterFcn)
The custom filter callback function.
(void)
A pointer to user-defined context data.
void:
Updates the gravity vector of the specified Box2D world. The gravity vector defines the global acceleration applied to all dynamic bodies in the world.
(b2WorldId)
The identifier for the Box2D world instance.
(b2Vec2)
The gravity vector to apply to the world. Defaults to (0,0).
void:
Retrieves the current gravity vector from the specified Box2D world instance. The gravity vector represents the global gravity force applied to all dynamic bodies in the world.
(b2WorldId)
The identifier for the Box2D world instance.
b2Vec2:
The gravity vector of the world. A 2D vector with x and y components.
Creates a circular explosion centered at the given position that applies radial forces to dynamic bodies within the explosion radius. The explosion force decreases with distance from the center point.
(b2WorldId)
The ID of the Box2D world
(b2Vec2)
The center point of the explosion
(number)
The radius of the explosion effect
(number)
The force magnitude of the explosion
void:
This function returns performance profiling data for a Box2D world. Not supported in Phaser Box2D JS implementation.
(b2WorldId)
The identifier of the Box2D world.
b2Profile:
A profile object containing performance metrics.
This function is not supported in the Phaser Box2D JS implementation and will generate a console warning when called.
(b2WorldId)
The ID of the Box2D world instance.
b2Counters:
An object containing various Box2D performance counters.
This function is a stub that displays a warning message indicating that memory statistics dumping is not supported in the Phaser Box2D JavaScript implementation.
(b2WorldId)
The identifier of the Box2D world
void:
This function is a stub that displays a warning message indicating that memory statistics dumping is not supported in the Phaser Box2D JavaScript implementation.
(b2WorldId)
The identifier of the Box2D world
void:
This file includes code that is:
(any
= 0)
(any
= 0)
(any
= 0)
This file includes code that is:
(b2Vec2)
: The closest point on the first segment
(b2Vec2)
: The closest point on the second segment
(number)
: The barycentric coordinate on the first segment
(number)
: The barycentric coordinate on the second segment
(number)
: The squared distance between the closest points
(b2DistanceProxy)
: The proxy for shape A
(b2DistanceProxy)
: The proxy for shape B
(b2Transform)
: The world transform for shape A
(b2Transform)
: The world transform for shape B
(boolean)
: Should the proxy radius be considered?
(b2SimplexVertex)
: Simplex vertex
(b2SimplexVertex)
: Simplex vertex
(b2SimplexVertex)
: Simplex vertex
(number)
: Number of valid vertices
(b2DistanceProxy)
: The proxy for shape A
(b2DistanceProxy)
: The proxy for shape B
(b2Transform)
: The world transform for shape A
(b2Transform)
: The world transform for shape B
(b2Vec2)
: The translation of shape B
(number)
: The fraction of the translation to consider, typically 1
(b2DistanceProxy)
: The proxy for shape A
(b2DistanceProxy)
: The proxy for shape B
(b2Sweep)
: The movement of shape A
(b2Sweep)
: The movement of shape B
(number)
: Defines the sweep interval [0, tMax]
(b2TOIState)
: The type of result
(number)
: The time of the collision
(b2Vec2)
: Location of the contact point in world space. Subject to precision loss at large coordinates. Should only be used for debugging.
(b2Vec2)
: Location of the contact point relative to bodyA's origin in world space. When used internally to the Box2D solver, this is relative to the center of mass.
(b2Vec2)
: Location of the contact point relative to bodyB's origin in world space. When used internally to the Box2D solver, this is relative to the center of mass.
(number)
: The separation of the contact point, negative if penetrating
(number)
: The impulse along the manifold normal vector
(number)
: The friction impulse
(number)
: The maximum normal impulse applied during sub-stepping
(number)
: Relative normal velocity pre-solve. Used for hit events. If the normal impulse is zero then there was no hit. Negative means shapes are approaching.
(number)
: Uniquely identifies a contact point between two shapes
(boolean)
: Did this contact point exist the previous step?
(Array<b2ManifoldPoint>)
: The manifold points, up to two are possible in 2D
(b2Vec2)
: The unit normal vector in world space, points from shape A to bodyB
(number)
: The number of contacts points, will be 0, 1, or 2
(b2AABB)
: The node bounding box
(number)
: Category bits for collision filtering
(number)
: The node parent index (allocated node)
(number)
: The node freelist next index (free node)
(number)
: Child 1 index (internal node)
(number)
: Child 2 index (internal node)
(number)
: User data (leaf node)
(number)
: Node height
(number)
: Node flags
This file includes code that is:
(any
= 0)
(any
= 0)
(any
= 0)
(any
= 0)
Tests if a contact ID represents a null/invalid contact by checking if its index1 property equals 0. In Box2D, an index1 value of 0 indicates a null contact ID.
(Object)
A contact ID object containing index1 property
boolean:
Returns true if the contact ID is null (index1 === 0), false otherwise
Tests whether a contact ID represents a valid contact by checking if its index1 property is not equal to 0. A zero value for index1 indicates a null contact ID.
(Object)
A contact ID object containing an index1 property.
boolean:
Returns true if the contact ID is non-null (index1 !== 0), false otherwise.
Performs a strict equality comparison between corresponding properties of two ID objects. Checks equality of index1, world0, and revision properties.
(Object)
First ID object containing index1, world0, and revision properties.
(Object)
Second ID object containing index1, world0, and revision properties.
boolean:
True if all corresponding properties between id1 and id2 are equal, false otherwise.
This file includes code that is:
This file includes code that is:
This file includes code that is:
(any)
(any
= null)
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
(any)
(any)
The broad-phase is used for computing pairs and performing volume queries and ray casts. This broad-phase does not persist pairs. Instead, this reports potentially new pairs. It is up to the client to consume the new pairs and to track subsequent overlap.
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
IMAGE HELPERS
(any)
UI HELPERS
(any)
(any)
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
(any)
Get proxy user data
number:
The proxy user data or 0 if the id is invalid
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
This file includes code that is:
Type: number
This file includes code that is:
This file includes code that is:
Creates a box-shaped polygon and attaches it to a body based on the dimensions, position and rotation of the given Sprite.
(number)
The World ID.
(Sprite)
The Sprite object to read the data from.
(BoxPolygonConfig)
Additional configuration for the box polygon.
{bodyId: b2BodyId, shapeId: b2ShapeId, object: b2Polygon}:
The created box's body ID, shape ID, and object.
Creates a circle-shaped polygon and attaches it to a body based on the dimensions, position and rotation of the given Sprite.
(number)
The World ID.
(Sprite)
The Sprite object to read the data from.
(CircleConfig)
Additional configuration for the circle.
{bodyId: b2BodyId, shapeId: b2ShapeId, object: b2Circle}:
The created box's body ID, shape ID, and object.
Creates a world and returns the ID.
(WorldConfig)
Configuration for the world.
{worldId: b2WorldId}:
The created world's ID.
Creates a chain of capsules with each one linked to the previous and next one.
(ChainConfig)
Configuration for the chain.
Array<BodyCapsule>:
A list of each link's body ID, shape ID, and object.
Creates a circle shape and attaches it to a body.
(CircleConfig)
Configuration for the circle.
{bodyId: b2BodyId, shapeId: b2ShapeId, object: b2Circle}:
The created circle's body ID, shape ID, and object.
Creates a capsule shape and attaches it to a body.
(CapsuleConfig)
Configuration for the capsule.
BodyCapsule:
The created capsule's body ID, shape ID, and object.
Creates a box-shaped polygon and attaches it to a body.
(BoxPolygonConfig)
Configuration for the box polygon.
{bodyId: b2BodyId, shapeId: b2ShapeId, object: b2Polygon}:
The created box's body ID, shape ID, and object.
Creates a regular n-gon polygon and attaches it to a body.
(NGonPolygonConfig)
Configuration for the n-gon polygon.
{bodyId: b2BodyId, shapeId: b2ShapeId, object: b2Polygon}:
The created n-gon's body ID, shape ID, and object.
Creates a polygon and attaches it to a body.
(PolygonConfig)
Configuration for the polygon.
{bodyId: b2BodyId, shapeId: b2ShapeId, object: b2Polygon}:
The created polygon's body ID, shape ID, and object.
Creates a polygon from Earcut CDT data and attaches it to a body.
(PolygonVertexConfig)
Configuration for the polygon.
{bodyId: b2BodyId, shapeId: b2ShapeId, object: b2Polygon}:
The created polygon's body ID, shape ID, and object.
Creates a polygon from Vertex and Index data and attaches it to a body.
(PolygonVertexConfig)
Configuration for the polygon.
{bodyId: b2BodyId, shapeId: b2ShapeId, object: b2Polygon}:
The created polygon's body ID, shape ID, and object.
Creates a polygon from PhysicsEditor XML data and attaches it to a body. It is recommended to prepare data with this before the game loop starts; It is async and quite slow.
(PolygonVertexConfig)
Configuration for the polygon.
Promise<{bodyId: b2BodyId, shapeId: b2ShapeId, object: b2Polygon}>:
The created polygon's body ID, shape ID, and object.
Creates a revolute joint between two bodies.
(RevoluteJointConfig)
Configuration for the revolute joint.
{jointId: b2JointId}:
The ID of the created revolute joint.
Creates a weld joint between two bodies.
(WeldJointConfig)
Configuration for the weld joint.
{jointId: b2JointId}:
The ID of the created weld joint.
Creates a distance joint between two bodies.
(DistanceJointConfig)
Configuration for the distance joint.
{jointId: b2JointId}:
The ID of the created distance joint.
Creates a wheel joint between two bodies.
(WheelJointConfig)
Configuration for the wheel joint.
{jointId: b2JointId}:
The ID of the created wheel joint.
Creates a prismatic joint between two bodies.
(PrismaticJointConfig)
Configuration for the prismatic joint.
{jointId: b2JointId}:
The ID of the created prismatic joint.
Creates a motor joint between two bodies.
(MotorJointConfig)
Configuration for the motor joint.
{jointId: b2JointId}:
The ID of the created motor joint.
Creates a mouse joint between two bodies.
(MouseJointConfig)
Configuration for the mouse joint.
{jointId: b2JointId}:
The ID of the created mouse joint.
Set the scale of the Box2D World when converting from pixels to meters.
(number)
Get the current scale of the Box2D World, as used when converting from pixels to meters.
number:
Converts a single numerical value from meters to pixels.
(number)
number:
Converts a single numerical value from pixels to meters.
(number)
number:
Converts the given x and y values from pixels to meters, stored in a new b2Vec2.
b2Vec2:
Convets the given value in radians to a b2Rot object, used for Box2D rotations.
(number)
b2Rot:
Adds a Sprite Game Object to the given World, attaching it to the given Body.
Removes a Sprite Game Object from the given World, optionally destroying the Body it was attached to.
Clears all Sprite to Body pairs. Neither the Sprites nor the Bodies are destroyed. The bodies remain in the world.
(number)
Returns the Body attached to the given Sprite in the given World.
Or null if no such pair exists.
(Sprite | null):
Either the sprite, or
null
.
Runs through all World-Sprite pairs and updates the Sprite positions and rotations to match the Body.
(number)
Converts a Box2D Body's position and rotation to a Sprite's position and rotation.
This is called automatically by UpdateWorldSprites.
(b2Body)
(Sprite)
Type: Object
(number)
: The x position of the sprite.
(number)
: The y position of the sprite.
(number)
: The width of the sprite.
(number)
: The height of the sprite.
(number)
: The rotation of the sprite in radians.
(number?)
: Optional horizontal scale of the sprite.
(number?)
: Optional vertical scale of the sprite.
(b2Vec2?)
: Optional scale vector of the sprite.
Type: Object
(b2WorldDef?)
: World definition
Type: Object
Steps a physics world to match fixedTimeStep. Returns the average time spent in the step function.
(WorldConfig)
Configuration for the world.
number:
totalTime - Time spent processing the step function, in seconds.
Type: Object
(b2WorldId)
: ID for the world.
(b2BodyId)
: ID for the static ground to attach the chain ends to.
(number?)
: Type of the body (static, dynamic, kinematic).
(b2Vec2)
: Position of the first link.
(b2Vec2)
: Position of the last link.
(number)
: Number of links in the chain.
(number)
: Length of each link
(number?)
: Density of the links.
(number?)
: Friction of the links.
(any?)
: Custom color for the links.
(number?)
: Radius for the circle 'caps' on each capsule link.
(boolean)
: Should the ends of the chain be fixed to the groundId object?
Type: Object
Type: Object
(b2WorldId)
: ID for the world in which to create the circle.
(b2BodyDef?)
: Body definition for the circle.
(number?)
: Type of the body (static, dynamic, kinematic).
(b2Vec2?)
: Position of the circle's center.
(b2BodyId?)
: Existing body ID if adding as a fixture.
(b2ShapeDef?)
: Shape definition for the circle.
(number?)
: Collision filtering, group index for the circle.
(number?)
: Collision filtering, what 'category' is this cirle in?
(number?)
: Collision filtering, what 'categories' will this circle collide with?
(number?)
: Density of the circle.
(number?)
: Friction of the circle.
(number?)
: Restitution of the circle.
(any?)
: Custom color for the circle.
(number?)
: Radius of the circle.
(boolean?)
: Enable presolve callback for the circle.
(boolean?)
: A sensor shape generates overlap events but never generates a collision response
(b2Vec2?)
: Offset of the circle's center when adding as a fixture.
Type: Object
(b2WorldId)
: ID for the world in which to create the capsule.
(b2BodyDef?)
: Body definition for the capsule.
(number?)
: Type of the body (static, dynamic, kinematic).
(b2Vec2?)
: Position of the capsule's center.
(b2BodyId?)
: Existing body ID if adding as a fixture.
(b2ShapeDef?)
: Shape definition for the capsule.
(number?)
: Density of the capsule.
(number?)
: Friction of the capsule.
(number?)
: Collision group index for the capsule.
(number?)
: Collision filtering, what 'category' is this in?
(number?)
: Collision filtering, what 'categories' will this collide with?
(any?)
: Custom color for the capsule.
(b2Vec2?)
: Center of the first circle of the capsule. Optional if 'height' is set.
(b2Vec2?)
: Center of the second circle of the capsule. Optional if 'height' is set.
(number?)
: Radius of the capsule's circles. Optional if 'width' is set.
(boolean?)
: Prevent rotation if set to true.
(number?)
: Linear damping of velocity.
(number?)
: The overall width of the capsule. If set replaces radius.
(number?)
: The overall height of the capsule, including the start and end caps. If set replaces center1 and center2.
Type: Object
(b2WorldId)
: ID for the world in which to create the box.
(b2BodyDef?)
: Body definition for the box.
(number?)
: Type of the body (static, dynamic, kinematic).
(b2Vec2?)
: Position of the box's center.
(boolean?)
: Prevent box from rotating?
(number?)
: Damping for linear velocity.
(number?)
: Damping for angular velocity.
(b2BodyId?)
: Existing body ID if adding as a fixture.
(b2ShapeDef?)
: Shape definition for the box.
(any?)
: The user data to associate with the body.
(number?)
: Collision group index for the box.
(number?)
: Collision filtering, what 'category' is this in?
(number?)
: Collision filtering, what 'categories' will this collide with?
(number?)
: Density of the box.
(number?)
: Friction of the box.
(number?)
: Restitution of the box.
(any?)
: Custom color for the box.
(boolean?)
: Enable presolve callback for the circle.
Type: Object
(b2WorldId)
: ID for the world in which to create the n-gon.
(b2BodyDef?)
: Body definition for the n-gon.
(number?)
: Type of the body (static, dynamic, kinematic).
(b2Vec2?)
: Position of the n-gon's center.
(b2BodyId?)
: Existing body ID if adding as a fixture.
(b2ShapeDef?)
: Shape definition for the n-gon.
(number?)
: Collision group index for the n-gon.
(number?)
: Density of the n-gon.
(number?)
: Friction of the n-gon.
(any?)
: Custom color for the n-gon.
(number)
: Radius of the n-gon.
(number)
: Number of sides for the n-gon.
Type: Object
(b2WorldId)
: ID for the world in which to create the polygon.
(b2BodyDef?)
: Body definition for the polygon.
(number?)
: Type of the body (static, dynamic, kinematic).
(b2Vec2?)
: Position of the polygon's center.
(b2BodyId?)
: Existing body ID if adding as a fixture.
(b2ShapeDef?)
: Shape definition for the polygon.
(number?)
: Collision group index for the polygon.
(number?)
: Density of the polygon.
(number?)
: Friction of the polygon.
(any?)
: Custom color for the polygon.
Type: Object
(b2WorldId)
: ID for the world in which to create the polygon.
(b2BodyDef?)
: Body definition for the polygon.
(number?)
: Type of the body (static, dynamic, kinematic).
(b2Vec2?)
: Position of the polygon's center.
(b2BodyId?)
: Existing body ID if adding as a fixture.
(b2ShapeDef?)
: Shape definition for the polygon.
(number?)
: Collision group index for the polygon.
(number?)
: Density of the polygon.
(number?)
: Friction of the polygon.
(number?)
: Restitution of the polygon.
(any?)
: Custom color for the polygon.
(Array<number>)
: List of vertices for the polygon in number pairs [x0,y0, x1,y1, ... xN,yN].
(b2Vec2)
: Offset to recenter the vertices if they are not zero based.
(b2Vec2)
: Scale for the vertices, defaults to 1, 1.
(string?)
: URL location of the XML data file, if we're using one.
(string?)
: Name 'key' to find the correct data in the XML.
Type: Object
(b2WorldId)
: ID for the world in which the bodies and joint exist.
(b2RevoluteJointDef?)
: A pre-existing b2RevoluteJointDef.
(b2BodyId)
: The first body to connect with this joint.
(b2BodyId)
: The second body to connect with this joint.
(b2Vec2?)
: Local position of the anchor point on the first body.
(b2Vec2?)
: Local position of the anchor point on the second body.
(number?)
: Lower limit of the joint's angle.
(number?)
: Upper limit of the joint's angle.
(boolean?)
: Whether to enable angle limits.
(boolean?)
: Whether to enable the joint's motor.
(number?)
: The desired motor speed.
(number?)
: The maximum torque the motor can apply.
(boolean?)
: Whether to enable the joint's spring.
(number?)
: The frequency of the joint's spring.
(number?)
: The damping ratio of the joint's spring.
(boolean?)
: Whether the connected bodies should collide.
(number?)
: The size to use when drawing the joint.
Type: Object
(b2WorldId)
: ID for the world in which the bodies and joint exist.
(b2WeldJointDef?)
: A pre-existing b2WeldJointDef.
(b2BodyId)
: The first body to weld with this joint.
(b2BodyId)
: The second body to weld with this joint.
(b2Vec2?)
: Local position of the anchor point on the first body.
(b2Vec2?)
: Local position of the anchor point on the second body.
(number?)
: The frequency at which the weld joint is enforced.
(number?)
: The angular damping ratio when the weld joint is springing back into alignment.
(number?)
: Reference angle for the weld joint at rest.
(boolean?)
: Whether the connected bodies should collide.
Type: Object
(b2WorldId)
: ID for the world in which the bodies and joint exist.
(b2DistanceJointDef?)
: A pre-existing b2DistanceJointDef.
(b2BodyId)
: The first body to connect with this joint.
(b2BodyId)
: The second body to connect with this joint.
(b2Vec2?)
: Local position of the anchor point on the first body.
(b2Vec2?)
: Local position of the anchor point on the second body.
(number?)
: The natural length of the joint.
(number?)
: The minimum allowed length of the joint.
(number?)
: The maximum allowed length of the joint.
(boolean?)
: Whether to enable the joint's spring.
(number?)
: The frequency of the joint's spring.
(number?)
: The damping ratio of the joint's spring.
(boolean?)
: Whether to enable length limits.
(boolean?)
: Whether the connected bodies should collide.
Type: Object
(b2WorldId)
: ID for the world in which the bodies and joint exist.
(b2WheelJointDef?)
: A pre-existing b2WheelJointDef.
(b2BodyId)
: The first body to connect with this joint.
(b2BodyId)
: The second body to connect with this joint.
(b2Vec2?)
: Local position of the anchor point on the first body.
(b2Vec2?)
: Local position of the anchor point on the second body.
(boolean?)
: Whether to enable the joint's spring.
(b2Vec2?)
: The local axis for the joint movement on body A.
(number?)
: The frequency of the joint's spring.
(number?)
: The damping ratio of the joint's spring.
(boolean?)
: Whether to enable translation limits.
(number?)
: The lower translation limit.
(number?)
: The upper translation limit.
(boolean?)
: Whether to enable the joint's motor.
(number?)
: The maximum torque the motor can apply.
(number?)
: The desired motor speed.
(boolean?)
: Whether the connected bodies should collide.
Type: Object
(b2WorldId)
: ID for the world in which the bodies and joint exist.
(b2PrismaticJointDef?)
: A pre-existing b2PrismaticJointDef.
(b2BodyId)
: The first body to connect with this joint.
(b2BodyId)
: The second body to connect with this joint.
(b2Vec2?)
: Local position of the anchor point on the first body.
(b2Vec2?)
: Local position of the anchor point on the second body.
(b2Vec2?)
: The local axis for the joint movement on body A.
(number?)
: The reference angle between the bodies.
(boolean?)
: Whether to enable the joint's spring.
(number?)
: The frequency of the joint's spring.
(number?)
: The damping ratio of the joint's spring.
(boolean?)
: Whether to enable translation limits.
(number?)
: The lower translation limit.
(number?)
: The upper translation limit.
(boolean?)
: Whether to enable the joint's motor.
(number?)
: The maximum force the motor can apply.
(number?)
: The desired motor speed.
(boolean?)
: Whether the connected bodies should collide.
Type: Object
(b2WorldId)
: ID for the world in which the bodies and joint exist.
(b2MotorJointDef?)
: A pre-existing b2MotorJointDef.
(b2BodyId)
: The first body to connect with this joint.
(b2BodyId)
: The second body to connect with this joint.
(b2Vec2?)
: The desired linear offset in frame A.
(number?)
: The maximum force that can be applied to reach the target offsets.
(number?)
: The desired angular offset.
(number?)
: The maximum torque that can be applied to reach the target angular offset.
(number?)
: Position correction factor in the range [0,1].
(boolean?)
: Whether the connected bodies should collide.
Type: Object
(b2WorldId)
: ID for the world in which the bodies and joint exist.
(b2MouseJointDef?)
: A pre-existing b2MouseJointDef.
(b2BodyId)
: The first (usually static) body to connect with this joint.
(b2BodyId)
: The second (usually dynamic) body to connect with this joint.
(b2Vec2?)
: The initial world target point.
(number?)
: The response frequency.
(number?)
: The damping ratio.
(number?)
: The maximum force that can be exerted to reach the target point.
(boolean?)
: Whether the connected bodies should collide.
e.g. worldId:worldId, bodyIdA:mouseCircle.bodyId, bodyIdB:mouseBox.bodyId, target:new b2Vec2(0, 0), hertz:30.0, dampingRatio:0.999, maxForce:35000
This file includes code that is:
function b2PrepareJointsTask(startIndex, endIndex, context) { const joints = context.joints;
for (let i = startIndex; i < endIndex; ++i) { const joint = joints[i]; joint_h.b2PrepareJoint(joint, context); } }
(any)
(any)
(any)
This file includes code that is:
This file includes code that is: