From c775ca6133d93ed97359a6a50bd94a5563c740de Mon Sep 17 00:00:00 2001 From: fschildt Date: Wed, 1 Oct 2025 14:08:24 +0200 Subject: general refactoring, prepare breakout game --- src/common/math.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/common/math.cpp (limited to 'src/common/math.cpp') diff --git a/src/common/math.cpp b/src/common/math.cpp new file mode 100644 index 0000000..ba54f3a --- /dev/null +++ b/src/common/math.cpp @@ -0,0 +1,95 @@ +#include + + +/* V2ST */ + +bool +V2ST::operator==(V2ST& b) +{ + bool result = this->x == b.x && this->y == b.y; + return result; +} + + + +/* V2F32 */ + +V2F32 +V2F32::operator/(float scalar) +{ + V2F32 result {}; + result.x = this->x / scalar; + result.y = this->y / scalar; + return result; +} + +V2F32 +V2F32::operator*(float scalar) +{ + V2F32 result {}; + result.x = this->x * scalar; + result.y = this->y * scalar; + return result; +} + +V2F32 V2F32::operator+(V2F32 other) { + V2F32 result {}; + result.x = this->x + other.x; + result.y = this->y + other.y; + return result; +} + + +/* V3F32 */ + +V3F32 V3F32::operator/(float scalar) { + V3F32 result = {}; + result.x = this->x / scalar; + result.y = this->y / scalar; + result.z = this->z / scalar; + return result; +} + +V3F32 V3F32::operator*(float scalar) { + V3F32 result = {}; + result.x = this->x * scalar; + result.y = this->y * scalar; + result.z = this->z * scalar; + return result; +} + + +/* V4F32 */ + +V4F32 +V4F32::operator/(float scalar) +{ + V4F32 result {}; + result.x = this->x / scalar; + result.y = this->y / scalar; + result.z = this->z / scalar; + result.w = this->w / scalar; + return result; +} + +V4F32 +V4F32::operator*(float scalar) +{ + V4F32 result {}; + result.x = this->x * scalar; + result.y = this->y * scalar; + result.z = this->z * scalar; + result.w = this->z * scalar; + return result; +} + + +/* V2I32 */ + +bool +V2I32::operator==(V2I32 other) +{ + bool result = x == other.x && y == other.y; + return result; +} + -- cgit v1.2.3