diff --git a/Crafter.Math-BasicTypes.cppm b/Crafter.Math-BasicTypes.cppm index 8e00e87..dcbafdd 100755 --- a/Crafter.Math-BasicTypes.cppm +++ b/Crafter.Math-BasicTypes.cppm @@ -1,6 +1,6 @@ /* Crafter.Math -Copyright (C) 2025 Catcrafts +Copyright (C) 2026 Catcrafts Catcrafts.net This library is free software; you can redistribute it and/or @@ -18,13 +18,9 @@ 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/Crafter.Math-MatrixCollumMajor.cppm b/Crafter.Math-MatrixCollumMajor.cppm deleted file mode 100755 index 7cc999a..0000000 --- a/Crafter.Math-MatrixCollumMajor.cppm +++ /dev/null @@ -1,211 +0,0 @@ -/* -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/Crafter.Math-MatrixRowMajor.cppm b/Crafter.Math-MatrixRowMajor.cppm index 69654ef..c0a4737 100755 --- a/Crafter.Math-MatrixRowMajor.cppm +++ b/Crafter.Math-MatrixRowMajor.cppm @@ -1,12 +1,11 @@ /* -Crafter.Math -Copyright (C) 2025 Catcrafts -Catcrafts.net +Crafter®.Math +Copyright (C) 2026 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. +License version 3.0 as published by the Free Software Foundation; This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -18,24 +17,15 @@ 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]; @@ -69,6 +59,27 @@ 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], @@ -143,6 +154,14 @@ 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( @@ -152,7 +171,13 @@ 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); } @@ -165,20 +190,26 @@ 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 = cosf(Pitch); - float sp = sinf(Pitch); + float cp = std::cosf(Pitch); + float sp = std::sinf(Pitch); - float cy = cosf(Yaw); - float sy = sinf(Yaw); + float cy = std::cosf(Yaw); + float sy = std::sinf(Yaw); - float cr = cosf(Roll); - float sr = sinf(Roll); + float cr = std::cosf(Roll); + float sr = std::sinf(Roll); MatrixRowMajor M; M.m[0][0] = cr * cy + sr * sp * sy; @@ -204,6 +235,35 @@ 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; @@ -251,7 +311,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); } @@ -266,6 +326,93 @@ 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; + // } }; } @@ -279,4 +426,15 @@ 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/Crafter.Math-Misc.cppm b/Crafter.Math-Misc.cppm index 41a65ee..9f88256 100644 --- a/Crafter.Math-Misc.cppm +++ b/Crafter.Math-Misc.cppm @@ -1,12 +1,11 @@ /* -Crafter.Math -Copyright (C) 2025 Catcrafts -Catcrafts.net +Crafter®.Math +Copyright (C) 2026 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. +License version 3.0 as published by the Free Software Foundation; This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -18,13 +17,8 @@ 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/Crafter.Math-Vector.cppm b/Crafter.Math-Vector.cppm index 731c4fc..823fcc1 100755 --- a/Crafter.Math-Vector.cppm +++ b/Crafter.Math-Vector.cppm @@ -1,12 +1,11 @@ /* -Crafter.Math -Copyright (C) 2025 Catcrafts -Catcrafts.net +Crafter®.Math +Copyright (C) 2026 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. +License version 3.0 as published by the Free Software Foundation; This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -18,23 +17,14 @@ 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]; }; @@ -89,7 +79,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) { @@ -105,16 +95,16 @@ namespace Crafter { static Vector QuaternionRotationRollPitchYaw(float Pitch, float Yaw, float Roll) requires(Len == 4) { const float halfpitch = Pitch * 0.5f; - float cp = cosf(halfpitch); - float sp = sinf(halfpitch); + float cp = std::cosf(halfpitch); + float sp = std::sinf(halfpitch); const float halfyaw = Yaw * 0.5f; - float cy = cosf(halfyaw); - float sy = sinf(halfyaw); + float cy = std::cosf(halfyaw); + float sy = std::sinf(halfyaw); const float halfroll = Roll * 0.5f; - float cr = cosf(halfroll); - float sr = sinf(halfroll); + float cr = std::cosf(halfroll); + float sr = std::sinf(halfroll); return Vector( cr * sp * cy + sr * cp * sy, @@ -124,41 +114,41 @@ namespace Crafter { ); } - template + template Vector operator+(Vector b){ Vector resultVector; - for(uint32_t i = 0; i < std::min(Len, Blen); i++) { + for(std::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(uint32_t i = 0; i < std::min(Len, Blen); i++) { + for(std::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(uint32_t i = 0; i < Len; i++) { + for(std::uint32_t i = 0; i < Len; i++) { resultVector.v[i] = -this->v[i]; } return resultVector; } - template + template Vector operator*(Vector b){ Vector resultVector; - for(uint32_t i = 0; i < std::min(Len, Blen); i++) { + for(std::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(uint32_t i = 0; i < std::min(Len, Blen); i++) { + for(std::uint32_t i = 0; i < std::min(Len, Blen); i++) { resultVector.v[i] = this->v[i]/b.v[i]; } return resultVector; @@ -197,7 +187,7 @@ namespace Crafter { float Length() { float Result = LengthSq(); - return sqrtf(Result); + return std::sqrtf(Result); } Vector ReciprocalLength() requires(Len == 3) { @@ -209,9 +199,9 @@ namespace Crafter { Vector ReciprocalSqrt() requires(Len == 3) { return Vector( - 1.f / sqrtf(this->v[0]), - 1.f / sqrtf(this->v[1]), - 1.f / sqrtf(this->v[2]) + 1.f / std::sqrtf(this->v[0]), + 1.f / std::sqrtf(this->v[1]), + 1.f / std::sqrtf(this->v[2]) ); } @@ -271,7 +261,14 @@ 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/Crafter.Math.cppm b/Crafter.Math.cppm index 797104b..340b1e9 100644 --- a/Crafter.Math.cppm +++ b/Crafter.Math.cppm @@ -21,6 +21,5 @@ 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/project.json b/project.json index fd6e3a3..77a85e0 100644 --- a/project.json +++ b/project.json @@ -1,30 +1,21 @@ { - "name": "crafter-math", + "name": "crafter-match", "configurations": [ { "name": "base", - "standard": "c++26", - "source_files": [], - "module_files": ["Crafter.Math-Vector", "Crafter.Math-BasicTypes", "Crafter.Math-MatrixCollumMajor", "Crafter.Math-MatrixRowMajor", "Crafter.Math-Misc", "Crafter.Math"], - "build_dir": "build", - "output_dir": "bin", - "type":"library" + "interfaces": ["Crafter.Math-Vector", "Crafter.Math-BasicTypes", "Crafter.Math-MatrixRowMajor", "Crafter.Math-Misc", "Crafter.Math"], + "implementations": [] + }, + { + "name": "lib", + "extends": ["base"], + "type":"library", + "dependencies": [] }, { "name": "lib-debug", - "extends": ["base"], - "debug": true - }, - { - "name": "lib-release", - "extends": ["base"], - "optimization_level": "3" - }, - { - "name": "develop", - "extends": ["debug"], - "type": "executable", - "source_files": ["main"] + "extends": ["lib"], + "debug": true } ] -} +} \ No newline at end of file