aboutsummaryrefslogtreecommitdiff
path: root/Client/Source/Phy2D/Common/Math.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-12-02 14:44:36 +0800
committerchai <chaifix@163.com>2021-12-02 14:44:36 +0800
commitfdd228071a3112aeebda20766c7df3b20b8651aa (patch)
treeedc6e05bda6c537582235dbe110e3ed783e0e36a /Client/Source/Phy2D/Common/Math.h
parentb1d4e9866de19c70174553e543e81ef4473dee6c (diff)
+Fix32
Diffstat (limited to 'Client/Source/Phy2D/Common/Math.h')
-rw-r--r--Client/Source/Phy2D/Common/Math.h191
1 files changed, 0 insertions, 191 deletions
diff --git a/Client/Source/Phy2D/Common/Math.h b/Client/Source/Phy2D/Common/Math.h
index 9c0ff8f..e69de29 100644
--- a/Client/Source/Phy2D/Common/Math.h
+++ b/Client/Source/Phy2D/Common/Math.h
@@ -1,191 +0,0 @@
-#pragma once
-
-#include <math.h>
-#include <assert.h>
-#include <stdlib.h>
-#include <string>
-
-#include "Settings.h"
-
-namespace Phy2D
-{
-
- struct Vec2
- {
- Vec2() {}
- Vec2(number x, number y) : x(x), y(y) {}
-
- void Set(number x_, number y_) { x = x_; y = y_; }
-
- Vec2 operator -() { return Vec2(-x, -y); }
-
- void operator += (const Vec2& v)
- {
- x += v.x; y += v.y;
- }
-
- void operator -= (const Vec2& v)
- {
- x -= v.x; y -= v.y;
- }
-
- void operator *= (number a)
- {
- x *= a; y *= a;
- }
-
- number Length() const
- {
- return SQRT(x * x + y * y);
- }
-
- std::string ToString()
- {
- return std::to_string((float)x) + "," + std::to_string((float)y);
- }
-
- number x, y;
- };
-
- struct Mat22
- {
- Mat22() {}
- Mat22(number angle)
- {
- number c = COS(angle), s = SIN(angle);
- col1.x = c; col2.x = -s;
- col1.y = s; col2.y = c;
- }
-
- Mat22(const Vec2& col1, const Vec2& col2) : col1(col1), col2(col2) {}
-
- Mat22 Transpose() const
- {
- return Mat22(Vec2(col1.x, col2.x), Vec2(col1.y, col2.y));
- }
-
- Mat22 Invert() const
- {
- number a = col1.x, b = col2.x, c = col1.y, d = col2.y;
- Mat22 B;
- number det = a * d - b * c;
- assert(det != 0.0f);
- det = (number)1.0f / det;
- B.col1.x = det * d; B.col2.x = -det * b;
- B.col1.y = -det * c; B.col2.y = det * a;
- return B;
- }
-
- Vec2 col1, col2;
- };
-
- inline number 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)
- {
- return a.x * b.y - a.y * b.x;
- }
-
- inline Vec2 Cross(const Vec2& a, number s)
- {
- return Vec2(s * a.y, -s * a.x);
- }
-
- inline Vec2 Cross(number s, const Vec2& a)
- {
- return Vec2(-s * a.y, s * a.x);
- }
-
- inline Vec2 operator * (const Mat22& A, const Vec2& v)
- {
- return Vec2(A.col1.x * v.x + A.col2.x * v.y, A.col1.y * v.x + A.col2.y * v.y);
- }
-
- inline Vec2 operator + (const Vec2& a, const Vec2& b)
- {
- return Vec2(a.x + b.x, a.y + b.y);
- }
-
- inline Vec2 operator - (const Vec2& a, const Vec2& b)
- {
- return Vec2(a.x - b.x, a.y - b.y);
- }
-
- inline Vec2 operator * (number s, const Vec2& v)
- {
- return Vec2(s * v.x, s * v.y);
- }
-
- inline Mat22 operator + (const Mat22& A, const Mat22& B)
- {
- return Mat22(A.col1 + B.col1, A.col2 + B.col2);
- }
-
- inline Mat22 operator * (const Mat22& A, const Mat22& B)
- {
- return Mat22(A * B.col1, A * B.col2);
- }
-
- inline number Abs(number a)
- {
- return a > 0.0f ? a : -a;
- }
-
- inline Vec2 Abs(const Vec2& a)
- {
- return Vec2(fabsf(a.x), fabsf(a.y));
- }
-
- inline Mat22 Abs(const Mat22& A)
- {
- return Mat22(Abs(A.col1), Abs(A.col2));
- }
-
- inline number Sign(number x)
- {
- return (float) x < 0.0f ? -1.0f : 1.0f;
- }
-
- inline number Min(number a, number b)
- {
- return a < b ? a : b;
- }
-
- inline number Max(number a, number b)
- {
- return a > b ? a : b;
- }
-
- inline number Clamp(number a, number low, number high)
- {
- return Max(low, Min(a, high));
- }
-
- template<typename T> inline void Swap(T& a, T& b)
- {
- T tmp = a;
- a = b;
- b = tmp;
- }
-
- //// Random number in range [-1,1]
- //inline number Random()
- //{
- // number r = (number)rand();
- // r /= RAND_MAX;
- // r = (number)2.0f * r - 1.0f;
- // return r;
- //}
-
- //inline number Random(number lo, number hi)
- //{
- // number r = (number)rand();
- // r /= RAND_MAX;
- // r = (hi - lo) * r + lo;
- // return r;
- //}
-
-}