diff --git a/Src/IAMath/CMakeLists.txt b/Src/IAMath/CMakeLists.txt index 2428b94..ad45604 100644 --- a/Src/IAMath/CMakeLists.txt +++ b/Src/IAMath/CMakeLists.txt @@ -1,4 +1,6 @@ add_library(IAMath STATIC imp/cpp/dummy.cpp) -target_include_directories(IAMath PUBLIC inc/hpp imp/inl) +target_include_directories(IAMath PUBLIC inc/ imp/inl) + +target_link_libraries(IAMath PUBLIC IACore) diff --git a/Src/IAMath/inc/IAMath/Lerp.hpp b/Src/IAMath/inc/IAMath/Lerp.hpp new file mode 100644 index 0000000..f778df7 --- /dev/null +++ b/Src/IAMath/inc/IAMath/Lerp.hpp @@ -0,0 +1,26 @@ +// IAMath; The Math Library for All IA Projects +// Copyright (C) 2025 IAS (ias@iasoft.dev) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include + +namespace ia::iam +{ + template + _value_type Lerp(IN CONST _value_type& v1, IN CONST _value_type& v2, IN FLOAT32 t) + { + return v1 + (v2 - v1) * t; + } +} \ No newline at end of file diff --git a/Src/IAMath/inc/IAMath/Vec.hpp b/Src/IAMath/inc/IAMath/Vec.hpp index 703e2ae..1488e61 100644 --- a/Src/IAMath/inc/IAMath/Vec.hpp +++ b/Src/IAMath/inc/IAMath/Vec.hpp @@ -1,16 +1,199 @@ -// IAMath; The Math Library for All IA Projects +// IAMath; The Math Library for All IA Projects // Copyright (C) 2025 IAS (ias@iasoft.dev) -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + +namespace ia::iam +{ + template + struct Vec2 + { + union { + struct { + _value_type Data[2]; + }; + struct { + _value_type X{}, Y{}; + }; + struct { + _value_type U, V; + }; + struct { + _value_type x, y; + }; + struct { + _value_type u, v; + }; + }; + + Vec2 operator+(IN CONST Vec2<_value_type>& other) + { + return { X + other.X, Y + other.Y }; + } + + Vec2 operator-(IN CONST Vec2<_value_type>& other) + { + return { X - other.X, Y - other.Y }; + } + + Vec2 operator*(IN CONST Vec2<_value_type>& other) + { + return { X * other.X, Y * other.Y }; + } + + Vec2 operator/(IN CONST Vec2<_value_type>& other) + { + return { X / other.X, Y / other.Y }; + } + + Vec2 operator*(IN _value_type other) + { + return { X * other, Y * other }; + } + + Vec2 operator/(IN _value_type other) + { + return { X / other, Y / other }; + } + + String ToString() CONST + { + return BuildString("{ X: ", X, ", Y: ", Y, " }"); + } + }; + + template + struct Vec3 + { + union { + struct { + _value_type Data[3]; + }; + struct { + _value_type X{}, Y{}, Z{}; + }; + struct { + _value_type R, G, B; + }; + struct { + _value_type x, y, z; + }; + struct { + _value_type r, g, b; + }; + }; + + Vec3 operator+(IN CONST Vec3<_value_type>& other) + { + return { X + other.X, Y + other.Y, Z + other.Z }; + } + + Vec3 operator-(IN CONST Vec3<_value_type>& other) + { + return { X - other.X, Y - other.Y, Z - other.Z }; + } + + Vec3 operator*(IN CONST Vec3<_value_type>& other) + { + return { X * other.X, Y * other.Y, Z * other.Z }; + } + + Vec3 operator/(IN CONST Vec3<_value_type>& other) + { + return { X / other.X, Y / other.Y, Z / other.Z }; + } + + Vec3 operator*(IN _value_type other) + { + return { X * other, Y * other, Z * other }; + } + + Vec3 operator/(IN _value_type other) + { + return { X / other, Y / other, Z / other }; + } + + String ToString() CONST + { + return BuildString("{ X: ", X, ", Y: ", Y, ", Z: ", Z, " }"); + } + }; + + template + struct Vec4 + { + union { + struct { + _value_type Data[4]; + }; + struct { + _value_type X{}, Y{}, Z{}, W{}; + }; + struct { + _value_type R, G, B, A; + }; + struct { + _value_type x, y, z, w; + }; + struct { + _value_type r, g, b, a; + }; + }; + + Vec4 operator+(IN CONST Vec4<_value_type>& other) + { + return { X + other.X, Y + other.Y, Z + other.Z, W + other.W }; + } + + Vec4 operator-(IN CONST Vec4<_value_type>& other) + { + return { X - other.X, Y - other.Y, Z - other.Z, W - other.W }; + } + + Vec4 operator*(IN CONST Vec4<_value_type>& other) + { + return { X * other.X, Y * other.Y, Z * other.Z, W * other.W }; + } + + Vec4 operator/(IN CONST Vec4<_value_type>& other) + { + return { X / other.X, Y / other.Y, Z / other.Z, W / other.W }; + } + + Vec4 operator*(IN _value_type other) + { + return { X * other, Y * other, Z * other, W * other }; + } + + Vec4 operator/(IN _value_type other) + { + return { X / other, Y / other, Z / other, W / other }; + } + + String ToString() CONST + { + return BuildString("{ X: ", X, ", Y: ", Y, ", Z: ", Z, ", W: ", W, " }"); + } + }; + + using Vec2i = Vec2; + using Vec3i = Vec3; + using Vec4i = Vec4; + + using Vec2f = Vec2; + using Vec3f = Vec3; + using Vec4f = Vec4; +} // namespace ia::iam \ No newline at end of file diff --git a/Src/IAMathTest/imp/cpp/Main.cpp b/Src/IAMathTest/imp/cpp/Main.cpp index b15d0a3..ba38514 100644 --- a/Src/IAMathTest/imp/cpp/Main.cpp +++ b/Src/IAMathTest/imp/cpp/Main.cpp @@ -1,7 +1,13 @@ #include +#include + int main(int argc, char* argv[]) { - + ia::iam::Vec2f a {6, 10}; + ia::iam::Vec2f b {2, 1}; + + printf("%s, %s, %s\n", a.ToString().c_str(), b.ToString().c_str(), (a + b).ToString().c_str()); + return 0; } \ No newline at end of file