26 inline bool b2IsValid(float32 x)
    28     int32 ix = *
reinterpret_cast<int32*
>(&x);
    29     return (ix & 0x7f800000) != 0x7f800000;
    33 inline float32 b2InvSqrt(float32 x)
    42     float32 xhalf = 0.5f * x;
    43     convert.i = 0x5f3759df - (convert.i >> 1);
    45     x = x * (1.5f - xhalf * x * x);
    49 #define b2Sqrt(x)   sqrtf(x)    50 #define b2Atan2(y, x)   atan2f(y, x)    59     b2Vec2(float32 x, float32 y) : x(x), y(y) {}
    65     void Set(float32 x_, float32 y_) { x = x_; y = y_; }
   103         return b2Sqrt(x * x + y * y);
   110         return x * x + y * y;
   116         float32 length = 
Length();
   117         if (length < b2_epsilon)
   121         float32 invLength = 1.0f / length;
   131         return b2IsValid(x) && b2IsValid(y);
   150     b2Vec3(float32 x, float32 y, float32 z) : x(x), y(y), z(z) {}
   153     void SetZero() { x = 0.0f; y = 0.0f; z = 0.0f; }
   156     void Set(float32 x_, float32 y_, float32 z_) { x = x_; y = y_; z = z_; }
   164         x += v.x; y += v.y; z += v.z;
   170         x -= v.x; y -= v.y; z -= v.z;
   176         x *= s; y *= s; z *= s;
   196     b2Mat22(float32 a11, float32 a12, float32 a21, float32 a22)
   198         ex.x = a11; ex.y = a21;
   199         ey.x = a12; ey.y = a22;
   212         ex.x = 1.0f; ey.x = 0.0f;
   213         ex.y = 0.0f; ey.y = 1.0f;
   219         ex.x = 0.0f; ey.x = 0.0f;
   220         ex.y = 0.0f; ey.y = 0.0f;
   225         float32 a = ex.x, b = ey.x, c = ex.y, d = ey.y;
   227         float32 det = a * d - b * c;
   232         B.ex.x =  det * d;  B.ey.x = -det * b;
   233         B.ex.y = -det * c;  B.ey.y =  det * a;
   241         float32 a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
   242         float32 det = a11 * a22 - a12 * a21;
   248         x.x = det * (a22 * b.x - a12 * b.y);
   249         x.y = det * (a11 * b.y - a21 * b.x);
   289     void GetInverse22(
b2Mat33* M) 
const;
   293     void GetSymInverse33(
b2Mat33* M) 
const;
   329         return b2Atan2(s, c);
   384     void GetTransform(
b2Transform* xfb, float32 beta) 
const;
   388     void Advance(float32 alpha);
   403 extern const b2Vec2 b2Vec2_zero;
   408     return a.x * b.x + a.y * b.y;
   412 inline float32 b2Cross(
const b2Vec2& a, 
const b2Vec2& b)
   414     return a.x * b.y - a.y * b.x;
   421     return b2Vec2(s * a.y, -s * a.x);
   428     return b2Vec2(-s * a.y, s * a.x);
   435     return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
   442     return b2Vec2(b2Dot(v, A.ex), b2Dot(v, A.ey));
   448     return b2Vec2(a.x + b.x, a.y + b.y);
   454     return b2Vec2(a.x - b.x, a.y - b.y);
   459     return b2Vec2(s * a.x, s * a.y);
   462 inline bool operator == (
const b2Vec2& a, 
const b2Vec2& b)
   464     return a.x == b.x && a.y == b.y;
   467 inline float32 b2Distance(
const b2Vec2& a, 
const b2Vec2& b)
   473 inline float32 b2DistanceSquared(
const b2Vec2& a, 
const b2Vec2& b)
   481     return b2Vec3(s * a.x, s * a.y, s * a.z);
   487     return b2Vec3(a.x + b.x, a.y + b.y, a.z + b.z);
   493     return b2Vec3(a.x - b.x, a.y - b.y, a.z - b.z);
   499     return a.x * b.x + a.y * b.y + a.z * b.z;
   505     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);
   510     return b2Mat22(A.ex + B.ex, A.ey + B.ey);
   516     return b2Mat22(b2Mul(A, B.ex), b2Mul(A, B.ey));
   522     b2Vec2 c1(b2Dot(A.ex, B.ex), b2Dot(A.ey, B.ex));
   523     b2Vec2 c2(b2Dot(A.ex, B.ey), b2Dot(A.ey, B.ey));
   530     return v.x * A.ex + v.y * A.ey + v.z * A.ez;
   536     return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
   547     qr.
s = q.
s * r.c + q.c * r.
s;
   548     qr.c = q.c * r.c - q.
s * r.
s;
   560     qr.
s = q.c * r.
s - q.
s * r.c;
   561     qr.c = q.c * r.c + q.
s * r.
s;
   568     return b2Vec2(q.c * v.x - q.
s * v.y, q.
s * v.x + q.c * v.y);
   574     return b2Vec2(q.c * v.x + q.
s * v.y, -q.
s * v.x + q.c * v.y);
   579     float32 x = (T.q.c * v.x - T.q.
s * v.y) + T.p.x;
   580     float32 y = (T.q.
s * v.x + T.q.c * v.y) + T.p.y;
   587     float32 px = v.x - T.p.x;
   588     float32 py = v.y - T.p.y;
   589     float32 x = (T.q.c * px + T.q.
s * py);
   590     float32 y = (-T.q.
s * px + T.q.c * py);
   600     C.q = b2Mul(A.q, B.q);
   601     C.p = b2Mul(A.q, B.p) + A.p;
   610     C.q = b2MulT(A.q, B.q);
   611     C.p = b2MulT(A.q, B.p - A.p);
   615 template <
typename T>
   618     return a > T(0) ? a : -a;
   623     return b2Vec2(b2Abs(a.x), b2Abs(a.y));
   628     return b2Mat22(b2Abs(A.ex), b2Abs(A.ey));
   631 template <
typename T>
   632 inline T b2Min(T a, T b)
   634     return a < b ? a : b;
   639     return b2Vec2(b2Min(a.x, b.x), b2Min(a.y, b.y));
   642 template <
typename T>
   643 inline T b2Max(T a, T b)
   645     return a > b ? a : b;
   650     return b2Vec2(b2Max(a.x, b.x), b2Max(a.y, b.y));
   653 template <
typename T>
   654 inline T b2Clamp(T a, T low, T high)
   656     return b2Max(low, b2Min(a, high));
   661     return b2Max(low, b2Min(a, high));
   664 template<
typename T> 
inline void b2Swap(T& a, T& b)
   676 inline uint32 b2NextPowerOfTwo(uint32 x)
   686 inline bool b2IsPowerOfTwo(uint32 x)
   688     bool result = x > 0 && (x & (x - 1)) == 0;
   694     xf->p = (1.0f - beta) * c0 + beta * c;
   695     float32 angle = (1.0f - beta) * a0 + beta * a;
   699     xf->p -= b2Mul(xf->q, localCenter);
   704     b2Assert(alpha0 < 1.0f);
   705     float32 beta = (alpha - alpha0) / (1.0f - alpha0);
   706     c0 += beta * (c - c0);
   707     a0 += beta * (a - a0);
   714     float32 twoPi = 2.0f * b2_pi;
   715     float32 d =  twoPi * floorf(a0 / twoPi);
 
b2Vec3(float32 x, float32 y, float32 z)
Construct using coordinates. 
Definition: b2Math.h:150
void GetTransform(b2Transform *xfb, float32 beta) const 
Definition: b2Math.h:692
A 2D column vector with 3 elements. 
Definition: b2Math.h:144
float32 GetAngle() const 
Get the angle in radians. 
Definition: b2Math.h:327
bool IsValid() const 
Does this vector contain finite coordinates? 
Definition: b2Math.h:129
b2Mat22(const b2Vec2 &c1, const b2Vec2 &c2)
Construct this matrix using columns. 
Definition: b2Math.h:189
b2Vec3()
Default constructor does nothing (for performance). 
Definition: b2Math.h:147
A 3-by-3 matrix. Stored in column-major order. 
Definition: b2Math.h:257
b2Vec2()
Default constructor does nothing (for performance). 
Definition: b2Math.h:56
void Set(float32 x_, float32 y_, float32 z_)
Set this vector to some specified coordinates. 
Definition: b2Math.h:156
float32 Normalize()
Convert this vector into a unit vector. Returns the length. 
Definition: b2Math.h:114
b2Vec2 GetYAxis() const 
Get the u-axis. 
Definition: b2Math.h:339
b2Mat33()
The default constructor does nothing (for performance). 
Definition: b2Math.h:260
b2Vec2 operator-() const 
Negate this vector. 
Definition: b2Math.h:68
b2Vec2(float32 x, float32 y)
Construct using coordinates. 
Definition: b2Math.h:59
b2Mat22()
The default constructor does nothing (for performance). 
Definition: b2Math.h:186
float32 s
Sine and cosine. 
Definition: b2Math.h:345
float32 a
world angles 
Definition: b2Math.h:395
b2Mat33(const b2Vec3 &c1, const b2Vec3 &c2, const b2Vec3 &c3)
Construct this matrix using columns. 
Definition: b2Math.h:263
b2Vec2 Skew() const 
Get the skew vector such that dot(skew_vec, other) == cross(vec, other) 
Definition: b2Math.h:135
b2Vec2 GetXAxis() const 
Get the x-axis. 
Definition: b2Math.h:333
void Set(float32 x_, float32 y_)
Set this vector to some specified coordinates. 
Definition: b2Math.h:65
void SetZero()
Set this vector to all zeros. 
Definition: b2Math.h:62
void operator+=(const b2Vec2 &v)
Add a vector to this vector. 
Definition: b2Math.h:83
void operator-=(const b2Vec2 &v)
Subtract a vector from this vector. 
Definition: b2Math.h:89
void SetZero()
Set this vector to all zeros. 
Definition: b2Math.h:153
b2Rot(float32 angle)
Initialize from an angle in radians. 
Definition: b2Math.h:304
b2Vec2 Solve(const b2Vec2 &b) const 
Definition: b2Math.h:239
b2Vec2 c
center world positions 
Definition: b2Math.h:394
float32 Length() const 
Get the length of this vector (the norm). 
Definition: b2Math.h:101
b2Vec2 localCenter
local center of mass position 
Definition: b2Math.h:393
A 2-by-2 matrix. Stored in column-major order. 
Definition: b2Math.h:183
void Set(const b2Vec2 &c1, const b2Vec2 &c2)
Initialize this matrix using columns. 
Definition: b2Math.h:203
void SetIdentity()
Set to the identity rotation. 
Definition: b2Math.h:320
float32 alpha0
Definition: b2Math.h:399
void SetIdentity()
Set this to the identity matrix. 
Definition: b2Math.h:210
void Normalize()
Normalize the angles. 
Definition: b2Math.h:712
void SetZero()
Set this matrix to all zeros. 
Definition: b2Math.h:217
A 2D column vector. 
Definition: b2Math.h:53
void Advance(float32 alpha)
Definition: b2Math.h:702
float32 LengthSquared() const 
Definition: b2Math.h:108
void operator*=(float32 a)
Multiply this vector by a scalar. 
Definition: b2Math.h:95
void Set(float32 angle)
Set using an angle in radians. 
Definition: b2Math.h:312
void SetZero()
Set this matrix to all zeros. 
Definition: b2Math.h:271
b2Mat22(float32 a11, float32 a12, float32 a21, float32 a22)
Construct this matrix using scalars. 
Definition: b2Math.h:196
Rotation. 
Definition: b2Math.h:299
float32 operator()(int32 i) const 
Read from and indexed element. 
Definition: b2Math.h:71