1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00
luanti/irr/include/Transform.h

55 lines
1,001 B
C
Raw Normal View History

2025-01-20 02:39:14 +01:00
#pragma once
#include "irrMath.h"
#include <matrix4.h>
#include <vector3d.h>
#include <quaternion.h>
namespace irr
{
namespace core
{
struct Transform {
vector3df translation;
quaternion rotation;
vector3df scale{1};
// Tries to decompose the matrix, if there is one.
static Transform decompose(const core::matrix4 &mat)
{
auto scale = mat.getScale();
return {
mat.getTranslation(),
2025-03-19 14:58:32 +01:00
quaternion(mat.getRotationRadians(scale)),
2025-01-20 02:39:14 +01:00
scale,
};
}
2025-01-26 17:38:50 +01:00
Transform interpolate(Transform to, f32 time) const
{
core::quaternion interpolated_rotation;
interpolated_rotation.slerp(rotation, to.rotation, time);
return {
to.translation.getInterpolated(translation, time),
interpolated_rotation,
to.scale.getInterpolated(scale, time),
};
}
2025-01-20 02:39:14 +01:00
matrix4 buildMatrix() const
{
matrix4 T;
T.setTranslation(translation);
matrix4 R;
rotation.getMatrix_transposed(R);
matrix4 S;
S.setScale(scale);
return T * R * S;
}
};
} // end namespace core
2025-01-26 17:38:50 +01:00
} // end namespace irr