Fixes for coordinate system converter

This commit is contained in:
Georg Hagen
2025-10-26 23:54:06 +01:00
parent 76440bb739
commit 4763767a9b

View File

@@ -13,8 +13,8 @@ namespace OpenVulkano::Math
{ {
class CoordinateSystemConverter class CoordinateSystemConverter
{ {
inline static Math::Matrix4i ROT_XP90 = { 1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1 }; inline static Matrix3i ROT_XP90 = { 1, 0, 0, 0, 0, 1, 0, -1, 0 };
inline static Math::Matrix4i ROT_XN90 = { 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1 }; inline static Matrix3i ROT_XN90 = { 1, 0, 0, 0, 0, -1, 0, 1, 0 };
CoordinateSystem from, to; CoordinateSystem from, to;
public: public:
@@ -85,20 +85,14 @@ namespace OpenVulkano::Math
[[nodiscard]] Matrix<S, T, Q> ConvertUp(const Matrix<S, T, Q>& mat) const [[nodiscard]] Matrix<S, T, Q> ConvertUp(const Matrix<S, T, Q>& mat) const
{ {
if (from.GetUpAxis() == to.GetUpAxis()) return mat; if (from.GetUpAxis() == to.GetUpAxis()) return mat;
Matrix4i* conv; Matrix<3, T, Q> conv((from.GetUpAxis() == CoordinateSystem::UpAxis::Y) ? ROT_XP90 : ROT_XN90);
Matrix4i* inverse;
if (from.GetUpAxis() == CoordinateSystem::UpAxis::Y && to.GetUpAxis() == CoordinateSystem::UpAxis::Z)
{
conv = &ROT_XP90;
inverse = &ROT_XN90;
}
else if (from.GetUpAxis() == CoordinateSystem::UpAxis::Z && to.GetUpAxis() == CoordinateSystem::UpAxis::Y)
{
conv = &ROT_XN90;
inverse = &ROT_XP90;
}
return Matrix<S, T, Q>(*conv) * mat * Matrix<S, T, Q>(*inverse); Matrix<S, T, Q> ret(conv * Matrix<3, T, Q>(mat));
if constexpr (S == 4)
{
ret[3] = { ConvertUp(Vector<3, T, Q>(mat[3])), 1 };
}
return ret;
} }
}; };
} }