Ocular Engine
Transform.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_MATH_TRANSFORM__H__
19 #define __H__OCULAR_MATH_TRANSFORM__H__
20 
21 #include "Vector3.hpp"
22 #include "Quaternion.hpp"
23 #include "Matrix4x4.hpp"
24 
25 #include "Utilities/Types.hpp"
26 #include "ObjectIO/ObjectIO.hpp"
27 
28 //------------------------------------------------------------------------------------------
29 
34 namespace Ocular
35 {
40  namespace Math
41  {
45  class Transform : public Core::ObjectIO
46  {
47  public:
48 
49  enum class DirtyFlags
50  {
51  None = 0,
52  Position = 1,
53  Rotation = 2,
54  Scale = 4
55  };
56 
57  Transform();
58  Transform(Vector3f const& position, Quaternion const& rotation, Vector3f const& scale);
59 
60  ~Transform();
61 
66  void refresh();
67 
68  //------------------------------------------------------------
69  // Getters and Setters
70  //------------------------------------------------------------
71 
72  uint32_t getDirtyFlags(bool clearFlags = true);
73 
77  void setPosition(Vector3f const& position);
78 
82  void setPosition(float const x, float const y, float const z);
83 
87  Vector3f const& getPosition() const;
88 
92  void setRotation(Quaternion const& rotation);
93 
97  Quaternion const& getRotation() const;
98 
102  void setScale(Vector3f const& scale);
103 
107  Vector3f const& getScale() const;
108 
112  Vector3f getForwards() const;
113 
117  Vector3f getUp() const;
118 
122  Vector3f getRight() const;
123 
127  Matrix4x4 const& getModelMatrix() const;
128 
129  //------------------------------------------------------------
130  // Movement
131  //------------------------------------------------------------
132 
137  void translate(Vector3f const& translation, bool local = true);
138 
145  void moveForward(float const delta);
146 
153  void moveUp(float const delta);
154 
161  void moveRight(float const delta);
162 
163  //------------------------------------------------------------
164  // Rotation
165  //------------------------------------------------------------
166 
173  void rotate(float angle, Vector3f const& axis);
174 
178  void rotate(Math::Quaternion const& rotation);
179 
186  void lookAt(Vector3f const& point, Vector3f const& upVector = Vector3f::Up());
187 
188  //------------------------------------------------------------
189  // Inherited Methods
190  //------------------------------------------------------------
191 
192  virtual void onLoad(Core::BuilderNode const* node) override;
193  virtual void onVariableModified(std::string const& varName) override;
194 
195  protected:
196 
197  private:
198 
199  Vector3f m_Position;
200  Quaternion m_Rotation;
201  Vector3f m_Scale;
202 
203  Matrix4x4 m_ModelMatrix;
204 
205  uint32_t m_DirtyFlags;
206  };
207  }
211 }
216 OCULAR_REGISTER_TYPE_CUSTOM(Ocular::Math::Transform, "Transform");
217 
218 //------------------------------------------------------------------------------------------
219 
220 #endif
void lookAt(Vector3f const &point, Vector3f const &upVector=Vector3f::Up())
Definition: Transform.cpp:217
virtual void onVariableModified(std::string const &varName) override
Definition: Transform.cpp:233
void refresh()
Definition: Transform.cpp:61
void moveUp(float const delta)
Definition: Transform.cpp:191
virtual void onLoad(Core::BuilderNode const *node) override
Definition: Transform.cpp:227
Vector3f getUp() const
Definition: Transform.cpp:142
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
Definition: Quaternion.hpp:50
void moveRight(float const delta)
Definition: Transform.cpp:196
Definition: ObjectIO.hpp:38
Vector3f getRight() const
Definition: Transform.cpp:152
void moveForward(float const delta)
Definition: Transform.cpp:186
void translate(Vector3f const &translation, bool local=true)
Definition: Transform.cpp:171
void rotate(float angle, Vector3f const &axis)
Definition: Transform.cpp:205
Definition: Transform.hpp:45
Generic node system used for loading and saving SceneObjects and their components.
Definition: BuilderNode.hpp:51
A 4x4 column-major float matrix.
Definition: Matrix4x4.hpp:64
Matrix4x4 const & getModelMatrix() const
Definition: Transform.cpp:162
Vector3f getForwards() const
Definition: Transform.cpp:132