Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
transform.h
1#ifndef OE_SCENE_TRANSFORM_H
2#define OE_SCENE_TRANSFORM_H
3
4#include "../common.h"
5
6#include <glm/mat4x4.hpp>
7#include <glm/vec3.hpp>
8
9#include <glm/gtx/quaternion.hpp>
10
11#include "../util/concept.h"
12#include "../util/angle.h"
13
14namespace oe::scene
15{
20 {
21 public:
32 const glm::vec3& translation = glm::vec3(0.f),
33 const glm::quat& rotation = glm::quat(1.f, 0.f, 0.f, 0.f),
34 const glm::vec3& scale = glm::vec3(1.f),
35 const glm::vec3& skew = glm::vec3(0.f),
36 const glm::vec4& perspective = glm::vec4(glm::vec3(0.f), 1.f)
37 );
38
44 Transform(const glm::mat4& model);
45
51 const glm::vec3& getTranslation() const
52 {
53 return _translation;
54 }
55
61 const glm::vec3& getPosition() const
62 {
63 return _translation;
64 }
65
71 const glm::quat& getRotation() const
72 {
73 return _rotation;
74 }
75
81 const glm::vec3& getScale() const
82 {
83 return _scale;
84 }
85
91 const glm::vec3& getSkew() const
92 {
93 return _skew;
94 }
95
101 const glm::vec4& getPerspective() const
102 {
103 return _perspective;
104 }
105
113 void setTranslation(const float x, const float y, const float z);
114
121 void setPosition(const glm::vec3& position)
122 {
123 setTranslation(position);
124 }
125
134 void setPosition(const float x, const float y, const float z)
135 {
136 setTranslation(x, y, z);
137 }
138
148 void setRotation(const float x, const float y, const float z);
149
157 void setRotation(const lit::Angle& x, const lit::Angle& y, const lit::Angle& z);
158
166 void setScale(const float x, const float y, const float z);
167
173 void relativeTranslate(const glm::vec3& translation);
174
182 void relativeTranslate(const float x, const float y, const float z);
183
189 void loadFromModel(const glm::mat4& model);
190
196 void relativeMove(const glm::vec3& translation);
197
203 void relativeRotate(const glm::quat& quaternion);
204
214 void relativeRotate(const float x, const float y, const float z);
215
223 void relativeRotate(const lit::Angle& x, const lit::Angle& y, const lit::Angle& z);
224
230 void relativeScale(const glm::vec3& scale);
231
237 void setSkew(const glm::vec3& skew);
238
244 void setPerspective(const glm::vec4& perspective);
245
252 void interpolateWith(const float ratio, const Transform& target);
253
259 void fillFrom(const Transform& transform);
260
266 template<TranslationType T>
267 void setTranslation(const T& translation)
268 {
269 _translation.x = translation.x;
270 _translation.y = translation.y;
271 _translation.z = translation.z;
272
273 _is_dirty = true;
274 }
275
281 template<RotationType R>
282 void setRotation(const R& rotation)
283 {
284 _rotation.x = rotation.x;
285 _rotation.y = rotation.y;
286 _rotation.z = rotation.z;
287 _rotation.w = rotation.w;
288
289 _is_dirty = true;
290 }
291
297 template<ScaleType S>
298 void setScale(const S& scale)
299 {
300 _scale.x = scale.x;
301 _scale.y = scale.y;
302 _scale.z = scale.z;
303
304 _is_dirty = true;
305 }
306
314 template<TranslationType T>
315 void getTranslationAs(T& result) const
316 {
317 result.x = _translation.x;
318 result.y = _translation.y;
319 result.z = _translation.z;
320 }
321
329 template<RotationType R>
330 void getRotationAs(R& result) const
331 {
332 result.x = _rotation.x;
333 result.y = _rotation.y;
334 result.z = _rotation.z;
335 result.w = _rotation.w;
336 }
337
345 template<ScaleType S>
346 void getScaleAs(S& result) const
347 {
348 result.x = _scale.x;
349 result.y = _scale.y;
350 result.z = _scale.z;
351 }
352
357 glm::mat4 getModelMatrix() const;
358
364 inline bool isDirty() const
365 {
366 return _is_dirty;
367 }
368
369 protected:
374 void forceDirty(const bool is_dirty) const
375 {
376 _is_dirty = is_dirty;
377 }
378
379 private:
380 glm::vec3 _translation;
381 glm::quat _rotation;
382 glm::vec3 _scale;
383 glm::vec3 _skew;
384 glm::vec4 _perspective;
385
386 mutable bool _is_dirty = true;
387 };
388}
389#endif
Manage local Translation / Rotation / Scale of an entity in the world.
Definition transform.h:20
void setPosition(const glm::vec3 &position)
Translate to the specified position.
Definition transform.h:121
void setTranslation(const float x, const float y, const float z)
Translate to the specified position, filled component wise.
const glm::vec3 & getTranslation() const
Get Translation component value of the transform.
Definition transform.h:51
const glm::vec3 & getSkew() const
Get Skew component value of the transform.
Definition transform.h:91
void relativeRotate(const glm::quat &quaternion)
Rotate the transform relative to current rotation.
void setScale(const float x, const float y, const float z)
Set scaling.
void relativeRotate(const float x, const float y, const float z)
Rotate the transform from Euler angles (component wise)
void setScale(const S &scale)
Set scale vector from a generic type.
Definition transform.h:298
void forceDirty(const bool is_dirty) const
Set custom dirty status.
Definition transform.h:374
void relativeTranslate(const float x, const float y, const float z)
Translate the transform from current position, component wise.
void relativeScale(const glm::vec3 &scale)
Multiply current scale by the new one.
const glm::vec4 & getPerspective() const
get Perspective component value of the transform
Definition transform.h:101
const glm::quat & getRotation() const
Get Rotation component value of the transform.
Definition transform.h:71
void relativeRotate(const lit::Angle &x, const lit::Angle &y, const lit::Angle &z)
Relatively rotate the transform using a lit::Angle triad.
void setPerspective(const glm::vec4 &perspective)
Set perspective effect of the transform.
void relativeTranslate(const glm::vec3 &translation)
Translate the transform from current position.
glm::mat4 getModelMatrix() const
Generate a Model matrix from the transform.
void setTranslation(const T &translation)
Translate to the specified position.
Definition transform.h:267
void relativeMove(const glm::vec3 &translation)
Move the transform relative to current translation.
Transform(const glm::vec3 &translation=glm::vec3(0.f), const glm::quat &rotation=glm::quat(1.f, 0.f, 0.f, 0.f), const glm::vec3 &scale=glm::vec3(1.f), const glm::vec3 &skew=glm::vec3(0.f), const glm::vec4 &perspective=glm::vec4(glm::vec3(0.f), 1.f))
Generate Transform from its translation, rotation, scale values.
void loadFromModel(const glm::mat4 &model)
Fill the transform from a model matrix.
void interpolateWith(const float ratio, const Transform &target)
Interpolate this transform with another one.
void getRotationAs(R &result) const
Get rotation quaternion and fill in generic type.
Definition transform.h:330
Transform(const glm::mat4 &model)
Generate Transform from a model matrix.
void getTranslationAs(T &result) const
Get translation vector and fill in generic type.
Definition transform.h:315
bool isDirty() const
Check if something modified this transform.
Definition transform.h:364
void setRotation(const float x, const float y, const float z)
Set rotation from Euler angles.
void fillFrom(const Transform &transform)
Fill current values from another transform.
void getScaleAs(S &result) const
Get scale vector and fill in generic type.
Definition transform.h:346
void setRotation(const R &rotation)
Get rotation quaternion from a generic type.
Definition transform.h:282
void setPosition(const float x, const float y, const float z)
Translate to the specified position.
Definition transform.h:134
const glm::vec3 & getScale() const
Get Scaling component value of the transform.
Definition transform.h:81
const glm::vec3 & getPosition() const
Get Translation component value of the transform.
Definition transform.h:61
void setRotation(const lit::Angle &x, const lit::Angle &y, const lit::Angle &z)
Relatively rotate the transform using a lit::Angle triad.
void setSkew(const glm::vec3 &skew)
Set skew of the transform.
Scene related management (Render-agnostic Geometry, Manger, etc...)
Definition debug.h:19
Wrapper and helper to abstract conversions between degree and radian angles.
Definition angle.h:19