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);
373 void GetTransform(
b2Transform* transform,
float beta)
const;
377 void Advance(
float alpha);
392extern B2_API
const b2Vec2 b2Vec2_zero;
397 return a.x * b.x + a.y * b.y;
403 return a.x * b.y - a.y * b.x;
410 return b2Vec2(s * a.y, -s * a.x);
417 return b2Vec2(-s * a.y, s * a.x);
424 return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
431 return b2Vec2(b2Dot(v, A.ex), b2Dot(v, A.ey));
437 return b2Vec2(a.x + b.x, a.y + b.y);
443 return b2Vec2(a.x - b.x, a.y - b.y);
448 return b2Vec2(s * a.x, s * a.y);
451inline bool operator == (
const b2Vec2& a,
const b2Vec2& b)
453 return a.x == b.x && a.y == b.y;
456inline bool operator != (
const b2Vec2& a,
const b2Vec2& b)
458 return a.x != b.x || a.y != b.y;
461inline float b2Distance(
const b2Vec2& a,
const b2Vec2& b)
467inline float b2DistanceSquared(
const b2Vec2& a,
const b2Vec2& b)
475 return b2Vec3(s * a.x, s * a.y, s * a.z);
481 return b2Vec3(a.x + b.x, a.y + b.y, a.z + b.z);
487 return b2Vec3(a.x - b.x, a.y - b.y, a.z - b.z);
493 return a.x * b.x + a.y * b.y + a.z * b.z;
499 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);
504 return b2Mat22(A.ex + B.ex, A.ey + B.ey);
510 return b2Mat22(b2Mul(A, B.ex), b2Mul(A, B.ey));
516 b2Vec2 c1(b2Dot(A.ex, B.ex), b2Dot(A.ey, B.ex));
517 b2Vec2 c2(b2Dot(A.ex, B.ey), b2Dot(A.ey, B.ey));
524 return v.x * A.ex + v.y * A.ey + v.z * A.ez;
530 return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
541 qr.
s = q.
s * r.c + q.c * r.
s;
542 qr.c = q.c * r.c - q.
s * r.
s;
554 qr.
s = q.c * r.
s - q.
s * r.c;
555 qr.c = q.c * r.c + q.
s * r.
s;
562 return b2Vec2(q.c * v.x - q.
s * v.y, q.
s * v.x + q.c * v.y);
568 return b2Vec2(q.c * v.x + q.
s * v.y, -q.
s * v.x + q.c * v.y);
573 float x = (T.q.c * v.x - T.q.
s * v.y) + T.p.x;
574 float y = (T.q.
s * v.x + T.q.c * v.y) + T.p.y;
581 float px = v.x - T.p.x;
582 float py = v.y - T.p.y;
583 float x = (T.q.c * px + T.q.
s * py);
584 float y = (-T.q.
s * px + T.q.c * py);
594 C.q = b2Mul(A.q, B.q);
595 C.p = b2Mul(A.q, B.p) + A.p;
604 C.q = b2MulT(A.q, B.q);
605 C.p = b2MulT(A.q, B.p - A.p);
612 return a > T(0) ? a : -a;
617 return b2Vec2(b2Abs(a.x), b2Abs(a.y));
622 return b2Mat22(b2Abs(A.ex), b2Abs(A.ey));
626inline T b2Min(T a, T b)
628 return a < b ? a : b;
633 return b2Vec2(b2Min(a.x, b.x), b2Min(a.y, b.y));
637inline T b2Max(T a, T b)
639 return a > b ? a : b;
644 return b2Vec2(b2Max(a.x, b.x), b2Max(a.y, b.y));
648inline T b2Clamp(T a, T low, T high)
650 return b2Max(low, b2Min(a, high));
655 return b2Max(low, b2Min(a, high));
658template<
typename T>
inline void b2Swap(T& a, T& b)
670inline uint32 b2NextPowerOfTwo(uint32 x)
680inline bool b2IsPowerOfTwo(uint32 x)
682 bool result = x > 0 && (x & (x - 1)) == 0;
689 xf->p = (1.0f - beta) * c0 + beta *
c;
690 float angle = (1.0f - beta) * a0 + beta *
a;
701 c0 += beta * (
c - c0);
702 a0 += beta * (
a - a0);
709 float twoPi = 2.0f * b2_pi;
710 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(const b2Vec2 &c1, const b2Vec2 &c2)
Construct this matrix using columns.
Definition: b2_math.h:177
b2Mat22()
The default constructor does nothing (for performance).
Definition: b2_math.h:174
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
b2Mat33()
The default constructor does nothing (for performance).
Definition: b2_math.h:248
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
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
Definition: b2_math.h:369
b2Vec2 c
center world positions
Definition: b2_math.h:383
void Advance(float alpha)
Definition: b2_math.h:697
b2Vec2 localCenter
local center of mass position
Definition: b2_math.h:382
float a
world angles
Definition: b2_math.h:384
void GetTransform(b2Transform *transform, float beta) const
Definition: b2_math.h:687
void Normalize()
Normalize the angles.
Definition: b2_math.h:707
float alpha0
Definition: b2_math.h:388
A 2D column vector.
Definition: b2_math.h:42
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()
Default constructor does nothing (for performance).
Definition: b2_math.h:44
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
void SetZero()
Set this vector to all zeros.
Definition: b2_math.h:141
b2Vec3()
Default constructor does nothing (for performance).
Definition: b2_math.h:135
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