32inline bool b2IsValid(
float x)
37#define b2Sqrt(x) sqrtf(x)
38#define b2Atan2(y, x) atan2f(y, x)
47 b2Vec2(
float xIn,
float yIn) : x(xIn), y(yIn) {}
53 void Set(
float x_,
float y_) { x = x_; y = y_; }
59 float operator () (int32 i)
const
65 float& operator () (int32 i)
83 void operator *= (
float a)
91 return b2Sqrt(x * x + y * y);
104 float length = Length();
105 if (length < b2_epsilon)
109 float invLength = 1.0f / length;
119 return b2IsValid(x) && b2IsValid(y);
138 b2Vec3(
float xIn,
float yIn,
float zIn) : x(xIn), y(yIn), z(zIn) {}
141 void SetZero() { x = 0.0f; y = 0.0f; z = 0.0f; }
144 void Set(
float x_,
float y_,
float z_) { x = x_; y = y_; z = z_; }
152 x += v.x; y += v.y; z += v.z;
158 x -= v.x; y -= v.y; z -= v.z;
162 void operator *= (
float s)
164 x *= s; y *= s; z *= s;
184 b2Mat22(
float a11,
float a12,
float a21,
float a22)
186 ex.x = a11; ex.y = a21;
187 ey.x = a12; ey.y = a22;
200 ex.x = 1.0f; ey.x = 0.0f;
201 ex.y = 0.0f; ey.y = 1.0f;
207 ex.x = 0.0f; ey.x = 0.0f;
208 ex.y = 0.0f; ey.y = 0.0f;
213 float a = ex.x, b = ey.x, c = ex.y, d = ey.y;
215 float det = a * d - b * c;
220 B.ex.x = det * d; B.ey.x = -det * b;
221 B.ex.y = -det * c; B.ey.y = det * a;
229 float a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
230 float det = a11 * a22 - a12 * a21;
236 x.x = det * (a22 * b.x - a12 * b.y);
237 x.y = det * (a11 * b.y - a21 * b.x);
317 return b2Atan2(s, c);
375 void GetTransform(
b2Transform* transform,
float beta)
const;
379 void Advance(
float alpha);
394extern B2_API
const b2Vec2 b2Vec2_zero;
399 return a.x * b.x + a.y * b.y;
405 return a.x * b.y - a.y * b.x;
412 return b2Vec2(s * a.y, -s * a.x);
419 return b2Vec2(-s * a.y, s * a.x);
426 return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
433 return b2Vec2(b2Dot(v, A.ex), b2Dot(v, A.ey));
439 return b2Vec2(a.x + b.x, a.y + b.y);
445 return b2Vec2(a.x - b.x, a.y - b.y);
450 return b2Vec2(s * a.x, s * a.y);
453inline bool operator == (
const b2Vec2& a,
const b2Vec2& b)
455 return a.x == b.x && a.y == b.y;
458inline bool operator != (
const b2Vec2& a,
const b2Vec2& b)
460 return a.x != b.x || a.y != b.y;
463inline float b2Distance(
const b2Vec2& a,
const b2Vec2& b)
469inline float b2DistanceSquared(
const b2Vec2& a,
const b2Vec2& b)
477 return b2Vec3(s * a.x, s * a.y, s * a.z);
483 return b2Vec3(a.x + b.x, a.y + b.y, a.z + b.z);
489 return b2Vec3(a.x - b.x, a.y - b.y, a.z - b.z);
495 return a.x * b.x + a.y * b.y + a.z * b.z;
501 return b2Vec3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
506 return b2Mat22(A.ex + B.ex, A.ey + B.ey);
512 return b2Mat22(b2Mul(A, B.ex), b2Mul(A, B.ey));
518 b2Vec2 c1(b2Dot(A.ex, B.ex), b2Dot(A.ey, B.ex));
519 b2Vec2 c2(b2Dot(A.ex, B.ey), b2Dot(A.ey, B.ey));
526 return v.x * A.ex + v.y * A.ey + v.z * A.ez;
532 return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
543 qr.
s = q.
s * r.c + q.c * r.
s;
544 qr.c = q.c * r.c - q.
s * r.
s;
556 qr.
s = q.c * r.
s - q.
s * r.c;
557 qr.c = q.c * r.c + q.
s * r.
s;
564 return b2Vec2(q.c * v.x - q.
s * v.y, q.
s * v.x + q.c * v.y);
570 return b2Vec2(q.c * v.x + q.
s * v.y, -q.
s * v.x + q.c * v.y);
575 float x = (T.q.c * v.x - T.q.
s * v.y) + T.p.x;
576 float y = (T.q.s * v.x + T.q.c * v.y) + T.p.y;
583 float px = v.x - T.p.x;
584 float py = v.y - T.p.y;
585 float x = (T.q.c * px + T.q.
s * py);
586 float y = (-T.q.
s * px + T.q.c * py);
596 C.q = b2Mul(A.q, B.q);
597 C.p = b2Mul(A.q, B.p) + A.p;
606 C.q = b2MulT(A.q, B.q);
607 C.p = b2MulT(A.q, B.p - A.p);
614 return a > T(0) ? a : -a;
619 return b2Vec2(b2Abs(a.x), b2Abs(a.y));
624 return b2Mat22(b2Abs(A.ex), b2Abs(A.ey));
628inline T b2Min(T a, T b)
630 return a < b ? a : b;
635 return b2Vec2(b2Min(a.x, b.x), b2Min(a.y, b.y));
639inline T b2Max(T a, T b)
641 return a > b ? a : b;
646 return b2Vec2(b2Max(a.x, b.x), b2Max(a.y, b.y));
650inline T b2Clamp(T a, T low, T high)
652 return b2Max(low, b2Min(a, high));
657 return b2Max(low, b2Min(a, high));
660template<
typename T>
inline void b2Swap(T& a, T& b)
672inline uint32 b2NextPowerOfTwo(uint32 x)
682inline bool b2IsPowerOfTwo(uint32 x)
684 bool result = x > 0 && (x & (x - 1)) == 0;
691 xf->p = (1.0f - beta) * c0 + beta *
c;
692 float angle = (1.0f - beta) * a0 + beta *
a;
703 c0 += beta * (
c - c0);
704 a0 += beta * (
a - a0);
711 float twoPi = 2.0f * b2_pi;
712 float d = twoPi * floorf(a0 / twoPi);
A 2-by-2 matrix. Stored in column-major order.
Definition b2_math.h:172
b2Mat22(float a11, float a12, float a21, float a22)
Construct this matrix using scalars.
Definition b2_math.h:184
b2Vec2 Solve(const b2Vec2 &b) const
Definition b2_math.h:227
void SetIdentity()
Set this to the identity matrix.
Definition b2_math.h:198
void SetZero()
Set this matrix to all zeros.
Definition b2_math.h:205
b2Mat22()=default
The default constructor does nothing (for performance).
b2Mat22(const b2Vec2 &c1, const b2Vec2 &c2)
Construct this matrix using columns.
Definition b2_math.h:177
void Set(const b2Vec2 &c1, const b2Vec2 &c2)
Initialize this matrix using columns.
Definition b2_math.h:191
A 3-by-3 matrix. Stored in column-major order.
Definition b2_math.h:246
void GetSymInverse33(b2Mat33 *M) const
b2Vec3 Solve33(const b2Vec3 &b) const
b2Mat33(const b2Vec3 &c1, const b2Vec3 &c2, const b2Vec3 &c3)
Construct this matrix using columns.
Definition b2_math.h:251
void SetZero()
Set this matrix to all zeros.
Definition b2_math.h:259
void GetInverse22(b2Mat33 *M) const
b2Mat33()=default
The default constructor does nothing (for performance).
b2Vec2 Solve22(const b2Vec2 &b) const
Rotation.
Definition b2_math.h:288
void Set(float angle)
Set using an angle in radians.
Definition b2_math.h:300
float s
Sine and cosine.
Definition b2_math.h:333
float GetAngle() const
Get the angle in radians.
Definition b2_math.h:315
void SetIdentity()
Set to the identity rotation.
Definition b2_math.h:308
b2Vec2 GetXAxis() const
Get the x-axis.
Definition b2_math.h:321
b2Rot(float angle)
Initialize from an angle in radians.
Definition b2_math.h:292
b2Vec2 GetYAxis() const
Get the u-axis.
Definition b2_math.h:327
b2Vec2 c
center world positions
Definition b2_math.h:385
void Advance(float alpha)
Definition b2_math.h:699
b2Vec2 localCenter
local center of mass position
Definition b2_math.h:384
float a
world angles
Definition b2_math.h:386
void GetTransform(b2Transform *transform, float beta) const
Definition b2_math.h:689
void Normalize()
Normalize the angles.
Definition b2_math.h:709
float alpha0
Definition b2_math.h:390
A 2D column vector.
Definition b2_math.h:42
b2Vec2()=default
Default constructor does nothing (for performance).
void SetZero()
Set this vector to all zeros.
Definition b2_math.h:50
void Set(float x_, float y_)
Set this vector to some specified coordinates.
Definition b2_math.h:53
float Length() const
Get the length of this vector (the norm).
Definition b2_math.h:89
b2Vec2 Skew() const
Get the skew vector such that dot(skew_vec, other) == cross(vec, other)
Definition b2_math.h:123
b2Vec2(float xIn, float yIn)
Construct using coordinates.
Definition b2_math.h:47
bool IsValid() const
Does this vector contain finite coordinates?
Definition b2_math.h:117
float LengthSquared() const
Definition b2_math.h:96
float Normalize()
Convert this vector into a unit vector. Returns the length.
Definition b2_math.h:102
A 2D column vector with 3 elements.
Definition b2_math.h:133
b2Vec3()=default
Default constructor does nothing (for performance).
void SetZero()
Set this vector to all zeros.
Definition b2_math.h:141
b2Vec3(float xIn, float yIn, float zIn)
Construct using coordinates.
Definition b2_math.h:138
void Set(float x_, float y_, float z_)
Set this vector to some specified coordinates.
Definition b2_math.h:144