Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
Transform.h
Go to the documentation of this file.
1#pragma once
2
3#include <glm/glm.hpp>
4#include <string>
5#include <glm/gtc/quaternion.hpp>
6
9
10namespace Ecs
11{
12 struct LocalTransform;
13
15 {
16 private:
18 glm::vec3 skew;
19 glm::vec4 perspective;
20 glm::vec3 translation;
21 glm::vec3 scale;
22 glm::quat rotation;
23 };
24
25 static MatrixTransformComponent extractComponents(const glm::mat4& matrix);
26
27 public:
28 static glm::vec3 getPosition(const glm::mat4& matrix);
29 static glm::quat getRotation(const glm::mat4& matrix);
30 static glm::vec3 getRotationEuler(const glm::mat4& matrix);
31 static glm::vec3 getScale(const glm::mat4& matrix);
32
33 static void setPosition(Ecs::LocalTransform& transform, const glm::vec3& newPosition);
34 static void setRotation(Ecs::LocalTransform& transform, const glm::vec3& newRotation);
35 static void setRotation(Ecs::LocalTransform& transform, const glm::quat& newQuaternion);
36 static void setScale(Ecs::LocalTransform& transform, const glm::vec3& newScale);
37 };
38}
39
40namespace EngineCore {
41
42 class Transform : public Serializable {
43 friend class SceneGraph;
44 public:
46
47 explicit Transform(glm::vec3 location);
48 Transform(glm::vec3 location, glm::vec3 rotation);
49 Transform(glm::vec3 location, glm::vec3 rotation, glm::vec3 scale);
50
51 explicit Transform(glm::mat4 matrix);
52
53 explicit Transform(nlohmann::json object);
55
56 private:
58 glm::vec3 skew;
59 glm::vec4 perspective;
60 glm::vec3 translation;
61 glm::vec3 scale;
62 glm::quat rotation;
63 };
64
65 // cached transform components
67 mutable bool needsComponentRebuild = true;
68 mutable bool isDirty = true;
69 mutable bool inverseNeedsUpdate = true;
70
73
74 mutable glm::mat4 cachedInverse = glm::mat4(1.0f);
75 public:
76 glm::mat4 getInverse() const;
77
79
80 [[nodiscard]] glm::vec3 getLocation() const;
81 void setLocation(const glm::vec3& newLocation);
82
83 [[nodiscard]] glm::vec3 getRotation() const;
84 void setRotation(const glm::vec3& newRotationEuler);
85
86 void setRotationQuat(glm::quat newQuaternion);
87 glm::quat getRotationQuat() const;
88
89 [[nodiscard]] glm::vec3 getScale() const;
90 void setScale(const glm::vec3& newScale);
91
92 Transform matrixToTransform(glm::mat4 matrix) const;
93
94 void overrideMatrix(glm::mat4 matrix);
95
96 Transform combine(const Transform& parent) const;
97 [[nodiscard]] glm::mat4 toMatrix() const;
98
99 [[nodiscard]] std::string toString() const;
100
101 void Serialize(nlohmann::json &archive) override;
102 void Deserialize(nlohmann::json& archive) override;
103 [[nodiscard]] std::string getClassName() const override;
104
105 bool isTransformDirty() const;
106
107 Transform operator*(const Transform& other) const;
108
109 void markDirty() const;
110 void markClean() const;
111 private:
112 class serial {
113 public:
114 inline static std::string LOCATION = "location";
115 inline static std::string ROTATION = "rotation";
116 inline static std::string SCALE = "scale";
117 };
118
119 glm::mat4 transform = glm::mat4(1.0f);
120
122 };
123}
#define REGISTER_SERIALIZABLE(ClassName)
Registers the serializable in the list of all serializable objects. This list is primarily used in th...
static void setScale(Ecs::LocalTransform &transform, const glm::vec3 &newScale)
static glm::vec3 getPosition(const glm::mat4 &matrix)
static void setPosition(Ecs::LocalTransform &transform, const glm::vec3 &newPosition)
static glm::quat getRotation(const glm::mat4 &matrix)
static glm::vec3 getScale(const glm::mat4 &matrix)
static void setRotation(Ecs::LocalTransform &transform, const glm::vec3 &newRotation)
static MatrixTransformComponent extractComponents(const glm::mat4 &matrix)
static glm::vec3 getRotationEuler(const glm::mat4 &matrix)
static std::string LOCATION
Definition Transform.h:114
static std::string SCALE
Definition Transform.h:116
static std::string ROTATION
Definition Transform.h:115
std::string getClassName() const override
glm::quat getRotationQuat() const
friend class SceneGraph
Definition Transform.h:43
glm::vec3 getRotation() const
glm::mat4 toMatrix() const
bool isTransformDirty() const
void setLocation(const glm::vec3 &newLocation)
Transform matrixToTransform(glm::mat4 matrix) const
void setScale(const glm::vec3 &newScale)
std::string toString() const
Transform operator*(const Transform &other) const
void Serialize(nlohmann::json &archive) override
void regenerateTransformComponents() const
Definition Transform.cpp:80
void markDirty() const
void overrideMatrix(glm::mat4 matrix)
glm::mat4 getInverse() const
Definition Transform.cpp:85
void setRotation(const glm::vec3 &newRotationEuler)
Transform combine(const Transform &parent) const
MatrixTransformComponent getComponents() const
Definition Transform.cpp:93
glm::mat4 cachedInverse
Definition Transform.h:74
void setRotationQuat(glm::quat newQuaternion)
Transform::MatrixTransformComponent transform_components
Definition Transform.h:66
void Deserialize(nlohmann::json &archive) override
glm::vec3 getScale() const
MatrixTransformComponent generateTransformComponentsFromMatrix(const glm::mat4 &matrix) const
Definition Transform.cpp:65
glm::vec3 getLocation() const
void markClean() const
Data structs for the Entity Component System.
Log category system implementation.