CG_Labs  2020.0
TRSTransform.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <glm/glm.hpp>
4 #define GLM_ENABLE_EXPERIMENTAL
5 #include <glm/gtx/io.hpp>
6 
7 #include <iostream>
8 
33 template<typename T, glm::precision P>
34 class TRSTransform {
35 
36 public:
37  TRSTransform();
38  ~TRSTransform();
39 
40 public:
41  /* Reset the transformation to the identity matrix */
42  void ResetTransform();
43 
44  /* Relative transformations */
45 
46  void Translate(glm::tvec3<T, P> v);
47  void Scale(glm::tvec3<T, P> v);
48  void Scale(T uniform);
49 
50  /* Rotate around vector (x, y, z) */
51  void Rotate(T angle, glm::tvec3<T, P> v);
52  void RotateX(T angle);
53  void RotateY(T angle);
54  void RotateZ(T angle);
55  void PreRotate(T angle, glm::tvec3<T, P> v);
56  void PreRotateX(T angle);
57  void PreRotateY(T angle);
58  void PreRotateZ(T angle);
59 
60  /* Absolute transformations */
61 
62  void SetTranslate(glm::tvec3<T, P> v);
63  void SetScale(glm::tvec3<T, P> v);
64  void SetScale(T uniform);
65 
66  /* Rotate around vector (x, y, z) */
67  void SetRotate(T angle, glm::tvec3<T, P> v);
68  void SetRotateX(T angle);
69  void SetRotateY(T angle);
70  void SetRotateZ(T angle);
71 
72 
73  void LookTowards(glm::tvec3<T, P> front_vec, glm::tvec3<T, P> up_vec);
74  void LookTowards(glm::tvec3<T, P> front_vec);
75  void LookAt(glm::tvec3<T, P> point, glm::tvec3<T, P> up_vec);
76  void LookAt(glm::tvec3<T, P> point);
77 
78  /* Useful getters */
79 
80  glm::tmat4x4<T, P> GetMatrix() const;
81  glm::tmat4x4<T, P> GetMatrixInverse() const;
82 
83  glm::tmat3x3<T, P> GetRotation() const;
84  glm::tvec3<T, P> GetTranslation() const;
85  glm::tvec3<T, P> GetScale() const;
86 
87  glm::tmat4x4<T, P> GetTranslationMatrix() const;
88  glm::tmat4x4<T, P> GetRotationMatrix() const;
89  glm::tmat4x4<T, P> GetScaleMatrix() const;
90 
91  glm::tmat4x4<T, P> GetTranslationMatrixInverse() const;
92  glm::tmat4x4<T, P> GetRotationMatrixInverse() const;
93  glm::tmat4x4<T, P> GetScaleMatrixInverse() const;
94 
95  glm::tmat4x4<T, P> GetTranslationRotationMatrix() const;
96 
97  glm::tvec3<T, P> GetUp() const;
98  glm::tvec3<T, P> GetDown() const;
99  glm::tvec3<T, P> GetLeft() const;
100  glm::tvec3<T, P> GetRight() const;
101  glm::tvec3<T, P> GetFront() const;
102  glm::tvec3<T, P> GetBack() const;
103 
104 protected:
105  glm::tmat3x3<T, P> mR;
106  glm::tvec3<T, P> mT;
107  glm::tvec3<T, P> mS;
108 
109 public:
110  friend std::ostream &operator<<(std::ostream &os, TRSTransform<T, P> &v)
111  {
112  os << v.mT << std::endl;
113  os << v.mR << std::endl;
114  os << v.mS << std::endl;
115  return os;
116  }
117  friend std::istream &operator>>(std::istream &is, TRSTransform<T, P> &v)
118  {
119  is >> v.mT;
120  is >> v.mR;
121  is >> v.mS;
122  return is;
123  }
124 };
125 
126 #include "TRSTransform.inl"
127 
TRSTransform::SetRotateZ
void SetRotateZ(T angle)
Definition: TRSTransform.inl:200
TRSTransform::GetMatrixInverse
glm::tmat4x4< T, P > GetMatrixInverse() const
Definition: TRSTransform.inl:352
TRSTransform::mR
glm::tmat3x3< T, P > mR
Definition: TRSTransform.h:105
TRSTransform::GetUp
glm::tvec3< T, P > GetUp() const
Definition: TRSTransform.inl:400
TRSTransform::GetBack
glm::tvec3< T, P > GetBack() const
Definition: TRSTransform.inl:430
TRSTransform::GetScale
glm::tvec3< T, P > GetScale() const
Definition: TRSTransform.inl:392
TRSTransform::GetTranslationRotationMatrix
glm::tmat4x4< T, P > GetTranslationRotationMatrix() const
Definition: TRSTransform.inl:328
TRSTransform::GetLeft
glm::tvec3< T, P > GetLeft() const
Definition: TRSTransform.inl:412
TRSTransform::GetDown
glm::tvec3< T, P > GetDown() const
Definition: TRSTransform.inl:406
TRSTransform::Scale
void Scale(glm::tvec3< T, P > v)
Definition: TRSTransform.inl:42
TRSTransform::GetRight
glm::tvec3< T, P > GetRight() const
Definition: TRSTransform.inl:418
TRSTransform::SetRotate
void SetRotate(T angle, glm::tvec3< T, P > v)
Definition: TRSTransform.inl:176
TRSTransform::PreRotateY
void PreRotateY(T angle)
Definition: TRSTransform.inl:126
TRSTransform::RotateZ
void RotateZ(T angle)
Definition: TRSTransform.inl:92
TRSTransform::ResetTransform
void ResetTransform()
Definition: TRSTransform.inl:24
TRSTransform::TRSTransform
TRSTransform()
Definition: TRSTransform.inl:9
TRSTransform::PreRotateX
void PreRotateX(T angle)
Definition: TRSTransform.inl:113
TRSTransform::GetRotationMatrixInverse
glm::tmat4x4< T, P > GetRotationMatrixInverse() const
Definition: TRSTransform.inl:304
TRSTransform::RotateY
void RotateY(T angle)
Definition: TRSTransform.inl:79
TRSTransform::mT
glm::tvec3< T, P > mT
Definition: TRSTransform.h:106
TRSTransform::~TRSTransform
~TRSTransform()
Definition: TRSTransform.inl:17
TRSTransform::operator<<
friend std::ostream & operator<<(std::ostream &os, TRSTransform< T, P > &v)
Definition: TRSTransform.h:110
TRSTransform::GetMatrix
glm::tmat4x4< T, P > GetMatrix() const
Definition: TRSTransform.inl:340
TRSTransform::Rotate
void Rotate(T angle, glm::tvec3< T, P > v)
Definition: TRSTransform.inl:58
TRSTransform::SetRotateX
void SetRotateX(T angle)
Definition: TRSTransform.inl:184
TRSTransform::GetTranslation
glm::tvec3< T, P > GetTranslation() const
Definition: TRSTransform.inl:384
TRSTransform::GetScaleMatrixInverse
glm::tmat4x4< T, P > GetScaleMatrixInverse() const
Definition: TRSTransform.inl:316
TRSTransform
Definition: TRSTransform.h:34
TRSTransform::GetFront
glm::tvec3< T, P > GetFront() const
Definition: TRSTransform.inl:424
TRSTransform::operator>>
friend std::istream & operator>>(std::istream &is, TRSTransform< T, P > &v)
Definition: TRSTransform.h:117
TRSTransform::GetScaleMatrix
glm::tmat4x4< T, P > GetScaleMatrix() const
Definition: TRSTransform.inl:280
TRSTransform::RotateX
void RotateX(T angle)
Definition: TRSTransform.inl:66
TRSTransform::GetRotation
glm::tmat3x3< T, P > GetRotation() const
Definition: TRSTransform.inl:376
TRSTransform::Translate
void Translate(glm::tvec3< T, P > v)
Definition: TRSTransform.inl:34
TRSTransform::GetRotationMatrix
glm::tmat4x4< T, P > GetRotationMatrix() const
Definition: TRSTransform.inl:268
TRSTransform::SetScale
void SetScale(glm::tvec3< T, P > v)
Definition: TRSTransform.inl:160
TRSTransform::PreRotateZ
void PreRotateZ(T angle)
Definition: TRSTransform.inl:139
TRSTransform::LookAt
void LookAt(glm::tvec3< T, P > point, glm::tvec3< T, P > up_vec)
Definition: TRSTransform.inl:240
TRSTransform::GetTranslationMatrix
glm::tmat4x4< T, P > GetTranslationMatrix() const
Definition: TRSTransform.inl:256
TRSTransform::PreRotate
void PreRotate(T angle, glm::tvec3< T, P > v)
Definition: TRSTransform.inl:105
TRSTransform::SetTranslate
void SetTranslate(glm::tvec3< T, P > v)
Definition: TRSTransform.inl:152
TRSTransform.inl
TRSTransform::GetTranslationMatrixInverse
glm::tmat4x4< T, P > GetTranslationMatrixInverse() const
Definition: TRSTransform.inl:292
TRSTransform::SetRotateY
void SetRotateY(T angle)
Definition: TRSTransform.inl:192
TRSTransform::LookTowards
void LookTowards(glm::tvec3< T, P > front_vec, glm::tvec3< T, P > up_vec)
Definition: TRSTransform.inl:208
TRSTransform::mS
glm::tvec3< T, P > mS
Definition: TRSTransform.h:107