3#include <Foundation/Math/Transform.h>
5template <
typename Type>
8 : m_vPosition(vPosition)
9 , m_qRotation(qRotation)
14template <
typename Type>
18 res.m_vPosition = vPosition;
19 res.m_qRotation = qRotation;
20 res.m_vScale = vScale;
24template <
typename Type>
28 res.m_vPosition.SetZero();
30 res.m_vScale.Set(1.0f);
34template <
typename Type>
47template <
typename Type>
50 const auto invRot = globalTransformParent.m_qRotation.GetInverse();
54 res.m_vPosition = (invRot * (globalTransformChild.m_vPosition - globalTransformParent.m_vPosition)).CompMul(invScale);
55 res.m_qRotation = invRot * globalTransformChild.m_qRotation;
56 res.m_vScale = invScale.CompMul(globalTransformChild.m_vScale);
60template <
typename Type>
63 return globalTransformParent * localTransformChild;
66template <
typename Type>
69 *
this = MakeIdentity();
72template <
typename Type>
75 auto absScale = m_vScale.Abs();
79template <
typename Type>
82 return (m_vScale.x * m_vScale.y * m_vScale.z) < 0.0f;
85template <
typename Type>
88 const Type fEpsilon = plMath::DefaultEpsilon<Type>();
92template <
typename Type>
95 return m_vPosition.IsIdentical(rhs.m_vPosition) && (m_qRotation == rhs.m_qRotation) && m_vScale.IsIdentical(rhs.m_vScale);
98template <
typename Type>
101 return m_vPosition.IsEqual(rhs.m_vPosition, fEpsilon) && m_qRotation.IsEqualRotation(rhs.m_qRotation, fEpsilon) && m_vScale.IsEqual(rhs.m_vScale, fEpsilon);
104template <
typename Type>
107 return m_vPosition.IsValid() && m_qRotation.IsValid(0.005f) && m_vScale.IsValid();
110template <
typename Type>
113 auto result = m_qRotation.GetAsMat4();
116 result.m_fElementsCM[1] *= m_vScale.x;
117 result.m_fElementsCM[2] *= m_vScale.x;
119 result.m_fElementsCM[4] *= m_vScale.y;
120 result.m_fElementsCM[5] *= m_vScale.y;
121 result.m_fElementsCM[6] *= m_vScale.y;
123 result.m_fElementsCM[8] *= m_vScale.z;
124 result.m_fElementsCM[9] *= m_vScale.z;
125 result.m_fElementsCM[10] *= m_vScale.z;
127 result.m_fElementsCM[12] = m_vPosition.x;
128 result.m_fElementsCM[13] = m_vPosition.y;
129 result.m_fElementsCM[14] = m_vPosition.z;
135template <
typename Type>
141template <
typename Type>
147template <
typename Type>
150 const auto scaled = m_vScale.CompMul(v);
151 const auto rotated = m_qRotation * scaled;
152 return m_vPosition + rotated;
155template <
typename Type>
158 const auto scaled = m_vScale.CompMul(v);
159 const auto rotated = m_qRotation * scaled;
163template <
typename Type>
168 r.m_vPosition = t.m_vPosition;
169 r.m_qRotation = q * t.m_qRotation;
170 r.m_vScale = t.m_vScale;
175template <
typename Type>
180 r.m_vPosition = t.m_vPosition;
181 r.m_qRotation = t.m_qRotation * q;
182 r.m_vScale = t.m_vScale;
187template <
typename Type>
193template <
typename Type>
199template <
typename Type>
202 return t.TransformPosition(v);
205template <
typename Type>
210 t.m_vPosition = (t1.m_qRotation * t2.m_vPosition.CompMul(t1.m_vScale)) + t1.m_vPosition;
211 t.m_qRotation = t1.m_qRotation * t2.m_qRotation;
212 t.m_vScale = t1.m_vScale.CompMul(t2.m_vScale);
217template <
typename Type>
223template <
typename Type>
229template <
typename Type>
232 (*this) = GetInverse();
235template <
typename Type>
240 const auto invPos = invRot * (invScale.CompMul(-m_vPosition));
A 3x3 component matrix class.
Definition Mat3.h:9
plResult SetScalingFactors(const plVec3Template< Type > &vXYZ, Type fEpsilon=plMath::DefaultEpsilon< Type >())
Tries to set the three scaling factors in the matrix. Returns PL_FAILURE if the matrix columns cannot...
Definition Mat3_inl.h:473
const plVec3Template< Type > GetScalingFactors() const
Returns the 3 scaling factors that are encoded in the matrix.
Definition Mat3_inl.h:460
A 4x4 component matrix class.
Definition Mat4.h:11
const plVec3Template< Type > GetTranslationVector() const
Returns the first 3 components of the last column.
Definition Mat4_inl.h:430
const plMat3Template< Type > GetRotationalPart() const
Returns the 3x3 rotational and scaling part of the matrix.
Definition Mat4_inl.h:458
Type m_fElementsCM[16]
The matrix as a 16-element Type array (column-major)
Definition Mat4.h:24
Quaternions can be used to represent rotations in 3D space.
Definition Quat.h:19
static plQuatTemplate< float > MakeFromMat3(const plMat3Template< float > &m)
Definition Quat_inl.h:275
static const plQuatTemplate< Type > MakeIdentity()
Static function that returns a quaternion that represents the identity rotation (none).
Definition Quat_inl.h:29
A 3-component vector class.
Definition Vec3.h:9
const plVec3Template< Type > CompDiv(const plVec3Template< Type > &rhs) const
Returns the component-wise division of *this and rhs.
Definition Vec3_inl.h:354
constexpr bool IsEqual(Type lhs, Type rhs, Type fEpsilon)
Checks, whether fValue is in the range [fDesired - fMaxImprecision; fDesired + fMaxImprecision].
Definition Math_inl.h:276
constexpr PL_ALWAYS_INLINE T Max(T f1, T f2)
Returns the greater value, f1 or f2.
Definition Math_inl.h:39
PL_ALWAYS_INLINE void IgnoreResult()
Used to silence compiler warnings, when success or failure doesn't matter.
Definition Types.h:69