Matrix4.hpp
Go to the documentation of this file.
1 
7 #include <etk/types.hpp>
8 
9 #pragma once
10 
11 #include <etk/math/Vector3D.hpp>
12 
13 #include <cmath>
14 
15 namespace etk {
21  template<class T>
22  T degreeToRadian(T _val) {
23  return _val*M_PI/T(180.0);
24  }
30  template<class T>
31  T radianToDegree(T _val) {
32  return _val*T(180.0)/M_PI;
33  }
37  class Matrix4 {
38  public:
39  float m_mat[4*4];
40  public:
44  void identity();
48  Matrix4();
53  Matrix4(const Matrix4& _obj);
73  Matrix4(float _a1, float _b1, float _c1, float _d1,
74  float _a2, float _b2, float _c2, float _d2,
75  float _a3, float _b3, float _c3, float _d3,
76  float _a4, float _b4, float _c4, float _d4);
81  Matrix4(float* _values);
87  const Matrix4& operator= (const Matrix4& _obj);
94  bool operator== (const Matrix4& _obj) const;
101  bool operator!= (const Matrix4& _obj) const;
107  const Matrix4& operator+= (const Matrix4& _obj);
113  Matrix4 operator+ (const Matrix4& _obj) const;
119  const Matrix4& operator-= (const Matrix4& _obj);
125  Matrix4 operator- (const Matrix4& _obj) const;
131  const Matrix4& operator*= (const Matrix4& _obj);
137  Matrix4 operator* (const Matrix4& _obj) const;
143  vec3 operator*(const vec3& _point) const;
147  void transpose();
152  void scale(const vec3& _vect);
159  void scale(float _sx, float _sy, float _sz);
165  void rotate(const vec3& _vect, float _angleRad=0.0);
170  void translate(const vec3& _vect);
177  float coFactor(int32_t _row, int32_t _col) const;
182  float determinant() const;
188  Matrix4 invert();
189  };
200  Matrix4 matFrustum(float _xmin, float _xmax, float _ymin, float _ymax, float _zNear, float _zFar);
209  Matrix4 matPerspective(float _foxy, float _aspect, float _zNear, float _zFar);
220  Matrix4 matOrtho(float _left, float _right, float _bottom, float _top, float _nearVal, float _farVal);
226  Matrix4 matTranslate(vec3 _translate);
232  Matrix4 matScale(vec3 _scale);
239  Matrix4 matRotate(vec3 _normal, float _angleRad=0.0);
241  Matrix4 matRotate2(vec3 _vect);
248  Matrix4 matLookAt(const vec3& _eye,
249  const vec3& _target,
250  const vec3& _up);
252  std::ostream& operator <<(std::ostream& _os, const etk::Matrix4& _obj);
253 };
254 
255 
256 // To siplify the writing of the code ==> this permit to have the same name with the glsl language...
258 
Matrix4 matFrustum(float _xmin, float _xmax, float _ymin, float _ymax, float _zNear, float _zFar)
Create projection matrix with the box parameter (camera view in -z axis)
Matrix4 matOrtho(float _left, float _right, float _bottom, float _top, float _nearVal, float _farVal)
Create orthogonal projection matrix with the box parameter (camera view in -z axis) ...
float coFactor(int32_t _row, int32_t _col) const
Computes a cofactor. Used for matrix inversion.
Matrix4 operator-(const Matrix4 &_obj) const
Operator- Decrement an other matrix with this one.
void scale(const vec3 &_vect)
Scale the current Matrix.
T radianToDegree(T _val)
Convert radian in degree.
Definition: Matrix4.hpp:31
basic namespace of the etk library. (it might contain all the etk fuctions/class/structures without m...
Definition: Archive.hpp:16
void rotate(const vec3 &_vect, float _angleRad=0.0)
Makes a rotation matrix about an arbitrary axis.
Matrix4 matScale(vec3 _scale)
Create a matrix 3D with a simple scale.
Matrix4 matLookAt(const vec3 &_eye, const vec3 &_target, const vec3 &_up)
Create projection matrix with camera property (camera view in -z axis)
const Matrix4 & operator+=(const Matrix4 &_obj)
Operator+= Addition an other matrix with this one.
Matrix4 operator+(const Matrix4 &_obj) const
Operator+ Addition an other matrix with this one.
const Matrix4 & operator=(const Matrix4 &_obj)
Operator= Asign the current object with an other object.
T degreeToRadian(T _val)
Convert degree in radian.
Definition: Matrix4.hpp:22
void identity()
configure identity of the matrix
Matrix4()
Constructor that load identity.
Transformation matrix for vector 3D.
Definition: Matrix4.hpp:37
Matrix4 matPerspective(float _foxy, float _aspect, float _zNear, float _zFar)
Create projection matrix with human repensentation view (camera view in -z axis)
Matrix4 matTranslate(vec3 _translate)
Create a matrix 3D with a simple translation.
float determinant() const
Computes the determinant of the matrix.
void translate(const vec3 &_vect)
Makes a translation of the matrix.
const Matrix4 & operator-=(const Matrix4 &_obj)
Operator-= Decrement an other matrix with this one.
float m_mat[4 *4]
matrix data
Definition: Matrix4.hpp:39
void transpose()
Transpose the current matix (usefull for OpenGL display)
bool operator==(const Matrix4 &_obj) const
Equality compare operator with an other object.
Matrix4 operator*(const Matrix4 &_obj) const
Operator* Multiplication an other matrix with this one.
Matrix4 matRotate(vec3 _normal, float _angleRad=0.0)
Create a matrix 3D with a simple rotation.
bool operator!=(const Matrix4 &_obj) const
In-Equality compare operator with an other object.
Vectorial 3-dimention vector (x/y/z)
Definition: Vector3D.hpp:20
Matrix4 invert()
Inverts the matrix.
const Matrix4 & operator*=(const Matrix4 &_obj)
Operator*= Multiplication an other matrix with this one.