29inline void TransformRT::WarnIfRotationNotNormalized()
const {
32#if MOCHI_ASSERT_VERBOSE_ENABLED && MOCHI_LOG_ENABLED
33 auto norm =
Norm(_rotation);
36 "TransformRT expects a unit length quaternion, but got [%g, %g, %g, %g] (magnitude %g).",
47 : _rotation(rotation), _translation(
ToReal3(translation)) {
48 WarnIfRotationNotNormalized();
52 : _rotation(rotation), _translation(translation) {
53 WarnIfRotationNotNormalized();
57 WarnIfRotationNotNormalized();
61 : _translation(
ToReal3(translation)) {}
83 WarnIfRotationNotNormalized();
87 return ToSimd(_translation, 1_r);
95 _translation =
ToReal3(translation);
99 _translation = translation;
103 return _rotation == rhs._rotation && _translation == rhs._translation;
107 return !(*
this == rhs);
117 *
this = (*this) * rhs;
160 q *
Vec4r(1.0_r, 0.0_r, 0.0_r),
161 q *
Vec4r(0.0_r, 1.0_r, 0.0_r),
162 q *
Vec4r(0.0_r, 0.0_r, 1.0_r),
212 auto translation =
ToReal3(matrixT[3]);
220 auto determinant =
Det3x3(matrixT);
221 if (determinant < 0_r) {
222 scale[0] = -scale[0];
226 matrixT[0] /= scale[0] + std::numeric_limits<real>::min();
227 matrixT[1] /= scale[1] + std::numeric_limits<real>::min();
228 matrixT[2] /= scale[2] + std::numeric_limits<real>::min();
231 for (
int i = 0; i < 3; ++i) {
232 int const j = (i + 1) % 3;
233 int const k = (i + 2) % 3;
234 if (scale[i] == 0_r && scale[j] != 0_r && scale[k] != 0_r) {
235 matrixT[i] =
Cross3(matrixT[j], matrixT[k]);
236 }
else if (scale[i] != 0_r && scale[j] == 0_r && scale[k] == 0_r) {
238 matrixT[k] =
Cross3(matrixT[i], matrixT[j]);
243 return std::make_pair(scale,
TransformRT{rotation, translation});
#define MOCHI_LOG_WARNING(...)
Quaternion Slerp(Quaternion a, Quaternion b, real t)
Simd< T, N > VIsFinite(Simd< T, N > a)
Simd< T, 4 > ToSimd(NdArray< T, 2 > const &v, T z=T(0), T w=T(0))
Simd< T, N > Cross3(Simd< T, N > a, Simd< T, N > b)
Real3 ToReal3(Simd< T, 4 > v)
NdArray< Simd< T, 4 >, 3 > Transpose3x3(NdArray< Simd< T, 4 >, D0 > const &m)
std::pair< Real3, TransformRT > DecomposeMatrixTransform(VMatrix4x4r const &matrixTransform)
NdArray< Simd< real, 4 >, 4 > VMatrix4x4r
Simd< T, N > Normalize(Simd< T, N > a)
TransformRT Invert(TransformRT const &a)
VMatrix4x4r ToVMatrix4x4(TransformRT const &a)
NdArray< Simd< T, 4 >, 4 > Transpose4x4(NdArray< Simd< T, 4 >, 4 > const &m)
Quaternion Conjugate(Quaternion const &a)
Simd< T, 4 > OrthogonalVector3(Simd< T, 4 > a)
TransformRT Repivot(TransformRT const &transform, Real3 const &pivot)
VMatrix4x4r ToVMatrix4x4Transpose(TransformRT const &a)
TransformRT NormalizeRotation(TransformRT const &a)
TransformRT Interpolate(TransformRT const &a, TransformRT const &b, real t)
bool NearEqual(TransformRT const &a, TransformRT const &b, real epsilon=kDefaultNearEqualEpsilon< real >)
T Det3x3(NdArray< Simd< T, 4 >, N > const &A)
Quaternion QuaternionFromMatrix(VMatrix3x3r const &matrix)
bool IsFinite(TransformRT const &a)