added alignment

This commit is contained in:
Jorijn van der Graaf 2026-02-05 01:18:05 +01:00
commit 5b9b9dc472
3 changed files with 106 additions and 946 deletions

View file

@ -1,12 +1,11 @@
/* /*
Crafter.Math Crafter®.Math
Copyright (C) 2026 Catcrafts Copyright (C) 2026 Catcrafts®
Catcrafts.net catcrafts.net
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either License version 3.0 as published by the Free Software Foundation;
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, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of

View file

@ -80,8 +80,9 @@ namespace Crafter {
m[2][3] = w2; m[2][3] = w2;
} }
Vector<T, 3> operator*(Vector<T, 3> b) const requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as<T, float>) { template <std::uint32_t VAligment>
return Vector<T, 3>( Vector<T, 3, VAligment> operator*(Vector<T, 3, VAligment> b) const requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as<T, float>) {
return Vector<T, 3, VAligment>(
b.x * m[0][0] + b.y * m[1][0] + b.z * m[2][0] + m[3][0], b.x * m[0][0] + b.y * m[1][0] + b.z * m[2][0] + m[3][0],
b.x * m[0][1] + b.y * m[1][1] + b.z * m[2][1] + m[3][1], b.x * m[0][1] + b.y * m[1][1] + b.z * m[2][1] + m[3][1],
b.x * m[0][2] + b.y * m[1][2] + b.z * m[2][2] + m[3][2] b.x * m[0][2] + b.y * m[1][2] + b.z * m[2][2] + m[3][2]
@ -178,7 +179,8 @@ namespace Crafter {
0, 0, z, 0 0, 0, z, 0
); );
} }
static MatrixRowMajor<T, CollumSize, RowSize, Repeats> Scaling(Vector<float, 3> vector) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as<T, float>) { template <std::uint32_t VAligment>
static MatrixRowMajor<T, CollumSize, RowSize, Repeats> Scaling(Vector<float, 3, VAligment> vector) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as<T, float>) {
return Scaling(vector.x, vector.y, vector.z); return Scaling(vector.x, vector.y, vector.z);
} }
@ -197,7 +199,9 @@ namespace Crafter {
0, 0, 1, z 0, 0, 1, z
); );
} }
static MatrixRowMajor<T, CollumSize, RowSize, Repeats> Translation(Vector<float, 3> vector) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as<T, float>) {
template <std::uint32_t VAligment>
static MatrixRowMajor<T, CollumSize, RowSize, Repeats> Translation(Vector<T, 3, VAligment> vector) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as<T, float>) {
return Translation(vector.x, vector.y, vector.z); return Translation(vector.x, vector.y, vector.z);
} }
@ -264,24 +268,26 @@ namespace Crafter {
return M; return M;
} }
static MatrixRowMajor<T, CollumSize, RowSize, Repeats> LookAt(Vector<float, 3> eyePosition, Vector<float, 3> focusPosition, Vector<float, 3> upDirection) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as<T, float>) { template <std::uint32_t VAligment>
static MatrixRowMajor<T, CollumSize, RowSize, Repeats> LookAt(Vector<T, 3, VAligment> eyePosition, Vector<T, 3, VAligment> focusPosition, Vector<T, 3, VAligment> upDirection) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as<T, float>) {
MatrixRowMajor<T, CollumSize, RowSize, Repeats> M; MatrixRowMajor<T, CollumSize, RowSize, Repeats> M;
Vector<float, 3> negEyeDirection = eyePosition - focusPosition; Vector<T, 3, VAligment> negEyeDirection = eyePosition - focusPosition;
return LookTo(eyePosition, negEyeDirection, upDirection); return LookTo(eyePosition, negEyeDirection, upDirection);
return M; return M;
} }
static MatrixRowMajor<T, CollumSize, RowSize, Repeats> LookTo(Vector<float, 3> eyePosition, Vector<float, 3> eyeDirection, Vector<float, 3> upDirection) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as<T, float>) { template <std::uint32_t VAligment>
Vector<float, 3> R2 = eyeDirection.Normalize(); static MatrixRowMajor<T, CollumSize, RowSize, Repeats> LookTo(Vector<T, 3, VAligment> eyePosition, Vector<T, 3, VAligment> eyeDirection, Vector<T, 3, VAligment> upDirection) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as<T, float>) {
Vector<T, 3, 3> R2 = eyeDirection.Normalize();
Vector<float, 3> R0 = upDirection.Cross(R2); Vector<T, 3, 3> R0 = upDirection.Cross(R2);
R0 = R0.Normalize(); R0 = R0.Normalize();
Vector<float, 3> R1 = R2.Cross(R0); Vector<T, 3, 3> R1 = R2.Cross(R0);
Vector<float, 3> NegEyePosition = -eyePosition; Vector<T, 3, 3> NegEyePosition = -eyePosition;
float D0 = R0.Dot(NegEyePosition); float D0 = R0.Dot(NegEyePosition);
float D1 = R1.Dot(NegEyePosition); float D1 = R1.Dot(NegEyePosition);
@ -311,18 +317,20 @@ namespace Crafter {
return M; return M;
} }
static MatrixRowMajor<T, CollumSize, RowSize, Repeats> Rotation(Vector<float, 3> vector) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as<T, float>) { template <std::uint32_t VAligment>
static MatrixRowMajor<T, CollumSize, RowSize, Repeats> Rotation(Vector<T, 3, VAligment> vector) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as<T, float>) {
return Rotation(vector.x, vector.y, vector.z); return Rotation(vector.x, vector.y, vector.z);
} }
Vector<float, 3> TransformNormal(Vector<float, 3> V) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as<T, float>) { template <std::uint32_t VAligment>
Vector<float, 3> Z = Vector<float, 3>(V.z, V.z, V.z); Vector<T, 3, VAligment> TransformNormal(Vector<T, 3, VAligment> V) requires(CollumSize == 4 && RowSize == 4 && Repeats == 1 && std::same_as<T, float>) {
Vector<float, 3> Y = Vector<float, 3>(V.y, V.y, V.y); Vector<T, 3, 3> Z = Vector<T, 3, 3>(V.z, V.z, V.z);
Vector<float, 3> X = Vector<float, 3>(V.x, V.x, V.x); Vector<T, 3, 3> Y = Vector<T, 3, 3>(V.y, V.y, V.y);
Vector<T, 3, 3> X = Vector<T, 3, 3>(V.x, V.x, V.x);
Vector<float, 3> Result = Z * Vector<float, 3>(m[2][0], m[2][1], m[2][2]); Vector<T, 3, VAligment> Result = Z * Vector<T, 3, VAligment>(m[2][0], m[2][1], m[2][2]);
Result = Y * Vector<float, 3>(m[1][0], m[1][1], m[1][2]) + Result; Result = Y * Vector<T, 3, VAligment>(m[1][0], m[1][1], m[1][2]) + Result;
Result = X * Vector<float, 3>(m[0][0], m[0][1], m[0][2]) + Result; Result = X * Vector<T, 3, VAligment>(m[0][0], m[0][1], m[0][2]) + Result;
return Result; return Result;
} }

File diff suppressed because it is too large Load diff