diff options
author | chai <chaifix@163.com> | 2021-11-04 12:48:01 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-11-04 12:48:01 +0800 |
commit | 94a9a28de16badb75e66a60efca3b01d31cc0fc6 (patch) | |
tree | a37e09236da2b7cda11a451d6fed4fe37afb065c /Runtime/Math | |
parent | b215d811a1981e20f35bb31df4e6cd2a74146193 (diff) |
* text anchor
Diffstat (limited to 'Runtime/Math')
-rw-r--r-- | Runtime/Math/Math.h | 5 | ||||
-rw-r--r-- | Runtime/Math/MathHelper.h | 2 | ||||
-rw-r--r-- | Runtime/Math/Vector2.h | 34 |
3 files changed, 28 insertions, 13 deletions
diff --git a/Runtime/Math/Math.h b/Runtime/Math/Math.h index 5e08613..80f23f7 100644 --- a/Runtime/Math/Math.h +++ b/Runtime/Math/Math.h @@ -8,8 +8,11 @@ #include "Rect.h" #include "MathHelper.h" -typedef Internal::Vector2 Vector2; typedef Internal::Vector3 Vector3; typedef Internal::Vector4 Vector4; typedef Internal::Matrix44 Matrix44; typedef Internal::Rect Rect; + +typedef Internal::Vector2T<int> Vector2i; +typedef Internal::Vector2T<float> Vector2f; + diff --git a/Runtime/Math/MathHelper.h b/Runtime/Math/MathHelper.h index c41eec9..ad64dcf 100644 --- a/Runtime/Math/MathHelper.h +++ b/Runtime/Math/MathHelper.h @@ -1,7 +1,7 @@ #pragma once #define max(a, b)\ -(a)>(b)?(a):(b) +((a)>(b)?(a):(b)) #define min(a, b)\ (a)<(b)?(a):(b) diff --git a/Runtime/Math/Vector2.h b/Runtime/Math/Vector2.h index 9d7e4e9..f13e522 100644 --- a/Runtime/Math/Vector2.h +++ b/Runtime/Math/Vector2.h @@ -4,47 +4,59 @@ namespace Internal { - struct Vector2 + template<typename T> + struct Vector2T { - Vector2(float x = 0, float y = 0) + Vector2T(T x = 0, T y = 0) { this->x = x; this->y = y; } - inline void Set(float x, float y) + inline void Set(T x, T y) { this->x = x; this->y = y; } - Vector2 Clamp(float xmin, float xmax, float ymin, float ymax) + Vector2T Clamp(T xmin, T xmax, T ymin, T ymax) { - Vector2 v; + Vector2T v; v.x = clamp(x, xmin, xmax); v.y = clamp(y, ymin, ymax); return v; } - float operator[](int i) + T operator[](int i) { if (i == 0) return x; else if (i == 1) return y; Assert(false); } - bool operator == (const Vector2& v) const + bool operator == (const Vector2T& v) const { return v.x == x && v.y == y; } - bool operator != (const Vector2& v) const + bool operator != (const Vector2T& v) const { return v.x != x || v.y != y; } - float x, y; + T x, y; - static Vector2 zero; - static Vector2 one; + static Vector2T<T> zero; + static Vector2T<T> one; }; + + template<typename T> + Vector2T<T> Vector2T<T>::zero = Vector2T(0, 0); + template<typename T> + Vector2T<T> Vector2T<T>::one = Vector2T(1, 1); + + typedef Internal::Vector2T<float> Vector2; + } + +typedef Internal::Vector2T<float> Vector2; + |