diff --git a/interfaces/Crafter.Math-BasicTypes.cppm b/interfaces/Crafter.Math-BasicTypes.cppm index dcbafdd..8e00e87 100755 --- a/interfaces/Crafter.Math-BasicTypes.cppm +++ b/interfaces/Crafter.Math-BasicTypes.cppm @@ -1,6 +1,6 @@ /* Crafter.Math -Copyright (C) 2026 Catcrafts +Copyright (C) 2025 Catcrafts Catcrafts.net This library is free software; you can redistribute it and/or @@ -18,9 +18,13 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +module; + +#include +#include +#include export module Crafter.Math:BasicTypes; -import std; namespace Crafter { diff --git a/interfaces/Crafter.Math-MatrixCollumMajor.cppm b/interfaces/Crafter.Math-MatrixCollumMajor.cppm new file mode 100755 index 0000000..7cc999a --- /dev/null +++ b/interfaces/Crafter.Math-MatrixCollumMajor.cppm @@ -0,0 +1,211 @@ +/* +Crafter.Math +Copyright (C) 2025 Catcrafts +Catcrafts.net + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 3.0 of the License, or (at your option) any later version. + +This library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +module; + +#include +#include +#include +#include +#include +#include +#include + +export module Crafter.Math:MatrixCollumMajor; + +import :BasicTypes; +import :Vector; +import :Misc; + +namespace Crafter { + export template + class MatrixCollumMajor { + public: + T m[CollumSize*Repeats][RowSize]; + + MatrixCollumMajor() = default; + + MatrixCollumMajor( + float x0, float y0, float z0, float w0, + float x1, float y1, float z1, float w1, + float x2, float y2, float z2, float w2, + float x3, float y3, float z3, float w3 + ) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { + m[0][0] = x0; + m[0][1] = x1; + m[0][2] = x2; + m[0][3] = x3; + + m[1][0] = y0; + m[1][1] = y1; + m[1][2] = y2; + m[1][3] = y3; + + m[2][0] = z0; + m[2][1] = z1; + m[2][2] = z2; + m[2][3] = z3; + + m[3][0] = w0; + m[3][1] = w1; + m[3][2] = w2; + m[3][3] = w3; + } + + Vector operator*(Vector b) const requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { + return Vector( + b.x * m[0][0] + b.y * m[0][1] + b.z * m[0][2] + m[0][3], + b.x * m[1][0] + b.y * m[1][1] + b.z * m[1][2] + m[1][3], + b.x * m[2][0] + b.y * m[2][1] + b.z * m[2][2] + m[2][3] + ); + } + + MatrixCollumMajor operator*(MatrixCollumMajor b) const requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { + MatrixCollumMajor result; + + result.m[0][0] = b.m[0][0] * m[0][0] + b.m[1][0] * m[0][1] + b.m[2][0] * m[0][2] + b.m[3][0] * m[0][3]; + result.m[0][1] = b.m[0][1] * m[0][0] + b.m[1][1] * m[0][1] + b.m[2][1] * m[0][2] + b.m[3][1] * m[0][3]; + result.m[0][2] = b.m[0][2] * m[0][0] + b.m[1][2] * m[0][1] + b.m[2][2] * m[0][2] + b.m[3][2] * m[0][3]; + result.m[0][3] = b.m[0][3] * m[0][0] + b.m[1][3] * m[0][1] + b.m[2][3] * m[0][2] + b.m[3][3] * m[0][3]; + + result.m[1][0] = b.m[0][0] * m[1][0] + b.m[1][0] * m[1][1] + b.m[2][0] * m[1][2] + b.m[3][0] * m[1][3]; + result.m[1][1] = b.m[0][1] * m[1][0] + b.m[1][1] * m[1][1] + b.m[2][1] * m[1][2] + b.m[3][1] * m[1][3]; + result.m[1][2] = b.m[0][2] * m[1][0] + b.m[1][2] * m[1][1] + b.m[2][2] * m[1][2] + b.m[3][2] * m[1][3]; + result.m[1][3] = b.m[0][3] * m[1][0] + b.m[1][3] * m[1][1] + b.m[2][3] * m[1][2] + b.m[3][3] * m[1][3]; + + result.m[2][0] = b.m[0][0] * m[2][0] + b.m[1][0] * m[2][1] + b.m[2][0] * m[2][2] + b.m[3][0] * m[2][3]; + result.m[2][1] = b.m[0][1] * m[2][0] + b.m[1][1] * m[2][1] + b.m[2][1] * m[2][2] + b.m[3][1] * m[2][3]; + result.m[2][2] = b.m[0][2] * m[2][0] + b.m[1][2] * m[2][1] + b.m[2][2] * m[2][2] + b.m[3][2] * m[2][3]; + result.m[2][3] = b.m[0][3] * m[2][0] + b.m[1][3] * m[2][1] + b.m[2][3] * m[2][2] + b.m[3][3] * m[2][3]; + + result.m[3][0] = b.m[0][0] * m[3][0] + b.m[1][0] * m[3][1] + b.m[2][0] * m[3][2] + b.m[3][0] * m[3][3]; + result.m[3][1] = b.m[0][1] * m[3][0] + b.m[1][1] * m[3][1] + b.m[2][1] * m[3][2] + b.m[3][1] * m[3][3]; + result.m[3][2] = b.m[0][2] * m[3][0] + b.m[1][2] * m[3][1] + b.m[2][2] * m[3][2] + b.m[3][2] * m[3][3]; + result.m[3][3] = b.m[0][3] * m[3][0] + b.m[1][3] * m[3][1] + b.m[2][3] * m[3][2] + b.m[3][3] * m[3][3]; + + return result; + } + + static MatrixCollumMajor Perspective(float fovAngleY, float aspectRatio, float nearZ, float farZ) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { + MatrixCollumMajor result; + float SinFov; + float CosFov; + XMScalarSinCos(&SinFov, &CosFov, 0.5f * fovAngleY); + + float Height = CosFov / SinFov; + float Width = Height / aspectRatio; + float fRange = farZ / (nearZ - farZ); + + result.m[0][0] = Width; + result.m[1][0] = 0.0f; + result.m[2][0] = 0.0f; + result.m[3][0] = 0.0f; + + result.m[0][1] = 0.0f; + result.m[1][1] = Height; + result.m[2][1] = 0.0f; + result.m[3][1] = 0.0f; + + result.m[0][2] = 0.0f; + result.m[1][2] = 0.0f; + result.m[2][2] = fRange; + result.m[3][2] = -1.0f; + + result.m[0][3] = 0.0f; + result.m[1][3] = 0.0f; + result.m[2][3] = fRange * nearZ; + result.m[3][3] = 0.0f; + return result; + } + + static MatrixCollumMajor Identity() requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { + return MatrixCollumMajor( + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + ); + } + + static MatrixCollumMajor Scaling(float x, float y, float z) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { + return MatrixCollumMajor( + x, 0, 0, 0, + 0, y, 0, 0, + 0, 0, z, 0, + 0, 0, 0, 1 + ); + } + + static MatrixCollumMajor Translation(float x, float y, float z) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { + return MatrixCollumMajor( + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + x, y, z, 1 + ); + } + + static MatrixCollumMajor Rotation(float Pitch, float Yaw, float Roll) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { + float cp = cosf(Pitch); + float sp = sinf(Pitch); + + float cy = cosf(Yaw); + float sy = sinf(Yaw); + + float cr = cosf(Roll); + float sr = sinf(Roll); + + MatrixCollumMajor M; + M.m[0][0] = cr * cy + sr * sp * sy; + M.m[1][0] = sr * cp; + M.m[2][0] = sr * sp * cy - cr * sy; + M.m[3][0] = 0.0f; + + M.m[0][1] = cr * sp * sy - sr * cy; + M.m[1][1] = cr * cp; + M.m[2][1] = sr * sy + cr * sp * cy; + M.m[3][1] = 0.0f; + + M.m[0][2] = cp * sy; + M.m[1][2] = -sp; + M.m[2][2] = cp * cy; + M.m[3][2] = 0.0f; + + M.m[0][3] = 0.0f; + M.m[1][3] = 0.0f; + M.m[2][3] = 0.0f; + M.m[3][3] = 1.0f; + + return M; + } + }; +} + +template <> +struct std::formatter> : std::formatter { + auto format(const Crafter::MatrixCollumMajor& obj, format_context& ctx) const { + return std::formatter::format(std::format("{{{}, {}, {}, {}\n{}, {}, {}, {}\n{}, {}, {}, {}\n{}, {}, {}, {}}}", + obj.m[0][0], obj.m[1][0], obj.m[2][0], obj.m[3][0], + obj.m[0][1], obj.m[1][1], obj.m[2][1], obj.m[3][1], + obj.m[0][2], obj.m[1][2], obj.m[2][2], obj.m[3][2], + obj.m[0][3], obj.m[1][3], obj.m[2][3], obj.m[3][3] + ), ctx); + } +}; \ No newline at end of file diff --git a/interfaces/Crafter.Math-MatrixRowMajor.cppm b/interfaces/Crafter.Math-MatrixRowMajor.cppm index c0a4737..69654ef 100755 --- a/interfaces/Crafter.Math-MatrixRowMajor.cppm +++ b/interfaces/Crafter.Math-MatrixRowMajor.cppm @@ -1,11 +1,12 @@ /* -Crafter®.Math -Copyright (C) 2026 Catcrafts® -catcrafts.net +Crafter.Math +Copyright (C) 2025 Catcrafts +Catcrafts.net This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public -License version 3.0 as published by the Free Software Foundation; +License as published by the Free Software Foundation; either +version 3.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -17,15 +18,24 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +module; + +#include +#include +#include +#include +#include +#include +#include + export module Crafter.Math:MatrixRowMajor; import :BasicTypes; import :Vector; import :Misc; -import std; namespace Crafter { - export template + export template class MatrixRowMajor { public: T m[RowSize][CollumSize*Repeats]; @@ -59,27 +69,6 @@ namespace Crafter { m[3][3] = w3; } - MatrixRowMajor( - float x0, float y0, float z0, float w0, - float x1, float y1, float z1, float w1, - float x2, float y2, float z2, float w2 - ) requires(CollumSize == 4 && RowSize == 3 && Repeats == 1 && std::same_as) { - m[0][0] = x0; - m[0][1] = y0; - m[0][2] = z0; - m[0][3] = w0; - - m[1][0] = x1; - m[1][1] = y1; - m[1][2] = z1; - m[1][3] = w1; - - m[2][0] = x2; - m[2][1] = y2; - m[2][2] = z2; - m[2][3] = w2; - } - Vector operator*(Vector b) const requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { return Vector( b.x * m[0][0] + b.y * m[1][0] + b.z * m[2][0] + m[3][0], @@ -154,14 +143,6 @@ namespace Crafter { 0, 0, 0, 1 ); } - static MatrixRowMajor Identity() requires(CollumSize == 4 && RowSize == 3 && Repeats == 1 && std::same_as) { - return MatrixRowMajor( - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0 - ); - } - static MatrixRowMajor Scaling(float x, float y, float z) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { return MatrixRowMajor( @@ -171,13 +152,7 @@ namespace Crafter { 0, 0, 0, 1 ); } - static MatrixRowMajor Scaling(float x, float y, float z) requires(CollumSize == 4 && RowSize == 3 && Repeats == 1 && std::same_as) { - return MatrixRowMajor( - x, 0, 0, 0, - 0, y, 0, 0, - 0, 0, z, 0 - ); - } + static MatrixRowMajor Scaling(Vector vector) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { return Scaling(vector.x, vector.y, vector.z); } @@ -190,26 +165,20 @@ namespace Crafter { x, y, z, 1 ); } - static MatrixRowMajor Translation(float x, float y, float z) requires(CollumSize == 4 && RowSize == 3 && Repeats == 1 && std::same_as) { - return MatrixRowMajor( - 1, 0, 0, x, - 0, 1, 0, y, - 0, 0, 1, z - ); - } + static MatrixRowMajor Translation(Vector vector) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { return Translation(vector.x, vector.y, vector.z); } static MatrixRowMajor Rotation(float Pitch, float Yaw, float Roll) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { - float cp = std::cosf(Pitch); - float sp = std::sinf(Pitch); + float cp = cosf(Pitch); + float sp = sinf(Pitch); - float cy = std::cosf(Yaw); - float sy = std::sinf(Yaw); + float cy = cosf(Yaw); + float sy = sinf(Yaw); - float cr = std::cosf(Roll); - float sr = std::sinf(Roll); + float cr = cosf(Roll); + float sr = sinf(Roll); MatrixRowMajor M; M.m[0][0] = cr * cy + sr * sp * sy; @@ -235,35 +204,6 @@ namespace Crafter { return M; } - static MatrixRowMajor Rotation(float Pitch, float Yaw, float Roll) requires(CollumSize == 4 && RowSize == 3 && Repeats == 1 && std::same_as) { - float cp = std::cosf(Pitch); - float sp = std::sinf(Pitch); - - float cy = std::cosf(Yaw); - float sy = std::sinf(Yaw); - - float cr = std::cosf(Roll); - float sr = std::sinf(Roll); - - MatrixRowMajor M; - M.m[0][0] = cr * cy + sr * sp * sy; - M.m[0][1] = sr * cp; - M.m[0][2] = sr * sp * cy - cr * sy; - M.m[0][3] = 0.0f; - - M.m[1][0] = cr * sp * sy - sr * cy; - M.m[1][1] = cr * cp; - M.m[1][2] = sr * sy + cr * sp * cy; - M.m[1][3] = 0.0f; - - M.m[2][0] = cp * sy; - M.m[2][1] = -sp; - M.m[2][2] = cp * cy; - M.m[2][3] = 0.0f; - - return M; - } - static MatrixRowMajor LookAt(Vector eyePosition, Vector focusPosition, Vector upDirection) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { MatrixRowMajor M; @@ -311,7 +251,7 @@ namespace Crafter { return M; } - static MatrixRowMajor Rotation(Vector vector) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { + static MatrixRowMajor Rotation(Vector vector) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { return Rotation(vector.x, vector.y, vector.z); } @@ -326,93 +266,6 @@ namespace Crafter { return Result; } - - // MatrixRowMajor Inverse() requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as) { - // Vector V0[4], V1[4]; - // V0[0] = Vector(m[0][2], m[0][2], m[1][2], m[1][2]); - // V1[0] = Vector(m[2][3], m[3][3], m[2][3], m[3][3]); - // V0[1] = Vector(m[0][0], m[0][0], m[1][0], m[1][0]); - // V1[1] = Vector(m[2][1], m[3][1], m[2][1], m[3][1]); - // V0[2] = Vector(m[0][2], m[2][2], m[0][0], m[2][0]); - // V1[2] = Vector(m[1][3], m[3][3], m[1][1], m[3][1]); - - // Vector D0 = V0[0] * V1[0]; - // Vector D1 = V0[1] * V1[1]; - // Vector D2 = V0[2] * V1[2]; - - // V0[0] = Vector(m[2][2], m[3][2], m[2][2], m[3][2]); - // V1[0] = Vector(m[0][3], m[0][3], m[1][3], m[1][3]); - // V0[1] = Vector(m[2][0], m[3][0], m[2][0], m[3][0]); - // V1[1] = Vector(m[0][1], m[0][1], m[1][1], m[1][1]); - // V0[2] = Vector(m[1][2], m[3][2], m[1][0], m[3][0]); - // V1[2] = Vector(m[0][3], m[2][3], m[0][1], m[2][1]); - - // D0 = Vector::NegativeMultiplySubtract(V0[0], V1[0], D0); - // D1 = Vector::NegativeMultiplySubtract(V0[1], V1[1], D1); - // D2 = Vector::NegativeMultiplySubtract(V0[2], V1[2], D2); - - // V0[0] = Vector(m[1][1], m[2][1], m[0][1], m[1][1]); - // V1[0] = Vector(D2.v[1], D0.v[1], D0.v[3], D0.v[0]); - // V0[1] = Vector(m[2][0], m[0][0], m[1][0], m[0][0]); - // V1[1] = Vector(D0.v[3], D2.v[1], D0.v[1], D0.v[2]); - // V0[2] = Vector(m[1][3], m[2][3], m[0][3], m[1][3]); - // V1[2] = Vector(D2.v[3], D1.v[1], D1.v[3], D1.v[0]); - // V0[3] = Vector(m[2][2], m[0][2], m[1][2], m[0][2]); - // V1[3] = Vector(D1.v[3], D2.v[3], D1.v[1], D1.v[2]); - - // Vector C0 = V0[0] * V1[0]; - // Vector C2 = V0[1] * V1[1]; - // Vector C4 = V0[2] * V1[2]; - // Vector C6 = V0[3] * V1[3]; - - // V0[0] = Vector(m[2][1], m[3][1], m[1][1], m[2][1]); - // V1[0] = Vector(D0.v[3], D0.v[0], D0.v[1], D2.v[0]); - // V0[1] = Vector(m[3][0], m[2][0], m[3][0], m[1][0]); - // V1[1] = Vector(D0.v[2], D0.v[1], D2.v[0], D0.v[0]); - // V0[2] = Vector(m[2][3], m[3][3], m[1][3], m[2][3]); - // V1[2] = Vector(D1.v[3], D1.v[0], D1.v[1], D2.v[2]); - // V0[3] = XMVectorSwizzle(MT.r[2]); - // V1[3] = XMVectorPermute(D1, D2); - - // C0 = XMVectorNegativeMultiplySubtract(V0[0], V1[0], C0); - // C2 = XMVectorNegativeMultiplySubtract(V0[1], V1[1], C2); - // C4 = XMVectorNegativeMultiplySubtract(V0[2], V1[2], C4); - // C6 = XMVectorNegativeMultiplySubtract(V0[3], V1[3], C6); - - // V0[0] = XMVectorSwizzle(MT.r[1]); - // V1[0] = XMVectorPermute(D0, D2); - // V0[1] = XMVectorSwizzle(MT.r[0]); - // V1[1] = XMVectorPermute(D0, D2); - // V0[2] = XMVectorSwizzle(MT.r[3]); - // V1[2] = XMVectorPermute(D1, D2); - // V0[3] = XMVectorSwizzle(MT.r[2]); - // V1[3] = XMVectorPermute(D1, D2); - - // XMVECTOR C1 = XMVectorNegativeMultiplySubtract(V0[0], V1[0], C0); - // C0 = XMVectorMultiplyAdd(V0[0], V1[0], C0); - // XMVECTOR C3 = XMVectorMultiplyAdd(V0[1], V1[1], C2); - // C2 = XMVectorNegativeMultiplySubtract(V0[1], V1[1], C2); - // XMVECTOR C5 = XMVectorNegativeMultiplySubtract(V0[2], V1[2], C4); - // C4 = XMVectorMultiplyAdd(V0[2], V1[2], C4); - // XMVECTOR C7 = XMVectorMultiplyAdd(V0[3], V1[3], C6); - // C6 = XMVectorNegativeMultiplySubtract(V0[3], V1[3], C6); - - // XMMATRIX R; - // R.r[0] = XMVectorSelect(C0, C1, g_XMSelect0101.v); - // R.r[1] = XMVectorSelect(C2, C3, g_XMSelect0101.v); - // R.r[2] = XMVectorSelect(C4, C5, g_XMSelect0101.v); - // R.r[3] = XMVectorSelect(C6, C7, g_XMSelect0101.v); - - // XMVECTOR Determinant = XMVector4Dot(R.r[0], MT.r[0]); - // XMVECTOR Reciprocal = XMVectorReciprocal(Determinant); - - // XMMATRIX Result; - // Result.r[0] = XMVectorMultiply(R.r[0], Reciprocal); - // Result.r[1] = XMVectorMultiply(R.r[1], Reciprocal); - // Result.r[2] = XMVectorMultiply(R.r[2], Reciprocal); - // Result.r[3] = XMVectorMultiply(R.r[3], Reciprocal); - // return Result; - // } }; } @@ -426,15 +279,4 @@ struct std::formatter> : std::formatter< obj.m[3][0], obj.m[3][1], obj.m[3][2], obj.m[3][3] ), ctx); } -}; - -template <> -struct std::formatter> : std::formatter { - auto format(const Crafter::MatrixRowMajor& obj, format_context& ctx) const { - return std::formatter::format(std::format("{{{}, {}, {}, {}\n{}, {}, {}, {}\n{}, {}, {}, {}}}", - obj.m[0][0], obj.m[0][1], obj.m[0][2], obj.m[0][3], - obj.m[1][0], obj.m[1][1], obj.m[1][2], obj.m[1][3], - obj.m[2][0], obj.m[2][1], obj.m[2][2], obj.m[2][3] - ), ctx); - } }; \ No newline at end of file diff --git a/interfaces/Crafter.Math-Misc.cppm b/interfaces/Crafter.Math-Misc.cppm index 9f88256..41a65ee 100644 --- a/interfaces/Crafter.Math-Misc.cppm +++ b/interfaces/Crafter.Math-Misc.cppm @@ -1,11 +1,12 @@ /* -Crafter®.Math -Copyright (C) 2026 Catcrafts® -catcrafts.net +Crafter.Math +Copyright (C) 2025 Catcrafts +Catcrafts.net This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public -License version 3.0 as published by the Free Software Foundation; +License as published by the Free Software Foundation; either +version 3.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -17,8 +18,13 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +module; + +#include +#include +#include + export module Crafter.Math:Misc; -import std; export namespace Crafter { //------------------------------------------------------------------------------------- diff --git a/interfaces/Crafter.Math-Vector.cppm b/interfaces/Crafter.Math-Vector.cppm index 823fcc1..731c4fc 100755 --- a/interfaces/Crafter.Math-Vector.cppm +++ b/interfaces/Crafter.Math-Vector.cppm @@ -1,11 +1,12 @@ /* -Crafter®.Math -Copyright (C) 2026 Catcrafts® -catcrafts.net +Crafter.Math +Copyright (C) 2025 Catcrafts +Catcrafts.net This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public -License version 3.0 as published by the Free Software Foundation; +License as published by the Free Software Foundation; either +version 3.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -17,14 +18,23 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +module; + +#include +#include +#include +#include +#include +#include +#include + export module Crafter.Math:Vector; -import std; import :BasicTypes; import :Misc; namespace Crafter { - template + template struct VectorBase { T v[Len]; }; @@ -79,7 +89,7 @@ namespace Crafter { VectorBase() = default; }; - export template + export template class Vector : public VectorBase { public: Vector(float x, float y, float z, float w ) requires(std::same_as && Len == 4) : VectorBase(x, y, z, w) { @@ -95,16 +105,16 @@ namespace Crafter { static Vector QuaternionRotationRollPitchYaw(float Pitch, float Yaw, float Roll) requires(Len == 4) { const float halfpitch = Pitch * 0.5f; - float cp = std::cosf(halfpitch); - float sp = std::sinf(halfpitch); + float cp = cosf(halfpitch); + float sp = sinf(halfpitch); const float halfyaw = Yaw * 0.5f; - float cy = std::cosf(halfyaw); - float sy = std::sinf(halfyaw); + float cy = cosf(halfyaw); + float sy = sinf(halfyaw); const float halfroll = Roll * 0.5f; - float cr = std::cosf(halfroll); - float sr = std::sinf(halfroll); + float cr = cosf(halfroll); + float sr = sinf(halfroll); return Vector( cr * sp * cy + sr * cp * sy, @@ -114,41 +124,41 @@ namespace Crafter { ); } - template + template Vector operator+(Vector b){ Vector resultVector; - for(std::uint32_t i = 0; i < std::min(Len, Blen); i++) { + for(uint32_t i = 0; i < std::min(Len, Blen); i++) { resultVector.v[i] = this->v[i]+b.v[i]; } return resultVector; } - template + template Vector operator-(Vector b){ Vector resultVector; - for(std::uint32_t i = 0; i < std::min(Len, Blen); i++) { + for(uint32_t i = 0; i < std::min(Len, Blen); i++) { resultVector.v[i] = this->v[i]-b.v[i]; } return resultVector; } Vector operator-(){ Vector resultVector; - for(std::uint32_t i = 0; i < Len; i++) { + for(uint32_t i = 0; i < Len; i++) { resultVector.v[i] = -this->v[i]; } return resultVector; } - template + template Vector operator*(Vector b){ Vector resultVector; - for(std::uint32_t i = 0; i < std::min(Len, Blen); i++) { + for(uint32_t i = 0; i < std::min(Len, Blen); i++) { resultVector.v[i] = this->v[i]*b.v[i]; } return resultVector; } - template + template Vector operator/(Vector b){ Vector resultVector; - for(std::uint32_t i = 0; i < std::min(Len, Blen); i++) { + for(uint32_t i = 0; i < std::min(Len, Blen); i++) { resultVector.v[i] = this->v[i]/b.v[i]; } return resultVector; @@ -187,7 +197,7 @@ namespace Crafter { float Length() { float Result = LengthSq(); - return std::sqrtf(Result); + return sqrtf(Result); } Vector ReciprocalLength() requires(Len == 3) { @@ -199,9 +209,9 @@ namespace Crafter { Vector ReciprocalSqrt() requires(Len == 3) { return Vector( - 1.f / std::sqrtf(this->v[0]), - 1.f / std::sqrtf(this->v[1]), - 1.f / std::sqrtf(this->v[2]) + 1.f / sqrtf(this->v[0]), + 1.f / sqrtf(this->v[1]), + 1.f / sqrtf(this->v[2]) ); } @@ -261,14 +271,7 @@ namespace Crafter { return N * Scale; } - static Vector NegativeMultiplySubtract(Vector a, Vector b, Vector c) requires(Len == 4) { - return Vector( - c.v[0] - (a.v[0] * b.v[0]), - c.v[1] - (a.v[1] * b.v[1]), - c.v[2] - (a.v[2] * b.v[2]), - c.v[3] - (a.v[3] * b.v[3]) - ); - } + diff --git a/interfaces/Crafter.Math.cppm b/interfaces/Crafter.Math.cppm index 340b1e9..797104b 100644 --- a/interfaces/Crafter.Math.cppm +++ b/interfaces/Crafter.Math.cppm @@ -21,5 +21,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA export module Crafter.Math; export import :BasicTypes; export import :Vector; +export import :MatrixCollumMajor; export import :MatrixRowMajor; export import :Misc; \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b96fa93 --- /dev/null +++ b/main.cpp @@ -0,0 +1,13 @@ +#include +#include +#include +#include +#include + +import Crafter.Math; +using namespace Crafter; + + +int main() { + +} \ No newline at end of file diff --git a/project.json b/project.json index de8a6f9..d624247 100644 --- a/project.json +++ b/project.json @@ -1,21 +1,19 @@ { - "name": "crafter-match", + "name": "crafter-math", "configurations": [ { "name": "base", - "interfaces": ["interfaces/Crafter.Math-Vector", "interfaces/Crafter.Math-BasicTypes", "interfaces/Crafter.Math-MatrixRowMajor", "interfaces/Crafter.Math-Misc", "interfaces/Crafter.Math"], - "implementations": [] - }, - { - "name": "lib", - "extends": ["base"], - "type":"library", - "dependencies": [] + "interfaces": ["interfaces/Crafter.Math-Vector", "interfaces/Crafter.Math-BasicTypes", "interfaces/Crafter.Math-MatrixCollumMajor", "interfaces/Crafter.Math-MatrixRowMajor", "interfaces/Crafter.Math-Misc", "interfaces/Crafter.Math"], + "type":"library" }, { "name": "lib-debug", - "extends": ["lib"], - "debug": true + "extends": ["base"], + "debug": true + }, + { + "name": "lib", + "extends": ["base"] } ] -} \ No newline at end of file +}