Box2D 3.2.0
A 2D physics engine for games
Loading...
Searching...
No Matches
Constants

Constants. More...

Macros

#define B2_HUGE   ( ( 100.0f * 1000.0f ) * b2_lengthUnitsPerMeter )
 Used to detect bad values.
#define B2_MAX_WORKERS   32
 Maximum parallel workers. Used for some fixed size arrays.
#define B2_MAX_TASKS   256
 Maximum number of tasks queued per world step.
#define B2_GRAPH_COLOR_COUNT   24
 Maximum number of colors in the constraint graph.
#define B2_LINEAR_SLOP   ( 0.005f * b2_lengthUnitsPerMeter )
 A small length used as a collision and constraint tolerance.
#define B2_MAX_WORLDS   128
 Maximum number of simultaneous worlds that can be allocated.
#define B2_NAME_LENGTH   10
 Maximum length of the body name. Can be 0 if you don't need names.
#define B2_MAX_ROTATION   ( 0.25f * B2_PI )
 The maximum rotation of a body per time step.
#define B2_SPECULATIVE_DISTANCE   ( 4.0f * B2_LINEAR_SLOP )
 Box2D uses limited speculative collision.
#define B2_CONTACT_RECYCLE_DISTANCE   ( 10.0f * B2_LINEAR_SLOP )
 The default contact recycling distance.
#define B2_CONTACT_RECYCLE_COS_ANGLE   ( 0.98f )
 The default contact recycling world angle threshold. 0.98 ~= 11.5 degrees.
#define B2_MAX_AABB_MARGIN   ( 0.05f * b2_lengthUnitsPerMeter )
 This is used to fatten AABBs in the dynamic tree.
#define B2_AABB_MARGIN_FRACTION   0.125f
 For small objects the margin is limited to this fraction times the maximum extent.
#define B2_TIME_TO_SLEEP   0.5f
 The time that a body must be still before it will go to sleep. In seconds.
#define B2_MAX_RESTITUTION_ITERATIONS   63
 The maximum number of restitution iterations. Needed to avoid a solver overflow.

Detailed Description

Constants.

Some can be configured. I try to include most internal constants here for convenience and clarity. This is why they are not all configurable.

Macro Definition Documentation

◆ B2_GRAPH_COLOR_COUNT

#define B2_GRAPH_COLOR_COUNT   24

Maximum number of colors in the constraint graph.

Constraints that cannot find a color are added to the overflow set, which is solved single-threaded. The compound barrel benchmark has minor overflow with 24 colors

◆ B2_HUGE

#define B2_HUGE   ( ( 100.0f * 1000.0f ) * b2_lengthUnitsPerMeter )

Used to detect bad values.

Positions greater than about 16km will have precision problems in single precision, so 100km as a limit should be fine in all cases. In large world mode the broad-phase starts to have excessive padding at 10,000km, so a value beyond 100,000km is extreme.

◆ B2_LINEAR_SLOP

#define B2_LINEAR_SLOP   ( 0.005f * b2_lengthUnitsPerMeter )

A small length used as a collision and constraint tolerance.

Usually it is chosen to be numerically significant, but visually insignificant. In meters. Normally this is 0.5cm.

Warning
modifying this can have a significant impact on stability

◆ B2_MAX_AABB_MARGIN

#define B2_MAX_AABB_MARGIN   ( 0.05f * b2_lengthUnitsPerMeter )

This is used to fatten AABBs in the dynamic tree.

This allows proxies to move by a small amount without triggering a tree adjustment. This is in meters. Normally this is 5cm. This has been tuned on benchmarks and I found that keeping the margin small improves performance by reducing the number of contacts. I used to keep this larger in the past to avoid tree insert and remove churn. But the broad-phase no longer works that way and now uses a two-phase refit and rebuild setup similar to Jolt.

Warning
modifying this can have a significant impact on performance

◆ B2_MAX_ROTATION

#define B2_MAX_ROTATION   ( 0.25f * B2_PI )

The maximum rotation of a body per time step.

This limit is very large and is used to prevent numerical problems. You shouldn't need to adjust this.

Warning
increasing this to 0.5f * B2_PI or greater will break continuous collision.

◆ B2_MAX_TASKS

#define B2_MAX_TASKS   256

Maximum number of tasks queued per world step.

b2EnqueueTaskCallbackFcn will never be called more than this per world step. This is related to B2_MAX_WORKERS. With 32 workers, the maximum observed task count is 130. This allows an external task system to use a fixed size array for Box2D tasks, which may help with creating stable user task pointers.

◆ B2_SPECULATIVE_DISTANCE

#define B2_SPECULATIVE_DISTANCE   ( 4.0f * B2_LINEAR_SLOP )

Box2D uses limited speculative collision.

This reduces jitter. Normally this is 2cm.

Warning
modifying this can have a significant impact on performance and stability