GameKit  0.0.1a
C++ gamedev tools
Transform.hpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: Transform.hpp
5  *
6  * Description:
7  *
8  * Created: 11/11/2018 17:39:49
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #ifndef GK_TRANSFORM_HPP_
15 #define GK_TRANSFORM_HPP_
16 
17 #define GLM_FORCE_RADIANS
18 #include <glm/gtc/type_ptr.hpp>
19 
20 #include "gk/core/Box.hpp"
21 
22 #ifndef RADIANS_PER_DEGREES
23 # define RADIANS_PER_DEGREES (M_PI / 180.0f)
24 #endif
25 
26 namespace gk {
27 
28 class Transform {
29  public:
30  Transform() = default;
31  Transform(const glm::mat4 &matrix) : m_matrix(matrix) {}
32 
33  Transform& combine(const Transform& transform);
34 
35  Transform& translate(float x, float y, float z = 0);
36  Transform& translate(const Vector3f& offset) { return translate(offset.x, offset.y, offset.z); }
37 
38  Transform& rotate(float angle) { return rotate(angle, {0, 0, 1}); }
39  Transform& rotate(float angle, const Vector3f& axis);
40 
41  Transform& scale(float scaleX, float scaleY, float scaleZ = 1);
42  Transform& scale(const Vector3f& factors) { return scale(factors.x, factors.y, factors.z); }
43 
44  const float* getRawMatrix() const { return glm::value_ptr(m_matrix); }
45  const glm::mat4 getMatrix() const { return m_matrix; }
46 
47  // Transform getInverse() const { return glm::inverse(m_matrix); }
48  // Transform getTranspose() const { return glm::transpose(m_matrix); }
49 
50  static const Transform Identity;
51 
52  private:
53  glm::mat4 m_matrix{1};
54 };
55 
56 Transform operator*(const Transform& left, const Transform& right);
57 Transform& operator*=(Transform& left, const Transform& right);
58 
59 } // namespace gk
60 
61 #endif // GK_TRANSFORM_HPP_
const glm::mat4 getMatrix() const
Definition: Transform.hpp:45
Transform & translate(float x, float y, float z=0)
Definition: Transform.cpp:28
Vector2< T > operator*(T n, Vector2< T > &vector2)
Definition: Vector2.hpp:65
Transform(const glm::mat4 &matrix)
Definition: Transform.hpp:31
static const Transform Identity
Definition: Transform.hpp:50
Transform & combine(const Transform &transform)
Definition: Transform.cpp:23
const float * getRawMatrix() const
Definition: Transform.hpp:44
Transform & rotate(float angle)
Definition: Transform.hpp:38
Transform & scale(float scaleX, float scaleY, float scaleZ=1)
Definition: Transform.cpp:39
glm::mat4 m_matrix
Definition: Transform.hpp:53
Transform()=default
Transform & operator*=(Transform &left, const Transform &right)
Definition: Transform.cpp:48
Transform & translate(const Vector3f &offset)
Definition: Transform.hpp:36
Transform & scale(const Vector3f &factors)
Definition: Transform.hpp:42