From 03c482737dc3fc0303b8676be92c1f5235d18ab6 Mon Sep 17 00:00:00 2001 From: psyGamer Date: Mon, 2 Nov 2026 13:26:00 +0100 Subject: [PATCH] math: Add `slerpTo` matrix function --- include/math/seadMatrix.h | 3 ++ include/math/seadMatrix.hpp | 18 ++++++++++++ include/math/seadMatrixCalcCommon.h | 3 ++ include/math/seadMatrixCalcCommon.hpp | 40 +++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/include/math/seadMatrix.h b/include/math/seadMatrix.h index fd5af108..ce16759b 100644 --- a/include/math/seadMatrix.h +++ b/include/math/seadMatrix.h @@ -81,6 +81,7 @@ class Matrix33 : public Policies::Mtx33Base void setMul(const Self& a, const Mtx34& b); void setTranspose(const Self& n); void transpose(); + void slerpTo(const Self& m1, const Self& m2, f32 t); void fromQuat(const Quat& q); void makeR(const Vec3& r); @@ -169,6 +170,7 @@ class Matrix34 : public Policies::Mtx34Base void setTranspose(const Self& n); void transpose(); + void slerpTo(const Self& m1, const Self& m2, f32 t); void fromQuat(const QuatT& q); void makeQT(const QuatT& q, const Vec3& t); @@ -249,6 +251,7 @@ class Matrix44 : public Policies::Mtx44Base void setMul(const Self& a, const Mtx34& b); void setTranspose(const Self& n); void transpose(); + void slerpTo(const Self& m1, const Self& m2, f32 t); void fromQuat(const Quat& q); void makeR(const Vec3& r); diff --git a/include/math/seadMatrix.hpp b/include/math/seadMatrix.hpp index fd3dfa07..c2e0ed1d 100644 --- a/include/math/seadMatrix.hpp +++ b/include/math/seadMatrix.hpp @@ -173,6 +173,12 @@ inline void Matrix33::transpose() Matrix33CalcCommon::transpose(*this); } +template +inline void Matrix33::slerpTo(const Self& m1, const Self& m2, f32 t) +{ + Matrix33CalcCommon::slerpTo(*this, m1, m2, t); +} + template inline void Matrix33::fromQuat(const Quat& q) { @@ -397,6 +403,12 @@ inline void Matrix34::transpose() Matrix34CalcCommon::transpose(*this); } +template +inline void Matrix34::slerpTo(const Self& m1, const Self& m2, f32 t) +{ + Matrix34CalcCommon::slerpTo(*this, m1, m2, t); +} + template inline void Matrix34::fromQuat(const QuatT& q) { @@ -722,6 +734,12 @@ inline void Matrix44::transpose() Matrix44CalcCommon::transpose(*this); } +template +inline void Matrix44::slerpTo(const Self& m1, const Self& m2, f32 t) +{ + Matrix44CalcCommon::slerpTo(*this, m1, m2, t); +} + template inline void Matrix44::fromQuat(const Quat& q) { diff --git a/include/math/seadMatrixCalcCommon.h b/include/math/seadMatrixCalcCommon.h index 427442d7..7207b6b9 100644 --- a/include/math/seadMatrixCalcCommon.h +++ b/include/math/seadMatrixCalcCommon.h @@ -46,6 +46,7 @@ class Matrix33CalcCommon static void multiply(Base& o, const Base& a, const Mtx34& b); static void transpose(Base& o); static void transposeTo(Base& o, const Base& n); + static void slerpTo(Base& o, const Base& m1, const Base& m2, f32 t); static void makeQ(Base& o, const Quat& q); static void makeR(Base& o, const Vec3& r); @@ -91,6 +92,7 @@ class Matrix34CalcCommon static void multiply(Base& o, const Base& a, const Mtx33& b); static void transpose(Base& o); static void transposeTo(Base& o, const Base& n); + static void slerpTo(Base& o, const Base& m1, const Base& m2, f32 t); static void makeQ(Base& o, const Quat& q); static void makeQT(Base& o, const Quat& q, const Vec3& t); @@ -150,6 +152,7 @@ class Matrix44CalcCommon static void multiply(Base& o, const Base& a, const Mtx34& b); static void transpose(Base& o); static void transposeTo(Base& o, const Base& n); + static void slerpTo(Base& o, const Base& m1, const Base& m2, f32 t); static void makeQ(Base& o, const Quat& q); static void makeR(Base& o, const Vec3& r); diff --git a/include/math/seadMatrixCalcCommon.hpp b/include/math/seadMatrixCalcCommon.hpp index de6a03f2..23a9c063 100644 --- a/include/math/seadMatrixCalcCommon.hpp +++ b/include/math/seadMatrixCalcCommon.hpp @@ -11,6 +11,7 @@ #include #include +#include #ifndef SEAD_MATH_MATRIX_CALC_COMMON_H_ #include #endif @@ -431,6 +432,19 @@ void Matrix33CalcCommon::transposeTo(Base& o, const Base& n) o.m[2][2] = n.m[2][2]; } +template +void Matrix33CalcCommon::slerpTo(Base& o, const Base& m1, const Base& m2, f32 t) +{ + Quat q1, q2; + toQuat(q1, m1); + toQuat(q2, m2); + + Quat qT; + QuatCalcCommon::slerpTo(qT, q1, q2, t); + + makeQ(o, qT); +} + template void Matrix33CalcCommon::makeQ(Base& o, const Quat& q) { @@ -1224,6 +1238,19 @@ void Matrix34CalcCommon::transposeTo(Base& o, const Base& n) #endif // cafe +template +void Matrix34CalcCommon::slerpTo(Base& o, const Base& m1, const Base& m2, f32 t) +{ + Quat q1, q2; + toQuat(q1, m1); + toQuat(q2, m2); + + Quat qT; + QuatCalcCommon::slerpTo(qT, q1, q2, t); + + makeQ(o, qT); +} + template void Matrix34CalcCommon::makeQ(Base& o, const Quat& q) { @@ -2475,6 +2502,19 @@ void Matrix44CalcCommon::transposeTo(Base& o, const Base& n) o.m[3][3] = n.m[3][3]; } +template +void Matrix44CalcCommon::slerpTo(Base& o, const Base& m1, const Base& m2, f32 t) +{ + Quat q1, q2; + toQuat(q1, m1); + toQuat(q2, m2); + + Quat qT; + QuatCalcCommon::slerpTo(qT, q1, q2, t); + + makeQ(o, qT); +} + template void Matrix44CalcCommon::makeQ(Base& o, const Quat& q) {