Guest User

Matrix4 class template - Henri Korpela aka Helixirr

a guest
Jul 1st, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. // File: Matrix4.hpp:
  2.  
  3. /// -----------------------------------
  4. /// @class  Matrix4
  5. /// @brief  Represents a 4 by 4 matrix.
  6. /// -----------------------------------
  7. #ifndef __MATRIX4__
  8. #define __MATRIX4__
  9.  
  10.     template<typename T>
  11.     class Matrix4 final{
  12.     public:
  13.  
  14.         /// Constructors & destructors:
  15.         Matrix4(void) = default;
  16.         Matrix4(Matrix4 const& matrix_) = default;
  17.         Matrix4(Matrix4&& matrix_) = default;
  18.         Matrix4(T (&matrix_)[4][4]);
  19.         Matrix4(T (&&matrix_)[4][4]);
  20.  
  21.         /// Member functions (overloaded operators, assignment):
  22.         Matrix4& operator=(Matrix4 const& matrix_) = default;
  23.         Matrix4& operator=(Matrix4&& matrix_) = default;
  24.  
  25.     private:
  26.         /// Member data:
  27.         T data[4][4] = {{0}};
  28.     };
  29. #include <Matrix4.inl>
  30. #endif /** __MATRIX4__ **/
  31.  
  32. // File: Matrix4.inl:
  33.  
  34. /// -----------------------------------
  35. /// @class  Matrix4
  36. /// @brief  Represents a 4 by 4 matrix.
  37. /// -----------------------------------
  38. /// Constructors & destructors:
  39. template<typename T>
  40. Matrix4<T>::Matrix4(T (&matrix_)[4][4]) : Matrix4({
  41.         .data = {
  42.             {matrix_[0][0], matrix_[0][1], matrix_[0][2], matrix_[0][3]},
  43.             {matrix_[1][0], matrix_[1][1], matrix_[1][2], matrix_[1][3]},
  44.             {matrix_[2][0], matrix_[2][1], matrix_[2][2], matrix_[2][3]},
  45.             {matrix_[3][0], matrix_[3][1], matrix_[3][2], matrix_[3][3]}
  46.         }
  47.     })
  48. {
  49.  
  50. }
  51. template<typename T>
  52. Matrix4<T>::Matrix4(T (&&matrix_)[4][4]) : Matrix4({
  53.         .data = {
  54.             {matrix_[0][0], matrix_[0][1], matrix_[0][2], matrix_[0][3]},
  55.             {matrix_[1][0], matrix_[1][1], matrix_[1][2], matrix_[1][3]},
  56.             {matrix_[2][0], matrix_[2][1], matrix_[2][2], matrix_[2][3]},
  57.             {matrix_[3][0], matrix_[3][1], matrix_[3][2], matrix_[3][3]}
  58.         }
  59.     })
  60. {
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment