summaryrefslogtreecommitdiff
path: root/Client/Source/Math
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Source/Math')
-rw-r--r--Client/Source/Math/Functions.cpp0
-rw-r--r--Client/Source/Math/Functions.h30
-rw-r--r--Client/Source/Math/Math.h6
-rw-r--r--Client/Source/Math/Matrix22.h10
-rw-r--r--Client/Source/Math/Matrix44.h8
-rw-r--r--Client/Source/Math/Rect.h13
-rw-r--r--Client/Source/Math/Vector2.hpp67
-rw-r--r--Client/Source/Math/Vector3.hpp32
-rw-r--r--Client/Source/Math/Vector4.hpp33
9 files changed, 199 insertions, 0 deletions
diff --git a/Client/Source/Math/Functions.cpp b/Client/Source/Math/Functions.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Client/Source/Math/Functions.cpp
diff --git a/Client/Source/Math/Functions.h b/Client/Source/Math/Functions.h
new file mode 100644
index 0000000..3dd17dd
--- /dev/null
+++ b/Client/Source/Math/Functions.h
@@ -0,0 +1,30 @@
+#pragma once
+
+namespace MathUtils
+{
+ template <typename T>
+ inline T Max(T a, T b)
+ {
+ return a < b ? b : a;
+ }
+
+ template <typename T>
+ inline T Min(T a, T b)
+ {
+ return a < b ? a : b;
+ }
+
+}
+
+#define max(a, b)\
+((a)>(b)?(a):(b))
+
+#define min(a, b)\
+(a)<(b)?(a):(b)
+
+#define clamp(v, lo, hi)\
+max((lo), min((v), (hi)))
+
+// ÆæÊý·µ»Ø1£¬·ñÔò0
+#define odd(n) \
+(((n)&1)?1:0)
diff --git a/Client/Source/Math/Math.h b/Client/Source/Math/Math.h
new file mode 100644
index 0000000..0cd7d84
--- /dev/null
+++ b/Client/Source/Math/Math.h
@@ -0,0 +1,6 @@
+#include "Vector2.hpp"
+#include "Matrix22.h"
+#include "Matrix44.h"
+#include "rect.h"
+#include "Functions.h"
+
diff --git a/Client/Source/Math/Matrix22.h b/Client/Source/Math/Matrix22.h
new file mode 100644
index 0000000..c777084
--- /dev/null
+++ b/Client/Source/Math/Matrix22.h
@@ -0,0 +1,10 @@
+#pragma once
+
+class Matrix22
+{
+public:
+ float m[2][2]; // row major
+
+
+
+};
diff --git a/Client/Source/Math/Matrix44.h b/Client/Source/Math/Matrix44.h
new file mode 100644
index 0000000..562ac54
--- /dev/null
+++ b/Client/Source/Math/Matrix44.h
@@ -0,0 +1,8 @@
+#pragma once
+
+class Matrix44
+{
+public:
+ float m[4][4]; // row major
+
+};
diff --git a/Client/Source/Math/Rect.h b/Client/Source/Math/Rect.h
new file mode 100644
index 0000000..63c6aa1
--- /dev/null
+++ b/Client/Source/Math/Rect.h
@@ -0,0 +1,13 @@
+#pragma once
+
+struct Rect
+{
+ Rect(float x = 0, float y = 0, float w = 0, float h = 0)
+ {
+ this->x = x;
+ this->y = y;
+ this->width = w;
+ this->height = h;
+ }
+ float x, y, width, height;
+};
diff --git a/Client/Source/Math/Vector2.hpp b/Client/Source/Math/Vector2.hpp
new file mode 100644
index 0000000..65f2c10
--- /dev/null
+++ b/Client/Source/Math/Vector2.hpp
@@ -0,0 +1,67 @@
+#pragma once
+
+#include "../Utilities/Assert.h"
+#include "../Math/Functions.h"
+
+template <typename T>
+class Vector2Template
+{
+public:
+ Vector2Template(T x = 0, T y = 0)
+ {
+ this->x = x;
+ this->y = y;
+ }
+ inline void Set(T x, T y)
+ {
+ this->x = x;
+ this->y = y;
+ }
+
+ Vector2Template Clamp(T xmin, T xmax, T ymin, T ymax)
+ {
+ Vector2Template v;
+ v.x = clamp(x, xmin, xmax);
+ v.y = clamp(y, ymin, ymax);
+ return v;
+ }
+
+ T operator[](int i)
+ {
+ if (i == 0) return x;
+ else if (i == 1) return y;
+ Assert(false);
+ }
+
+ bool operator == (const Vector2Template& v) const
+ {
+ return v.x == x && v.y == y;
+ }
+
+ bool operator != (const Vector2Template& v) const
+ {
+ return v.x != x || v.y != y;
+ }
+
+ Vector2Template<T> operator - (const Vector2Template& v) const
+ {
+ Vector2Template<T> res = Vector2Template<T>(x - v.x, y - v.y);
+ return res;
+ }
+
+
+ float x, y;
+
+ static Vector2Template<T> zero;
+ static Vector2Template<T> one ;
+
+};
+
+using Vector2f = Vector2Template<float>;
+using Vector2i = Vector2Template<int>;
+
+
+template<typename T>
+Vector2Template<T> Vector2Template<T>::zero = Vector2Template(0, 0);
+template<typename T>
+Vector2Template<T> Vector2Template<T>::one = Vector2Template(1, 1);
diff --git a/Client/Source/Math/Vector3.hpp b/Client/Source/Math/Vector3.hpp
new file mode 100644
index 0000000..eee913b
--- /dev/null
+++ b/Client/Source/Math/Vector3.hpp
@@ -0,0 +1,32 @@
+#pragma once
+
+template<typename T>
+struct Vector3Template
+{
+ T x, y, z;
+ Vector3Template(T x = 0, T y = 0, T z = 0)
+ {
+ this->x = x;
+ this->y = y;
+ this->z = z;
+ }
+ inline void Set(T x, T y, T z)
+ {
+ this->x = x;
+ this->y = y;
+ this->z = z;
+ }
+
+
+ static Vector3Template zero;
+ static Vector3Template one;
+
+};
+
+template<typename T>
+Vector3Template<T> Vector3Template<T>::zero = Vector3Template(0, 0, 0);
+template<typename T>
+Vector3Template<T> Vector3Template<T>::one = Vector3Template(1, 1, 1);
+
+using Vector3f = Vector3Template<float>;
+
diff --git a/Client/Source/Math/Vector4.hpp b/Client/Source/Math/Vector4.hpp
new file mode 100644
index 0000000..8fbf7e6
--- /dev/null
+++ b/Client/Source/Math/Vector4.hpp
@@ -0,0 +1,33 @@
+#pragma once
+
+template<typename T>
+struct Vector4Template
+{
+ T x, y, z, w;
+
+ Vector4Template(T x = 0, T y = 0, T z = 0, T w = 0)
+ {
+ this->x = x;
+ this->y = y;
+ this->z = z;
+ this->w = w;
+ }
+
+ inline void Set(T x, T y, T z, T w)
+ {
+ this->x = x;
+ this->y = y;
+ this->z = z;
+ this->w = w;
+ }
+
+ static Vector4Template zero;
+ static Vector4Template one;
+};
+
+template<typename T>
+Vector4Template<T> Vector4Template<T>::zero = Vector4Template(0, 0, 0, 0);
+template<typename T>
+Vector4Template<T> Vector4Template<T>::one = Vector4Template(1, 1, 1, 1);
+
+using Vector4f = Vector4Template<float>; \ No newline at end of file