NGL  6.5
The NCCA Graphics Library
Transformation.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Jon Macey
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #ifndef TRANSFORM_H_
18 #define TRANSFORM_H_
19 //----------------------------------------------------------------------------------------------------------------------
22 //----------------------------------------------------------------------------------------------------------------------
23 // Library includes
24 #include "Mat4.h"
25 #include "NGLassert.h"
26 #include "Transformation.h"
27 #include "Vec4.h"
28 
29 namespace ngl
30 {
31 //----------------------------------------------------------------------------------------------------------------------
33 //----------------------------------------------------------------------------------------------------------------------
34 enum class ActiveMatrix : char{NORMAL,TRANSPOSE,INVERSE};
35 //----------------------------------------------------------------------------------------------------------------------
42 //----------------------------------------------------------------------------------------------------------------------
44 {
45  friend class Vec4;
46 public:
47 
48  //----------------------------------------------------------------------------------------------------------------------
50  //----------------------------------------------------------------------------------------------------------------------
51  Transformation() noexcept;
52  //----------------------------------------------------------------------------------------------------------------------
54  //----------------------------------------------------------------------------------------------------------------------
55  Transformation(const Transformation &_t) noexcept;
56  //----------------------------------------------------------------------------------------------------------------------
58  //----------------------------------------------------------------------------------------------------------------------
59  Transformation & operator =(const Transformation &_t) noexcept;
60  //----------------------------------------------------------------------------------------------------------------------
63  //----------------------------------------------------------------------------------------------------------------------
64  void setScale( const Vec3& _scale ) noexcept;
65  void setScale( const Vec4& _scale ) noexcept;
66 
67  //----------------------------------------------------------------------------------------------------------------------
72  //----------------------------------------------------------------------------------------------------------------------
73  void setScale( Real _x, Real _y, Real _z ) noexcept;
74  //----------------------------------------------------------------------------------------------------------------------
77  //----------------------------------------------------------------------------------------------------------------------
78  void addScale( const Vec3& _scale ) noexcept;
79  //----------------------------------------------------------------------------------------------------------------------
84  //----------------------------------------------------------------------------------------------------------------------
85  void addScale( Real _x, Real _y, Real _z ) noexcept;
86  //----------------------------------------------------------------------------------------------------------------------
89  //----------------------------------------------------------------------------------------------------------------------
90  void setPosition( const Vec4& _position ) noexcept;
91  //----------------------------------------------------------------------------------------------------------------------
94  //----------------------------------------------------------------------------------------------------------------------
95  void setPosition( const Vec3& _position ) noexcept;
96  //----------------------------------------------------------------------------------------------------------------------
101  //----------------------------------------------------------------------------------------------------------------------
102  void setPosition( Real _x, Real _y, Real _z ) noexcept;
103  //----------------------------------------------------------------------------------------------------------------------
106  //----------------------------------------------------------------------------------------------------------------------
107  void addPosition( const Vec4& _position ) noexcept;
108  //----------------------------------------------------------------------------------------------------------------------
111  //----------------------------------------------------------------------------------------------------------------------
112  void addPosition( const Vec3& _position ) noexcept;
113  //----------------------------------------------------------------------------------------------------------------------
118  //----------------------------------------------------------------------------------------------------------------------
119  void addPosition( Real _x, Real _y, Real _z ) noexcept;
120  //----------------------------------------------------------------------------------------------------------------------
124  //----------------------------------------------------------------------------------------------------------------------
125  void setMatrix( const Mat4 &_m ) noexcept;
126  //----------------------------------------------------------------------------------------------------------------------
131  //----------------------------------------------------------------------------------------------------------------------
132  void setRotation( const Vec3& _rotation ) noexcept;
133  void setRotation( const Vec4& _rotation ) noexcept;
134  //----------------------------------------------------------------------------------------------------------------------
141  //----------------------------------------------------------------------------------------------------------------------
142  void setRotation( Real _x, Real _y, Real _z ) noexcept;
143  //----------------------------------------------------------------------------------------------------------------------
148  //----------------------------------------------------------------------------------------------------------------------
149  void addRotation( const Vec3& _rotation ) noexcept;
150  //----------------------------------------------------------------------------------------------------------------------
157  //----------------------------------------------------------------------------------------------------------------------
158  void addRotation( Real _x, Real _y, Real _z ) noexcept;
159  //----------------------------------------------------------------------------------------------------------------------
161  //----------------------------------------------------------------------------------------------------------------------
162  void reset() noexcept;
163  //----------------------------------------------------------------------------------------------------------------------
166  //----------------------------------------------------------------------------------------------------------------------
167  Vec3 getScale() const noexcept { return m_scale; }
168  //----------------------------------------------------------------------------------------------------------------------
171  //----------------------------------------------------------------------------------------------------------------------
172  Vec3 getPosition() const noexcept { return m_position; }
173  //----------------------------------------------------------------------------------------------------------------------
176  //----------------------------------------------------------------------------------------------------------------------
177  Vec3 getRotation() const noexcept { return m_rotation; }
178  //----------------------------------------------------------------------------------------------------------------------
181  //----------------------------------------------------------------------------------------------------------------------
182  Mat4 getMatrix() noexcept{ computeMatrices(); return m_matrix; }
183  //----------------------------------------------------------------------------------------------------------------------
186  //----------------------------------------------------------------------------------------------------------------------
187  Mat4 getTransposeMatrix() noexcept{ computeMatrices(); return m_transposeMatrix; }
188  //----------------------------------------------------------------------------------------------------------------------
191  //----------------------------------------------------------------------------------------------------------------------
192  Mat4 getInverseMatrix() noexcept { computeMatrices(); return m_inverseMatrix; }
193  //----------------------------------------------------------------------------------------------------------------------
196  //----------------------------------------------------------------------------------------------------------------------
197  void operator*=( const Transformation &_m ) noexcept;
198  //----------------------------------------------------------------------------------------------------------------------
205  //----------------------------------------------------------------------------------------------------------------------
206  Transformation operator*( const Transformation &_m ) noexcept;
207  //----------------------------------------------------------------------------------------------------------------------
211  //----------------------------------------------------------------------------------------------------------------------
212  void loadMatrixToShader(const std::string &_param, const ActiveMatrix &_which=ActiveMatrix::NORMAL ) noexcept;
213  //----------------------------------------------------------------------------------------------------------------------
217  //----------------------------------------------------------------------------------------------------------------------
218  void loadGlobalAndCurrentMatrixToShader( const std::string &_param, Transformation &_global, const ActiveMatrix &_which=ActiveMatrix::NORMAL )noexcept;
219 
220 protected :
221 
222  //----------------------------------------------------------------------------------------------------------------------
224  //----------------------------------------------------------------------------------------------------------------------
226  //----------------------------------------------------------------------------------------------------------------------
228  //----------------------------------------------------------------------------------------------------------------------
230  //----------------------------------------------------------------------------------------------------------------------
232  //----------------------------------------------------------------------------------------------------------------------
234  //----------------------------------------------------------------------------------------------------------------------
236  //----------------------------------------------------------------------------------------------------------------------
238  //----------------------------------------------------------------------------------------------------------------------
240  //----------------------------------------------------------------------------------------------------------------------
242  //----------------------------------------------------------------------------------------------------------------------
244  //----------------------------------------------------------------------------------------------------------------------
246  //----------------------------------------------------------------------------------------------------------------------
248  //----------------------------------------------------------------------------------------------------------------------
250  //----------------------------------------------------------------------------------------------------------------------
252  //----------------------------------------------------------------------------------------------------------------------
253  void computeMatrices() noexcept;
254 
255 };
256 
257 } // end ngl namespace
258 #endif
259 //----------------------------------------------------------------------------------------------------------------------
simple Vector class for OpenGL graphics, contains overloaded operators for most math functions...
Definition: Vec4.h:57
Mat4 m_transposeMatrix
transpose matrix transformation
#define NGL_DLLEXPORT
Definition: Types.h:65
bool m_isMatrixComputed
boolean defines if the matrix is dirty or not
Vec3 getPosition() const noexcept
function to get the position
Mat4 m_matrix
matrix transformation
Mat4 getInverseMatrix() noexcept
function to get the inverse matrix. It computes the inverse matrix if it&#39;s dirty
simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths a...
Definition: Vec3.h:51
implementation files for RibExport class
Definition: AABB.cpp:22
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
encapsulates a 4d Homogenous Point / Vector object
Mat4 getMatrix() noexcept
function to get the matrix. It computes the matrix if it&#39;s dirty
a simple transformation object containing rot / tx / scale and final matrix
Vec3 getRotation() const noexcept
function to get the rotation
GLboolean reset
Definition: glew.h:4987
Mat4 m_inverseMatrix
inverse matrix transformation
Vec2 operator*(Real _k, const Vec2 &_v) noexcept
scalar * vector operator
Definition: Vec2.h:286
Vec3 m_rotation
rotation
Vec3 m_position
position
Transformation describes a transformation (translate, scale, rotation) modifed by j macey and include...
ActiveMatrix
Matrix Class to do simple matrix operations included operator overloaded functions for maths and matr...
Definition: Mat4.h:58
Mat4 getTransposeMatrix() noexcept
function to get the transpose matrix. It computes the transpose matrix if it&#39;s dirty ...
re impliment asserts so we don&#39;t exit on failure
GLsizei const GLchar *const * string
Definition: glew.h:1847