Voltray Engine Docs
Loading...
Searching...
No Matches
Transform.h
Go to the documentation of this file.
1#pragma once
2
3#include "Vec3.h"
4#include "Mat4.h"
5
15{
16public:
20 Transform();
21
26 Transform(const Vec3 &position);
32 Transform(const Vec3 &position, const Vec3 &rotation, const Vec3 &scale);
33
34 // Getters
35 const Vec3 &GetPosition() const { return m_Position; }
36 const Vec3 &GetRotation() const { return m_Rotation; }
37 const Vec3 &GetScale() const { return m_Scale; }
38 const Vec3 &GetPivot() const { return m_Pivot; }
39
40 // Setters
41 void SetPosition(const Vec3 &position);
42 void SetRotation(const Vec3 &rotation);
43 void SetScale(const Vec3 &scale);
44 void SetScale(float uniformScale);
45 void SetPivot(const Vec3 &pivot);
46 void SetMeshCenter(const Vec3 &meshCenter);
47
53 void SetRelativePivot(const Vec3 &meshCenter, const Vec3 &relativePivot = Vec3(0.0f, 0.0f, 0.0f));
54
55 // Transformation operations
56 void Translate(const Vec3 &translation);
57 void Rotate(const Vec3 &rotation);
58 void Scale(const Vec3 &scale);
59 void Scale(float uniformScale);
60
61 // Local space transformation operations
66 void TranslateLocal(const Vec3 &localTranslation);
67
72 void TranslateLocalX(float distance);
73
78 void TranslateLocalY(float distance);
79
84 void TranslateLocalZ(float distance);
85
90 Vec3 GetLocalRight() const;
91
96 Vec3 GetLocalUp() const;
97
102 Vec3 GetLocalForward() const;
103
108 Mat4 GetMatrix() const;
109
114 Mat4 GetInverseMatrix() const;
115
119 void Reset();
120
121private:
122 Vec3 m_Position{0.0f, 0.0f, 0.0f};
123 Vec3 m_Rotation{0.0f, 0.0f, 0.0f}; // Euler angles in degrees
124 Vec3 m_Scale{1.0f, 1.0f, 1.0f};
125 Vec3 m_Pivot{0.0f, 0.0f, 0.0f}; // Relative pivot offset from mesh center
126 Vec3 m_MeshCenter{0.0f, 0.0f, 0.0f}; // Center of the mesh
127
128 mutable Mat4 m_CachedMatrix;
129 mutable bool m_MatrixDirty = true;
130
131 void InvalidateMatrix() const { m_MatrixDirty = true; }
132 void UpdateMatrix() const;
133};
Represents a 3D transformation with position, rotation, and scale.
Definition Transform.h:15
void Translate(const Vec3 &translation)
Definition Transform.cpp:63
Vec3 GetLocalUp() const
Gets the local Y axis (up vector) of the object.
Definition Transform.cpp:133
Vec3 GetLocalRight() const
Gets the local X axis (right vector) of the object.
Definition Transform.cpp:122
void TranslateLocalX(float distance)
Translates the object along its local X axis.
Definition Transform.cpp:107
Mat4 GetInverseMatrix() const
Gets the inverse transformation matrix.
Definition Transform.cpp:165
void SetScale(const Vec3 &scale)
Definition Transform.cpp:32
void Reset()
Resets transform to identity.
Definition Transform.cpp:200
Vec3 GetLocalForward() const
Gets the local Z axis (forward vector) of the object.
Definition Transform.cpp:144
Mat4 GetMatrix() const
Gets the transformation matrix.
Definition Transform.cpp:155
void SetPosition(const Vec3 &position)
Definition Transform.cpp:20
void TranslateLocalZ(float distance)
Translates the object along its local Z axis.
Definition Transform.cpp:117
const Vec3 & GetPivot() const
Definition Transform.h:38
void Scale(const Vec3 &scale)
Definition Transform.cpp:75
void TranslateLocalY(float distance)
Translates the object along its local Y axis.
Definition Transform.cpp:112
void SetPivot(const Vec3 &pivot)
Definition Transform.cpp:44
void TranslateLocal(const Vec3 &localTranslation)
Translates the object along its local axes.
Definition Transform.cpp:92
Transform()
Default constructor - creates identity transform.
Definition Transform.cpp:5
const Vec3 & GetScale() const
Definition Transform.h:37
void Rotate(const Vec3 &rotation)
Definition Transform.cpp:69
const Vec3 & GetRotation() const
Definition Transform.h:36
void SetMeshCenter(const Vec3 &meshCenter)
Definition Transform.cpp:50
void SetRotation(const Vec3 &rotation)
Definition Transform.cpp:26
const Vec3 & GetPosition() const
Definition Transform.h:35
void SetRelativePivot(const Vec3 &meshCenter, const Vec3 &relativePivot=Vec3(0.0f, 0.0f, 0.0f))
Sets the pivot based on mesh bounds, where (0,0,0) represents the mesh center.
Definition Transform.cpp:56
4x4 Matrix structure for 3D transformations and projections.
Definition Mat4.h:16
Definition Vec3.h:5