From d718dc1cfc04f1eabce48159f258a7f2dc281fc3 Mon Sep 17 00:00:00 2001 From: talha Date: Wed, 15 Jan 2025 14:26:29 +0500 Subject: Added IVec, setting up level editing --- source/math.h | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'source/math.h') diff --git a/source/math.h b/source/math.h index 3f20e43..1d0ebc2 100755 --- a/source/math.h +++ b/source/math.h @@ -33,6 +33,71 @@ r32 clampf(r32 x, r32 bottom, r32 top) // ==== Vector Math ==== +union IVec2 { + struct { + u32 x; + u32 y; + }; + u32 data[2]; + + IVec2 operator+(u32 scaler) { + IVec2 res; + res.x = this->x + scaler; + res.y = this->y + scaler; + + return res; + } + + IVec2 operator+(IVec2 v) { + IVec2 res; + res.x = this->x + v.x; + res.y = this->y + v.y; + + return res; + } + + IVec2 operator-(u32 scaler) { + IVec2 res; + res.x = this->x - scaler; + res.y = this->y - scaler; + + return res; + } + + IVec2 operator-(IVec2 v) { + IVec2 res; + res.x = this->x - v.x; + res.y = this->y - v.y; + + return res; + } + + IVec2 operator*(u32 scaler) { + IVec2 res; + res.x = this->x * scaler; + res.y = this->y * scaler; + + return res; + } + + IVec2 operator*(IVec2 v) { + IVec2 res; + res.x = this->x * v.x; + res.y = this->y * v.y; + + return res; + } + + IVec2 operator/(u32 scaler) { + SDL_assert(scaler != 0); + IVec2 res; + res.x = this->x / scaler; + res.y = this->y / scaler; + + return res; + } +}; + union Vec2 { struct { r32 x; -- cgit v1.2.3