Plasma Engine  2.0
Loading...
Searching...
No Matches
Transform.h
1#pragma once
2
3#include <Foundation/Math/Mat3.h>
4#include <Foundation/Math/Mat4.h>
5#include <Foundation/Math/Quat.h>
6#include <Foundation/Math/Vec3.h>
7
9
29template <typename Type>
31{
32public:
33 PL_DECLARE_POD_TYPE();
34
35 // *** Data ***
36 plVec3Template<Type> m_vPosition;
37 plQuatTemplate<Type> m_qRotation;
38 plVec3Template<Type> m_vScale;
39
40 // *** Constructors ***
41public:
44
45
49 const plVec3Template<Type>& vScale = plVec3Template<Type>(1)); // [tested]
50
53
55 [[nodiscard]] static plTransformTemplate<Type> MakeIdentity();
56
62 [[nodiscard]] static plTransformTemplate<Type> MakeFromMat4(const plMat4Template<Type>& mMat);
63
65 [[nodiscard]] static plTransformTemplate<Type> MakeLocalTransform(const plTransformTemplate& globalTransformParent, const plTransformTemplate& globalTransformChild); // [tested]
66
68 [[nodiscard]] static plTransformTemplate<Type> MakeGlobalTransform(const plTransformTemplate& globalTransformParent, const plTransformTemplate& localTransformChild); // [tested]
69
71 void SetIdentity(); // [tested]
72
74 Type GetMaxScale() const;
75
77 bool HasMirrorScaling() const;
78
80 bool ContainsUniformScale() const;
81
83 bool IsValid() const;
84
85 // *** Equality ***
86public:
88 bool IsIdentical(const plTransformTemplate& rhs) const; // [tested]
89
91 bool IsEqual(const plTransformTemplate& rhs, Type fEpsilon) const; // [tested]
92
93 // *** Inverse ***
94public:
96 void Invert(); // [tested]
97
99 const plTransformTemplate GetInverse() const; // [tested]
100
101 [[nodiscard]] plVec3Template<Type> TransformPosition(const plVec3Template<Type>& v) const; // [tested]
102 [[nodiscard]] plVec3Template<Type> TransformDirection(const plVec3Template<Type>& v) const; // [tested]
103
104 void operator+=(const plVec3Template<Type>& v); // [tested]
105 void operator-=(const plVec3Template<Type>& v); // [tested]
106
107 // *** Conversion operations ***
108public:
110 const plMat4Template<Type> GetAsMat4() const; // [tested]
111};
112
113// *** free functions ***
114
116template <typename Type>
117const plVec3Template<Type> operator*(const plTransformTemplate<Type>& t, const plVec3Template<Type>& v); // [tested]
118
120template <typename Type>
121const plTransformTemplate<Type> operator*(const plQuatTemplate<Type>& q, const plTransformTemplate<Type>& t); // [tested]
122
124template <typename Type>
126
128template <typename Type>
129const plTransformTemplate<Type> operator+(const plTransformTemplate<Type>& t, const plVec3Template<Type>& v); // [tested]
130
132template <typename Type>
133const plTransformTemplate<Type> operator-(const plTransformTemplate<Type>& t, const plVec3Template<Type>& v); // [tested]
134
136template <typename Type>
137const plTransformTemplate<Type> operator*(const plTransformTemplate<Type>& t1, const plTransformTemplate<Type>& t2); // [tested]
138
139template <typename Type>
140bool operator==(const plTransformTemplate<Type>& t1, const plTransformTemplate<Type>& t2); // [tested]
141
142template <typename Type>
143bool operator!=(const plTransformTemplate<Type>& t1, const plTransformTemplate<Type>& t2); // [tested]
144
145#include <Foundation/Math/Implementation/Transform_inl.h>
A 4x4 component matrix class.
Definition Mat4.h:11
Quaternions can be used to represent rotations in 3D space.
Definition Quat.h:19
A class that represents position, rotation and scaling via a position vector, a quaternion and a scal...
Definition Transform.h:31
void Invert()
Inverts this transform.
Definition Transform_inl.h:230
static plTransformTemplate< Type > MakeIdentity()
Creates an identity transform.
Definition Transform_inl.h:25
static plTransformTemplate< Type > MakeGlobalTransform(const plTransformTemplate &globalTransformParent, const plTransformTemplate &localTransformChild)
Creates a transform that is the global transform, that is reached by applying the child's local trans...
Definition Transform_inl.h:61
static plTransformTemplate< Type > MakeLocalTransform(const plTransformTemplate &globalTransformParent, const plTransformTemplate &globalTransformChild)
Creates a transform that is the local transformation needed to get from the parent's transform to the...
Definition Transform_inl.h:48
bool HasMirrorScaling() const
Returns whether this transform contains negative scaling aka mirroring.
Definition Transform_inl.h:80
const plMat4Template< Type > GetAsMat4() const
Returns the transformation as a matrix.
Definition Transform_inl.h:111
bool IsValid() const
Checks that all components are valid (no NaN, only finite numbers).
Definition Transform_inl.h:105
const plTransformTemplate GetInverse() const
Returns the inverse of this transform.
Definition Transform_inl.h:236
bool IsEqual(const plTransformTemplate &rhs, Type fEpsilon) const
Equality Check with epsilon.
Definition Transform_inl.h:99
Type GetMaxScale() const
Returns the scale component with maximum magnitude.
Definition Transform_inl.h:73
void SetIdentity()
Sets the position to be zero and the rotation to identity.
Definition Transform_inl.h:67
bool IsIdentical(const plTransformTemplate &rhs) const
Equality Check (bitwise)
Definition Transform_inl.h:93
bool ContainsUniformScale() const
Returns whether this transform contains uniform scaling.
Definition Transform_inl.h:86
plTransformTemplate()=default
Default constructor: Does not do any initialization.
static plTransformTemplate< Type > Make(const plVec3Template< Type > &vPosition, const plQuatTemplate< Type > &qRotation=plQuatTemplate< Type >::MakeIdentity(), const plVec3Template< Type > &vScale=plVec3Template< Type >(1))
Creates a transform from the given position, rotation and scale.
Definition Transform_inl.h:15
static plTransformTemplate< Type > MakeFromMat4(const plMat4Template< Type > &mMat)
Creates a transform from the given matrix.
Definition Transform_inl.h:35
A 3-component vector class.
Definition Vec3.h:9