From 60cbbdec07ab7a5636eac5b3c024ae44e937f4d4 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 13 Dec 2021 00:07:19 +0800 Subject: +init --- Client/Source/Math/Vector2.hpp | 67 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Client/Source/Math/Vector2.hpp (limited to 'Client/Source/Math/Vector2.hpp') 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 +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 operator - (const Vector2Template& v) const + { + Vector2Template res = Vector2Template(x - v.x, y - v.y); + return res; + } + + + float x, y; + + static Vector2Template zero; + static Vector2Template one ; + +}; + +using Vector2f = Vector2Template; +using Vector2i = Vector2Template; + + +template +Vector2Template Vector2Template::zero = Vector2Template(0, 0); +template +Vector2Template Vector2Template::one = Vector2Template(1, 1); -- cgit v1.1-26-g67d0