Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
transform.h
Go to the documentation of this file.
1 #ifndef TRANSFORM_H
2 #define TRANSFORM_H
3 #include <glm/glm.hpp>
4 #include <glm/gtc/quaternion.hpp>
5 #include <memory>
6 #include <list>
7 
8 //= SCRIPTABLE
9 
13 class Transform : public std::enable_shared_from_this<Transform> {
14  private:
15  std::weak_ptr<Transform> parent;
16  std::list<std::shared_ptr<Transform>> children;
17 
18  glm::vec3 local_translation;
19  glm::quat local_rotation;
20  glm::vec3 local_scale;
21  public:
22 
23  //= BEGIN SCRIPTABLE
24 
28  Transform();
32  ~Transform();
33 
43  bool operator==(const Transform& other);
53  bool operator!=(const Transform& other);
54 
62  Transform operator*(const Transform& other) const;
63 
69  void addChild(std::shared_ptr<Transform> transform);
75  void removeChild(std::shared_ptr<Transform> transform);
76 
82  std::list<std::shared_ptr<Transform>> getChildren() const;
88  std::shared_ptr<Transform> getParent() const;
89 
95  unsigned int getTreeSize() const;
96 
103  void translate(const float x, const float y) noexcept;
111  void translate(const float x, const float y, const float z) noexcept;
117  void translate(const glm::vec3& vec) noexcept;
123  void translate(const glm::vec2& vec) noexcept;
124 
130  glm::vec3 getAbsoluteTranslation() const noexcept;
136  glm::vec3 getLocalTranslation() const noexcept;
137 
145  void rotate(const float angle_x, const float angle_y, const float angle_z) noexcept;
151  void rotate(const glm::vec3& euler_angles) noexcept;
157  void rotate(const glm::quat& quat) noexcept;
164  void rotate(const float angle, const glm::vec3& axis) noexcept;
165 
171  glm::quat getAbsoluteRotation() const noexcept;
177  float getAbsoluteRotationAngle() const noexcept;
183  glm::vec3 getAbsoluteRotationAxis() const noexcept;
189  glm::vec3 getAbsoluteEulerAngles() const noexcept;
190 
196  glm::quat getLocalRotation() const noexcept;
202  float getLocalRotationAngle() const noexcept;
208  glm::vec3 getLocalRotationAxis() const noexcept;
214  glm::vec3 getLocalEulerAngles() const noexcept;
215 
221  void scale(const float x) noexcept;
228  void scale(const float x, const float y) noexcept;
236  void scale(const float x, const float y, const float z) noexcept;
242  void scale(const glm::vec2& vec) noexcept;
248  void scale(const glm::vec3& vec) noexcept;
249 
255  glm::vec3 getAbsoluteScale() const noexcept;
261  glm::vec3 getLocalScale() const noexcept;
262 
268  glm::mat4 getAbsoluteTransformationMatrix() const noexcept;
274  glm::mat4 getLocalTransformationMatrix() const noexcept;
280  std::string to_string() const noexcept;
281  //= END SCRIPTABLE
282 };
283 
284 #endif
Transform operator*(const Transform &other) const
Essentially a matrix multiplication, combines translations, rotations, and scales.
Definition: transform.cpp:41
std::string to_string() const noexcept
Returns a string representation of the object.
Definition: transform.cpp:206
glm::quat getAbsoluteRotation() const noexcept
Gets the absolute rotation.
Definition: transform.cpp:102
std::shared_ptr< Transform > getParent() const
Gets the parent.
Definition: transform.cpp:197
float getLocalRotationAngle() const noexcept
Gets the local rotation angle.
Definition: transform.cpp:125
unsigned int getTreeSize() const
Gets the tree size.
Definition: transform.cpp:49
glm::vec3 getAbsoluteRotationAxis() const noexcept
Gets the absolute rotation axis.
Definition: transform.cpp:113
bool operator==(const Transform &other)
operator ==
Definition: transform.cpp:31
glm::vec3 getAbsoluteTranslation() const noexcept
Gets the absolute translation.
Definition: transform.cpp:72
glm::vec3 getAbsoluteEulerAngles() const noexcept
Gets the absolute euler angles.
Definition: transform.cpp:117
glm::vec3 getLocalTranslation() const noexcept
Gets the local translation.
Definition: transform.cpp:79
void rotate(const float angle_x, const float angle_y, const float angle_z) noexcept
Rotates this transform using yaw roll pitch/euler angles.
Definition: transform.cpp:88
void removeChild(std::shared_ptr< Transform > transform)
Removes a child.
Definition: transform.cpp:188
void scale(const float x) noexcept
Scales transform in all 3 directions by x.
Definition: transform.cpp:145
glm::vec3 getLocalEulerAngles() const noexcept
Gets the local euler angles.
Definition: transform.cpp:133
Class for transform.
Definition: transform.h:13
glm::vec3 getAbsoluteScale() const noexcept
Gets the absolute scale.
Definition: transform.cpp:157
void addChild(std::shared_ptr< Transform > transform)
Adds a child.
Definition: transform.cpp:182
float getAbsoluteRotationAngle() const noexcept
Gets the absolute rotation angle.
Definition: transform.cpp:109
Transform()
Transform Constructor.
Definition: transform.cpp:8
glm::quat getLocalRotation() const noexcept
Gets the local rotation.
Definition: transform.cpp:121
glm::mat4 getLocalTransformationMatrix() const noexcept
Gets the local transformation matrix.
Definition: transform.cpp:175
~Transform()
Destroys the object.
Definition: transform.cpp:14
glm::vec3 getLocalScale() const noexcept
Gets the local scale.
Definition: transform.cpp:164
bool operator!=(const Transform &other)
operator !=
Definition: transform.cpp:37
glm::mat4 getAbsoluteTransformationMatrix() const noexcept
Gets the absolute transformation matrix.
Definition: transform.cpp:168
glm::vec3 getLocalRotationAxis() const noexcept
Gets the local rotation axis.
Definition: transform.cpp:129
void translate(const float x, const float y) noexcept
Adds 2d translation to Transform.
Definition: transform.cpp:64
std::list< std::shared_ptr< Transform > > getChildren() const
Gets the children.
Definition: transform.cpp:193