Box2D 3.2.0
A 2D physics engine for games
Loading...
Searching...
No Matches
math_types.h
1// SPDX-FileCopyrightText: 2026 Erin Catto
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
11
13typedef struct b2Vec2
14{
16 float x, y;
17} b2Vec2;
18
20typedef struct b2CosSin
21{
23 float cosine;
24 float sine;
25} b2CosSin;
26
28typedef struct b2Rot
29{
31 float c, s;
32} b2Rot;
33
35typedef struct b2Transform
36{
37 b2Vec2 p;
38 b2Rot q;
40
41#if defined( BOX2D_DOUBLE_PRECISION )
42
45typedef struct b2Pos
46{
47 double x, y;
48} b2Pos;
49
52typedef struct b2WorldTransform
53{
54 b2Pos p;
55 b2Rot q;
57
58#else
59
61typedef b2Vec2 b2Pos;
62
65
66#endif
67
69typedef struct b2Mat22
70{
73} b2Mat22;
74
76typedef struct b2AABB
77{
78 b2Vec2 lowerBound;
79 b2Vec2 upperBound;
80} b2AABB;
81
83typedef struct b2Plane
84{
85 b2Vec2 normal;
86 float offset;
87} b2Plane;
88
90#define B2_PI 3.14159265359f
91
92static const b2Vec2 b2Vec2_zero = { 0.0f, 0.0f };
93static const b2Rot b2Rot_identity = { 1.0f, 0.0f };
94static const b2Transform b2Transform_identity = { { 0.0f, 0.0f }, { 1.0f, 0.0f } };
95static const b2Mat22 b2Mat22_zero = { { 0.0f, 0.0f }, { 0.0f, 0.0f } };
96
97// Initializers valid in both modes: 0.0f promotes to double, the identity rotation is float
98static const b2Pos b2Pos_zero = { 0.0f, 0.0f };
99static const b2WorldTransform b2WorldTransform_identity = { { 0.0f, 0.0f }, { 1.0f, 0.0f } };
100
float c
cosine and sine
Definition math_types.h:31
float x
coordinates
Definition math_types.h:16
b2Vec2 cx
columns
Definition math_types.h:72
float cosine
cosine and sine
Definition math_types.h:23
b2Vec2 b2Pos
Alias in single precision.
Definition math_types.h:61
b2Transform b2WorldTransform
Alias in single precision.
Definition math_types.h:64
Axis-aligned bounding box.
Definition math_types.h:77
Cosine and sine pair This uses a custom implementation designed for cross-platform determinism.
Definition math_types.h:21
A 2-by-2 Matrix.
Definition math_types.h:70
separation = dot(normal, point) - offset
Definition math_types.h:84
2D rotation This is similar to using a complex number for rotation
Definition math_types.h:29
A 2D rigid transform.
Definition math_types.h:36
2D vector This can be used to represent a point or free vector
Definition math_types.h:14