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

Vector math types and functions. More...

Data Structures

struct  b2Vec2
 2D vector This can be used to represent a point or free vector More...
struct  b2CosSin
 Cosine and sine pair This uses a custom implementation designed for cross-platform determinism. More...
struct  b2Rot
 2D rotation This is similar to using a complex number for rotation More...
struct  b2Transform
 A 2D rigid transform. More...
struct  b2Mat22
 A 2-by-2 Matrix. More...
struct  b2AABB
 Axis-aligned bounding box. More...
struct  b2Plane
 separation = dot(normal, point) - offset More...

Macros

#define B2_PI   3.14159265359f
 https://en.wikipedia.org/wiki/Pi

Typedefs

typedef b2Vec2 b2Pos
 Alias in single precision.
typedef b2Transform b2WorldTransform
 Alias in single precision.

Functions

bool b2IsValidFloat (float a)
 Is this a valid number? Not NaN or infinity.
bool b2IsValidVec2 (b2Vec2 v)
 Is this a valid vector? Not NaN or infinity.
bool b2IsValidRot (b2Rot q)
 Is this a valid rotation? Not NaN or infinity. Is normalized.
bool b2IsValidTransform (b2Transform t)
 Is this a valid transform? Not NaN or infinity. Rotation is normalized.
bool b2IsValidAABB (b2AABB aabb)
 Is this a valid bounding box?
bool b2IsValidPlane (b2Plane a)
 Is this a valid plane? Normal is a unit vector. Not NaN or infinity.
bool b2IsValidPos (b2Pos p)
 Is this a valid world position? Not NaN or infinity.
bool b2IsValidWorldTransform (b2WorldTransform t)
 Is this a valid world transform? Not NaN or infinity. Rotation is normalized.
float b2Atan2 (float y, float x)
 Compute an approximate arctangent in the range [-pi, pi] This is hand coded for cross-platform determinism.
b2CosSin b2ComputeCosSin (float radians)
 Compute the cosine and sine of an angle in radians. Implemented for cross-platform determinism.
b2Rot b2ComputeRotationBetweenUnitVectors (b2Vec2 v1, b2Vec2 v2)
 Compute the rotation between two unit vectors.
void b2SetLengthUnitsPerMeter (float lengthUnits)
 Box2D bases all length units on meters, but you may need different units for your game.
float b2GetLengthUnitsPerMeter (void)
 Get the current length units per meter.

Variables

BOX2D_EXPORT float b2_lengthUnitsPerMeter
 This value is exported for efficiency. Don't modify directly.

Detailed Description

Vector math types and functions.


Data Structure Documentation

◆ b2Vec2

struct b2Vec2

2D vector This can be used to represent a point or free vector

Data Fields
float x coordinates
float y

◆ b2CosSin

struct b2CosSin

Cosine and sine pair This uses a custom implementation designed for cross-platform determinism.

Data Fields
float cosine cosine and sine
float sine

◆ b2Rot

struct b2Rot

2D rotation This is similar to using a complex number for rotation

Data Fields
float c cosine and sine
float s

◆ b2Transform

struct b2Transform

A 2D rigid transform.

Data Fields
b2Vec2 p
b2Rot q

◆ b2Mat22

struct b2Mat22

A 2-by-2 Matrix.

Data Fields
b2Vec2 cx columns
b2Vec2 cy

◆ b2AABB

struct b2AABB

Axis-aligned bounding box.

Data Fields
b2Vec2 lowerBound
b2Vec2 upperBound

◆ b2Plane

struct b2Plane

separation = dot(normal, point) - offset

Data Fields
b2Vec2 normal
float offset

Function Documentation

◆ b2Atan2()

float b2Atan2 ( float y,
float x )

Compute an approximate arctangent in the range [-pi, pi] This is hand coded for cross-platform determinism.

The atan2f function in the standard library is not cross-platform deterministic. Accurate to around 0.0023 degrees

◆ b2IsValidAABB()

bool b2IsValidAABB ( b2AABB aabb)

Is this a valid bounding box?

Not NaN or infinity. Upper bound greater than or equal to lower bound.

◆ b2SetLengthUnitsPerMeter()

void b2SetLengthUnitsPerMeter ( float lengthUnits)

Box2D bases all length units on meters, but you may need different units for your game.

You can set this value to use different units. This should be done at application startup and only modified once. Default value is 1. For example, if your game uses pixels for units you can use pixels for all length values sent to Box2D. There should be no extra cost. However, Box2D has some internal tolerances and thresholds that have been tuned for meters. By calling this function, Box2D is able to adjust those tolerances and thresholds to improve accuracy. A good rule of thumb is to pass the height of your player character to this function. So if your player character is 32 pixels high, then pass 32 to this function. Then you may confidently use pixels for all the length values sent to Box2D. All length values returned from Box2D will also be pixels because Box2D does not do any scaling internally. However, you are now on the hook for coming up with good values for gravity, density, and forces.

Warning
This must be modified before any calls to Box2D