diff options
Diffstat (limited to 'Client/Source/Phy2DLite/Math.h')
-rw-r--r-- | Client/Source/Phy2DLite/Math.h | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/Client/Source/Phy2DLite/Math.h b/Client/Source/Phy2DLite/Math.h index 7e10b73..987b55a 100644 --- a/Client/Source/Phy2DLite/Math.h +++ b/Client/Source/Phy2DLite/Math.h @@ -14,9 +14,9 @@ namespace Phy2D struct Vec2 { Vec2() {} - Vec2(number x, number y) : x(x), y(y) {} + Vec2(fixed x, fixed y) : x(x), y(y) {} - void Set(number x_, number y_) { x = x_; y = y_; } + void Set(fixed x_, fixed y_) { x = x_; y = y_; } Vec2 operator -() { return Vec2(-x, -y); } @@ -30,12 +30,12 @@ namespace Phy2D x -= v.x; y -= v.y; } - void operator *= (number a) + void operator *= (fixed a) { x *= a; y *= a; } - number Length() const + fixed Length() const { return SQRT(x * x + y * y); } @@ -45,15 +45,15 @@ namespace Phy2D return std::to_string((float)x) + "," + std::to_string((float)y); } - number x, y; + fixed x, y; }; struct Mat22 { Mat22() {} - Mat22(number angle) + Mat22(fixed angle) { - number c = COS(angle), s = SIN(angle); + fixed c = COS(angle), s = SIN(angle); col1.x = c; col2.x = -s; col1.y = s; col2.y = c; } @@ -67,11 +67,11 @@ namespace Phy2D Mat22 Invert() const { - number a = col1.x, b = col2.x, c = col1.y, d = col2.y; + fixed a = col1.x, b = col2.x, c = col1.y, d = col2.y; Mat22 B; - number det = a * d - b * c; + fixed det = a * d - b * c; assert(det != _0); - det = (number)_1 / det; + det = (fixed)_1 / det; B.col1.x = det * d; B.col2.x = -det * b; B.col1.y = -det * c; B.col2.y = det * a; return B; @@ -80,22 +80,22 @@ namespace Phy2D Vec2 col1, col2; }; - inline number Dot(const Vec2& a, const Vec2& b) + inline fixed Dot(const Vec2& a, const Vec2& b) { return a.x * b.x + a.y * b.y; } - inline number Cross(const Vec2& a, const Vec2& b) + inline fixed Cross(const Vec2& a, const Vec2& b) { return a.x * b.y - a.y * b.x; } - inline Vec2 Cross(const Vec2& a, number s) + inline Vec2 Cross(const Vec2& a, fixed s) { return Vec2(s * a.y, -s * a.x); } - inline Vec2 Cross(number s, const Vec2& a) + inline Vec2 Cross(fixed s, const Vec2& a) { return Vec2(-s * a.y, s * a.x); } @@ -115,7 +115,7 @@ namespace Phy2D return Vec2(a.x - b.x, a.y - b.y); } - inline Vec2 operator * (number s, const Vec2& v) + inline Vec2 operator * (fixed s, const Vec2& v) { return Vec2(s * v.x, s * v.y); } @@ -130,7 +130,7 @@ namespace Phy2D return Mat22(A * B.col1, A * B.col2); } - inline number Abs(number a) + inline fixed Abs(fixed a) { return a > _0 ? a : -a; } @@ -145,22 +145,22 @@ namespace Phy2D return Mat22(Abs(A.col1), Abs(A.col2)); } - inline number Sign(number x) + inline fixed Sign(fixed x) { return x < _0 ? -_1 : _1; } - inline number Min(number a, number b) + inline fixed Min(fixed a, fixed b) { return a < b ? a : b; } - inline number Max(number a, number b) + inline fixed Max(fixed a, fixed b) { return a > b ? a : b; } - inline number Clamp(number a, number low, number high) + inline fixed Clamp(fixed a, fixed low, fixed high) { return Max(low, Min(a, high)); } @@ -172,18 +172,18 @@ namespace Phy2D b = tmp; } - //// Random number in range [-1,1] - //inline number Random() + //// Random fixed in range [-1,1] + //inline fixed Random() //{ - // number r = (number)rand(); + // fixed r = (fixed)rand(); // r /= RAND_MAX; - // r = (number)2.0f * r - _1; + // r = (fixed)2.0f * r - _1; // return r; //} - //inline number Random(number lo, number hi) + //inline fixed Random(fixed lo, fixed hi) //{ - // number r = (number)rand(); + // fixed r = (fixed)rand(); // r /= RAND_MAX; // r = (hi - lo) * r + lo; // return r; |