LiquidFun
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
b2Math.h
1 /*
2 * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 * 1. The origin of this software must not be misrepresented; you must not
11 * claim that you wrote the original software. If you use this software
12 * in a product, an acknowledgment in the product documentation would be
13 * appreciated but is not required.
14 * 2. Altered source versions must be plainly marked as such, and must not be
15 * misrepresented as being the original software.
16 * 3. This notice may not be removed or altered from any source distribution.
17 */
18 
19 #ifndef B2_MATH_H
20 #define B2_MATH_H
21 
23 #include <math.h>
24 
26 inline bool b2IsValid(float32 x)
27 {
28  union {
29  float32 f;
30  int32 i;
31  } v = { x };
32  return (v.i & 0x7f800000) != 0x7f800000;
33 }
34 
36 inline float32 b2InvSqrt(float32 x)
37 {
38  union
39  {
40  float32 x;
41  int32 i;
42  } convert;
43 
44  convert.x = x;
45  float32 xhalf = 0.5f * x;
46  convert.i = 0x5f3759df - (convert.i >> 1);
47  x = convert.x;
48  x = x * (1.5f - xhalf * x * x);
49  return x;
50 }
51 
52 #define b2Sqrt(x) sqrtf(x)
53 #define b2Atan2(y, x) atan2f(y, x)
54 
56 struct b2Vec2
57 {
59  b2Vec2() {}
60 
62  b2Vec2(float32 x, float32 y) : x(x), y(y) {}
63 
65  void SetZero() { x = 0.0f; y = 0.0f; }
66 
68  void Set(float32 x_, float32 y_) { x = x_; y = y_; }
69 
71  b2Vec2 operator -() const { b2Vec2 v; v.Set(-x, -y); return v; }
72 
74  float32 operator () (int32 i) const
75  {
76  return (&x)[i];
77  }
78 
80  float32& operator () (int32 i)
81  {
82  return (&x)[i];
83  }
84 
86  void operator += (const b2Vec2& v)
87  {
88  x += v.x; y += v.y;
89  }
90 
92  void operator -= (const b2Vec2& v)
93  {
94  x -= v.x; y -= v.y;
95  }
96 
98  void operator *= (float32 a)
99  {
100  x *= a; y *= a;
101  }
102 
104  float32 Length() const
105  {
106  return b2Sqrt(x * x + y * y);
107  }
108 
111  float32 LengthSquared() const
112  {
113  return x * x + y * y;
114  }
115 
117  float32 Normalize()
118  {
119  float32 length = Length();
120  if (length < b2_epsilon)
121  {
122  return 0.0f;
123  }
124  float32 invLength = 1.0f / length;
125  x *= invLength;
126  y *= invLength;
127 
128  return length;
129  }
130 
132  bool IsValid() const
133  {
134  return b2IsValid(x) && b2IsValid(y);
135  }
136 
138  b2Vec2 Skew() const
139  {
140  return b2Vec2(-y, x);
141  }
142 
143  float32 x, y;
144 };
145 
147 inline b2Vec2 operator + (const b2Vec2& v, float f)
148 {
149  return b2Vec2(v.x + f, v.y + f);
150 }
151 
153 inline b2Vec2 operator - (const b2Vec2& v, float f)
154 {
155  return b2Vec2(v.x - f, v.y - f);
156 }
157 
159 inline b2Vec2 operator * (const b2Vec2& v, float f)
160 {
161  return b2Vec2(v.x * f, v.y * f);
162 }
163 
165 inline b2Vec2 operator / (const b2Vec2& v, float f)
166 {
167  return b2Vec2(v.x / f, v.y / f);
168 }
169 
171 struct b2Vec3
172 {
174  b2Vec3() {}
175 
177  b2Vec3(float32 x, float32 y, float32 z) : x(x), y(y), z(z) {}
178 
180  void SetZero() { x = 0.0f; y = 0.0f; z = 0.0f; }
181 
183  void Set(float32 x_, float32 y_, float32 z_) { x = x_; y = y_; z = z_; }
184 
186  b2Vec3 operator -() const { b2Vec3 v; v.Set(-x, -y, -z); return v; }
187 
189  void operator += (const b2Vec3& v)
190  {
191  x += v.x; y += v.y; z += v.z;
192  }
193 
195  void operator -= (const b2Vec3& v)
196  {
197  x -= v.x; y -= v.y; z -= v.z;
198  }
199 
201  void operator *= (float32 s)
202  {
203  x *= s; y *= s; z *= s;
204  }
205 
207  float32 Length() const
208  {
209  return b2Sqrt(x * x + y * y + z * z);
210  }
211 
213  float32 Normalize()
214  {
215  float32 length = Length();
216  if (length < b2_epsilon)
217  {
218  return 0.0f;
219  }
220  float32 invLength = 1.0f / length;
221  x *= invLength;
222  y *= invLength;
223  z *= invLength;
224 
225  return length;
226  }
227 
228  float32 x, y, z;
229 };
230 
232 struct b2Vec4
233 {
235  b2Vec4() {}
236 
238  b2Vec4(float32 x, float32 y, float32 z, float32 w) : x(x), y(y), z(z), w(w) {}
239 
240  float32 x, y, z, w;
241 };
242 
244 struct b2Mat22
245 {
247  b2Mat22() {}
248 
250  b2Mat22(const b2Vec2& c1, const b2Vec2& c2)
251  {
252  ex = c1;
253  ey = c2;
254  }
255 
257  b2Mat22(float32 a11, float32 a12, float32 a21, float32 a22)
258  {
259  ex.x = a11; ex.y = a21;
260  ey.x = a12; ey.y = a22;
261  }
262 
264  void Set(const b2Vec2& c1, const b2Vec2& c2)
265  {
266  ex = c1;
267  ey = c2;
268  }
269 
271  void SetIdentity()
272  {
273  ex.x = 1.0f; ey.x = 0.0f;
274  ex.y = 0.0f; ey.y = 1.0f;
275  }
276 
278  void SetZero()
279  {
280  ex.x = 0.0f; ey.x = 0.0f;
281  ex.y = 0.0f; ey.y = 0.0f;
282  }
283 
284  b2Mat22 GetInverse() const
285  {
286  float32 a = ex.x, b = ey.x, c = ex.y, d = ey.y;
287  b2Mat22 B;
288  float32 det = a * d - b * c;
289  if (det != 0.0f)
290  {
291  det = 1.0f / det;
292  }
293  B.ex.x = det * d; B.ey.x = -det * b;
294  B.ex.y = -det * c; B.ey.y = det * a;
295  return B;
296  }
297 
300  b2Vec2 Solve(const b2Vec2& b) const
301  {
302  float32 a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
303  float32 det = a11 * a22 - a12 * a21;
304  if (det != 0.0f)
305  {
306  det = 1.0f / det;
307  }
308  b2Vec2 x;
309  x.x = det * (a22 * b.x - a12 * b.y);
310  x.y = det * (a11 * b.y - a21 * b.x);
311  return x;
312  }
313 
314  b2Vec2 ex, ey;
315 };
316 
318 struct b2Mat33
319 {
321  b2Mat33() {}
322 
324  b2Mat33(const b2Vec3& c1, const b2Vec3& c2, const b2Vec3& c3)
325  {
326  ex = c1;
327  ey = c2;
328  ez = c3;
329  }
330 
332  void SetZero()
333  {
334  ex.SetZero();
335  ey.SetZero();
336  ez.SetZero();
337  }
338 
341  b2Vec3 Solve33(const b2Vec3& b) const;
342 
346  b2Vec2 Solve22(const b2Vec2& b) const;
347 
350  void GetInverse22(b2Mat33* M) const;
351 
354  void GetSymInverse33(b2Mat33* M) const;
355 
356  b2Vec3 ex, ey, ez;
357 };
358 
360 struct b2Rot
361 {
362  b2Rot() {}
363 
365  explicit b2Rot(float32 angle)
366  {
368  s = sinf(angle);
369  c = cosf(angle);
370  }
371 
373  void Set(float32 angle)
374  {
376  s = sinf(angle);
377  c = cosf(angle);
378  }
379 
381  void SetIdentity()
382  {
383  s = 0.0f;
384  c = 1.0f;
385  }
386 
388  float32 GetAngle() const
389  {
390  return b2Atan2(s, c);
391  }
392 
394  b2Vec2 GetXAxis() const
395  {
396  return b2Vec2(c, s);
397  }
398 
400  b2Vec2 GetYAxis() const
401  {
402  return b2Vec2(-s, c);
403  }
404 
406  float32 s, c;
407 };
408 
412 {
415 
417  b2Transform(const b2Vec2& position, const b2Rot& rotation) : p(position), q(rotation) {}
418 
420  void SetIdentity()
421  {
422  p.SetZero();
423  q.SetIdentity();
424  }
425 
427  void Set(const b2Vec2& position, float32 angle)
428  {
429  p = position;
430  q.Set(angle);
431  }
432 
433 #if LIQUIDFUN_EXTERNAL_LANGUAGE_API
434  float32 GetPositionX() const { return p.x; }
436 
438  float32 GetPositionY() const { return p.y; }
439 
441  float32 GetRotationSin() const { return q.s; }
442 
444  float32 GetRotationCos() const { return q.c; }
445 #endif // LIQUIDFUN_EXTERNAL_LANGUAGE_API
446 
447  b2Vec2 p;
448  b2Rot q;
449 };
450 
455 struct b2Sweep
456 {
459  void GetTransform(b2Transform* xfb, float32 beta) const;
460 
463  void Advance(float32 alpha);
464 
466  void Normalize();
467 
469  b2Vec2 c0, c;
470  float32 a0, a;
471 
474  float32 alpha0;
475 };
476 
478 extern const b2Vec2 b2Vec2_zero;
479 
481 inline float32 b2Dot(const b2Vec2& a, const b2Vec2& b)
482 {
483  return a.x * b.x + a.y * b.y;
484 }
485 
487 inline float32 b2Cross(const b2Vec2& a, const b2Vec2& b)
488 {
489  return a.x * b.y - a.y * b.x;
490 }
491 
494 inline b2Vec2 b2Cross(const b2Vec2& a, float32 s)
495 {
496  return b2Vec2(s * a.y, -s * a.x);
497 }
498 
501 inline b2Vec2 b2Cross(float32 s, const b2Vec2& a)
502 {
503  return b2Vec2(-s * a.y, s * a.x);
504 }
505 
508 inline b2Vec2 b2Mul(const b2Mat22& A, const b2Vec2& v)
509 {
510  return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
511 }
512 
515 inline b2Vec2 b2MulT(const b2Mat22& A, const b2Vec2& v)
516 {
517  return b2Vec2(b2Dot(v, A.ex), b2Dot(v, A.ey));
518 }
519 
521 inline b2Vec2 operator + (const b2Vec2& a, const b2Vec2& b)
522 {
523  return b2Vec2(a.x + b.x, a.y + b.y);
524 }
525 
527 inline b2Vec2 operator - (const b2Vec2& a, const b2Vec2& b)
528 {
529  return b2Vec2(a.x - b.x, a.y - b.y);
530 }
531 
532 inline b2Vec2 operator * (float32 s, const b2Vec2& a)
533 {
534  return b2Vec2(s * a.x, s * a.y);
535 }
536 
537 inline bool operator == (const b2Vec2& a, const b2Vec2& b)
538 {
539  return a.x == b.x && a.y == b.y;
540 }
541 
542 inline bool operator != (const b2Vec2& a, const b2Vec2& b)
543 {
544  return !operator==(a, b);
545 }
546 
547 inline float32 b2Distance(const b2Vec2& a, const b2Vec2& b)
548 {
549  b2Vec2 c = a - b;
550  return c.Length();
551 }
552 
553 inline float32 b2DistanceSquared(const b2Vec2& a, const b2Vec2& b)
554 {
555  b2Vec2 c = a - b;
556  return b2Dot(c, c);
557 }
558 
559 inline b2Vec3 operator * (float32 s, const b2Vec3& a)
560 {
561  return b2Vec3(s * a.x, s * a.y, s * a.z);
562 }
563 
565 inline b2Vec3 operator + (const b2Vec3& a, const b2Vec3& b)
566 {
567  return b2Vec3(a.x + b.x, a.y + b.y, a.z + b.z);
568 }
569 
571 inline b2Vec3 operator - (const b2Vec3& a, const b2Vec3& b)
572 {
573  return b2Vec3(a.x - b.x, a.y - b.y, a.z - b.z);
574 }
575 
577 inline float32 b2Dot(const b2Vec3& a, const b2Vec3& b)
578 {
579  return a.x * b.x + a.y * b.y + a.z * b.z;
580 }
581 
583 inline b2Vec3 b2Cross(const b2Vec3& a, const b2Vec3& b)
584 {
585  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);
586 }
587 
588 inline b2Mat22 operator + (const b2Mat22& A, const b2Mat22& B)
589 {
590  return b2Mat22(A.ex + B.ex, A.ey + B.ey);
591 }
592 
593 // A * B
594 inline b2Mat22 b2Mul(const b2Mat22& A, const b2Mat22& B)
595 {
596  return b2Mat22(b2Mul(A, B.ex), b2Mul(A, B.ey));
597 }
598 
599 // A^T * B
600 inline b2Mat22 b2MulT(const b2Mat22& A, const b2Mat22& B)
601 {
602  b2Vec2 c1(b2Dot(A.ex, B.ex), b2Dot(A.ey, B.ex));
603  b2Vec2 c2(b2Dot(A.ex, B.ey), b2Dot(A.ey, B.ey));
604  return b2Mat22(c1, c2);
605 }
606 
608 inline b2Vec3 b2Mul(const b2Mat33& A, const b2Vec3& v)
609 {
610  return v.x * A.ex + v.y * A.ey + v.z * A.ez;
611 }
612 
614 inline b2Vec2 b2Mul22(const b2Mat33& A, const b2Vec2& v)
615 {
616  return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
617 }
618 
620 inline b2Rot b2Mul(const b2Rot& q, const b2Rot& r)
621 {
622  // [qc -qs] * [rc -rs] = [qc*rc-qs*rs -qc*rs-qs*rc]
623  // [qs qc] [rs rc] [qs*rc+qc*rs -qs*rs+qc*rc]
624  // s = qs * rc + qc * rs
625  // c = qc * rc - qs * rs
626  b2Rot qr;
627  qr.s = q.s * r.c + q.c * r.s;
628  qr.c = q.c * r.c - q.s * r.s;
629  return qr;
630 }
631 
633 inline b2Rot b2MulT(const b2Rot& q, const b2Rot& r)
634 {
635  // [ qc qs] * [rc -rs] = [qc*rc+qs*rs -qc*rs+qs*rc]
636  // [-qs qc] [rs rc] [-qs*rc+qc*rs qs*rs+qc*rc]
637  // s = qc * rs - qs * rc
638  // c = qc * rc + qs * rs
639  b2Rot qr;
640  qr.s = q.c * r.s - q.s * r.c;
641  qr.c = q.c * r.c + q.s * r.s;
642  return qr;
643 }
644 
646 inline b2Vec2 b2Mul(const b2Rot& q, const b2Vec2& v)
647 {
648  return b2Vec2(q.c * v.x - q.s * v.y, q.s * v.x + q.c * v.y);
649 }
650 
652 inline b2Vec2 b2MulT(const b2Rot& q, const b2Vec2& v)
653 {
654  return b2Vec2(q.c * v.x + q.s * v.y, -q.s * v.x + q.c * v.y);
655 }
656 
657 inline b2Vec2 b2Mul(const b2Transform& T, const b2Vec2& v)
658 {
659  float32 x = (T.q.c * v.x - T.q.s * v.y) + T.p.x;
660  float32 y = (T.q.s * v.x + T.q.c * v.y) + T.p.y;
661 
662  return b2Vec2(x, y);
663 }
664 
665 inline b2Vec2 b2MulT(const b2Transform& T, const b2Vec2& v)
666 {
667  float32 px = v.x - T.p.x;
668  float32 py = v.y - T.p.y;
669  float32 x = (T.q.c * px + T.q.s * py);
670  float32 y = (-T.q.s * px + T.q.c * py);
671 
672  return b2Vec2(x, y);
673 }
674 
675 // v2 = A.q.Rot(B.q.Rot(v1) + B.p) + A.p
676 // = (A.q * B.q).Rot(v1) + A.q.Rot(B.p) + A.p
677 inline b2Transform b2Mul(const b2Transform& A, const b2Transform& B)
678 {
679  b2Transform C;
680  C.q = b2Mul(A.q, B.q);
681  C.p = b2Mul(A.q, B.p) + A.p;
682  return C;
683 }
684 
685 // v2 = A.q' * (B.q * v1 + B.p - A.p)
686 // = A.q' * B.q * v1 + A.q' * (B.p - A.p)
687 inline b2Transform b2MulT(const b2Transform& A, const b2Transform& B)
688 {
689  b2Transform C;
690  C.q = b2MulT(A.q, B.q);
691  C.p = b2MulT(A.q, B.p - A.p);
692  return C;
693 }
694 
695 template <typename T>
696 inline T b2Abs(T a)
697 {
698  return a > T(0) ? a : -a;
699 }
700 
701 inline b2Vec2 b2Abs(const b2Vec2& a)
702 {
703  return b2Vec2(b2Abs(a.x), b2Abs(a.y));
704 }
705 
706 inline b2Mat22 b2Abs(const b2Mat22& A)
707 {
708  return b2Mat22(b2Abs(A.ex), b2Abs(A.ey));
709 }
710 
711 template <typename T>
712 inline T b2Min(T a, T b)
713 {
714  return a < b ? a : b;
715 }
716 
717 inline b2Vec2 b2Min(const b2Vec2& a, const b2Vec2& b)
718 {
719  return b2Vec2(b2Min(a.x, b.x), b2Min(a.y, b.y));
720 }
721 
722 template <typename T>
723 inline T b2Max(T a, T b)
724 {
725  return a > b ? a : b;
726 }
727 
728 inline b2Vec2 b2Max(const b2Vec2& a, const b2Vec2& b)
729 {
730  return b2Vec2(b2Max(a.x, b.x), b2Max(a.y, b.y));
731 }
732 
733 template <typename T>
734 inline T b2Clamp(T a, T low, T high)
735 {
736  return b2Max(low, b2Min(a, high));
737 }
738 
739 inline b2Vec2 b2Clamp(const b2Vec2& a, const b2Vec2& low, const b2Vec2& high)
740 {
741  return b2Max(low, b2Min(a, high));
742 }
743 
744 template<typename T> inline void b2Swap(T& a, T& b)
745 {
746  T tmp = a;
747  a = b;
748  b = tmp;
749 }
750 
756 inline uint32 b2NextPowerOfTwo(uint32 x)
757 {
758  x |= (x >> 1);
759  x |= (x >> 2);
760  x |= (x >> 4);
761  x |= (x >> 8);
762  x |= (x >> 16);
763  return x + 1;
764 }
765 
766 inline bool b2IsPowerOfTwo(uint32 x)
767 {
768  bool result = x > 0 && (x & (x - 1)) == 0;
769  return result;
770 }
771 
772 inline void b2Sweep::GetTransform(b2Transform* xf, float32 beta) const
773 {
774  xf->p = (1.0f - beta) * c0 + beta * c;
775  float32 angle = (1.0f - beta) * a0 + beta * a;
776  xf->q.Set(angle);
777 
778  // Shift to origin
779  xf->p -= b2Mul(xf->q, localCenter);
780 }
781 
782 inline void b2Sweep::Advance(float32 alpha)
783 {
784  b2Assert(alpha0 < 1.0f);
785  float32 beta = (alpha - alpha0) / (1.0f - alpha0);
786  c0 += beta * (c - c0);
787  a0 += beta * (a - a0);
788  alpha0 = alpha;
789 }
790 
792 inline void b2Sweep::Normalize()
793 {
794  float32 twoPi = 2.0f * b2_pi;
795  float32 d = twoPi * floorf(a0 / twoPi);
796  a0 -= d;
797  a -= d;
798 }
799 
800 #endif
b2Vec2 Solve22(const b2Vec2 &b) const
Definition: b2Math.cpp:41
Definition: b2Math.h:411
b2Transform()
The default constructor does nothing.
Definition: b2Math.h:414
b2Vec3(float32 x, float32 y, float32 z)
Construct using coordinates.
Definition: b2Math.h:177
void GetTransform(b2Transform *xfb, float32 beta) const
Definition: b2Math.h:772
b2Vec4()
Default constructor does nothing (for performance).
Definition: b2Math.h:235
A 3D column vector with 3 elements.
Definition: b2Math.h:171
float32 GetAngle() const
Get the angle in radians.
Definition: b2Math.h:388
bool IsValid() const
Does this vector contain finite coordinates?
Definition: b2Math.h:132
b2Mat22(const b2Vec2 &c1, const b2Vec2 &c2)
Construct this matrix using columns.
Definition: b2Math.h:250
float32 Length() const
Get the length of this vector (the norm).
Definition: b2Math.h:207
b2Vec3()
Default constructor does nothing (for performance).
Definition: b2Math.h:174
A 3-by-3 matrix. Stored in column-major order.
Definition: b2Math.h:318
b2Vec2()
Default constructor does nothing (for performance).
Definition: b2Math.h:59
void Set(float32 x_, float32 y_, float32 z_)
Set this vector to some specified coordinates.
Definition: b2Math.h:183
float32 Normalize()
Convert this vector into a unit vector. Returns the length.
Definition: b2Math.h:117
b2Vec2 GetYAxis() const
Get the u-axis.
Definition: b2Math.h:400
b2Mat33()
The default constructor does nothing (for performance).
Definition: b2Math.h:321
b2Vec2 operator-() const
Negate this vector.
Definition: b2Math.h:71
A 4D column vector with 4 elements.
Definition: b2Math.h:232
b2Vec2(float32 x, float32 y)
Construct using coordinates.
Definition: b2Math.h:62
Definition: b2Math.h:455
b2Mat22()
The default constructor does nothing (for performance).
Definition: b2Math.h:247
float32 s
Sine and cosine.
Definition: b2Math.h:406
float32 a
world angles
Definition: b2Math.h:470
b2Mat33(const b2Vec3 &c1, const b2Vec3 &c2, const b2Vec3 &c3)
Construct this matrix using columns.
Definition: b2Math.h:324
b2Vec2 Skew() const
Get the skew vector such that dot(skew_vec, other) == cross(vec, other)
Definition: b2Math.h:138
b2Vec2 GetXAxis() const
Get the x-axis.
Definition: b2Math.h:394
b2Vec3 operator-() const
Negate this vector.
Definition: b2Math.h:186
void Set(float32 x_, float32 y_)
Set this vector to some specified coordinates.
Definition: b2Math.h:68
float32 Normalize()
Convert this vector into a unit vector. Returns the length.
Definition: b2Math.h:213
void Set(const b2Vec2 &position, float32 angle)
Set this based on the position and angle.
Definition: b2Math.h:427
void SetZero()
Set this vector to all zeros.
Definition: b2Math.h:65
void operator+=(const b2Vec2 &v)
Add a vector to this vector.
Definition: b2Math.h:86
void GetInverse22(b2Mat33 *M) const
Definition: b2Math.cpp:56
void operator*=(float32 s)
Multiply this vector by a scalar.
Definition: b2Math.h:201
void SetIdentity()
Set this to the identity transform.
Definition: b2Math.h:420
void operator-=(const b2Vec2 &v)
Subtract a vector from this vector.
Definition: b2Math.h:92
void SetZero()
Set this vector to all zeros.
Definition: b2Math.h:180
void operator-=(const b2Vec3 &v)
Subtract a vector from this vector.
Definition: b2Math.h:195
b2Rot(float32 angle)
Initialize from an angle in radians.
Definition: b2Math.h:365
void operator+=(const b2Vec3 &v)
Add a vector to this vector.
Definition: b2Math.h:189
b2Vec2 Solve(const b2Vec2 &b) const
Definition: b2Math.h:300
b2Vec2 c
center world positions
Definition: b2Math.h:469
float32 Length() const
Get the length of this vector (the norm).
Definition: b2Math.h:104
b2Vec2 localCenter
local center of mass position
Definition: b2Math.h:468
void GetSymInverse33(b2Mat33 *M) const
Returns the zero matrix if singular.
Definition: b2Math.cpp:71
A 2-by-2 matrix. Stored in column-major order.
Definition: b2Math.h:244
void Set(const b2Vec2 &c1, const b2Vec2 &c2)
Initialize this matrix using columns.
Definition: b2Math.h:264
b2Vec4(float32 x, float32 y, float32 z, float32 w)
Construct using coordinates.
Definition: b2Math.h:238
void SetIdentity()
Set to the identity rotation.
Definition: b2Math.h:381
float32 alpha0
Definition: b2Math.h:474
void SetIdentity()
Set this to the identity matrix.
Definition: b2Math.h:271
void Normalize()
Normalize the angles.
Definition: b2Math.h:792
b2Vec3 Solve33(const b2Vec3 &b) const
Definition: b2Math.cpp:25
void SetZero()
Set this matrix to all zeros.
Definition: b2Math.h:278
A 2D column vector.
Definition: b2Math.h:56
void Advance(float32 alpha)
Definition: b2Math.h:782
float32 LengthSquared() const
Definition: b2Math.h:111
void operator*=(float32 a)
Multiply this vector by a scalar.
Definition: b2Math.h:98
void Set(float32 angle)
Set using an angle in radians.
Definition: b2Math.h:373
b2Transform(const b2Vec2 &position, const b2Rot &rotation)
Initialize using a position vector and a rotation.
Definition: b2Math.h:417
void SetZero()
Set this matrix to all zeros.
Definition: b2Math.h:332
b2Mat22(float32 a11, float32 a12, float32 a21, float32 a22)
Construct this matrix using scalars.
Definition: b2Math.h:257
Rotation.
Definition: b2Math.h:360
float32 operator()(int32 i) const
Read from and indexed element.
Definition: b2Math.h:74