Aether3D Game Engine
Matrix.hpp
1 #ifndef MATRIX_H
2 #define MATRIX_H
3 
4 struct Vec3;
5 struct Vec4;
6 
7 // \todo Can be replaced with something else on C++11, but what? Keywords: alignof, alignas and std::aligned_storage
8 #if defined( _MSC_VER ) || defined( COMPILER_INTEL )
9 # define BEGIN_ALIGNED( n, a ) __declspec( align( a ) ) n
10 # define END_ALIGNED( n, a )
11 #elif defined( __GNUC__ ) || defined( __clang__ )
12 # define BEGIN_ALIGNED( n, a ) n
13 # define END_ALIGNED( n, a ) __attribute__( (aligned( a ) ) )
14 #endif
15 
17 #ifdef SIMD_SSE3
18 struct BEGIN_ALIGNED( Matrix44, 16 )
19 #else
20 struct Matrix44
21 #endif
22 {
24  static const Matrix44 identity;
25 
27  static const Matrix44 bias;
28 
35  static void Invert( const Matrix44& matrix, Matrix44& out );
36 
44  static void InverseTranspose( const float m[ 16 ], float* out );
45 
51  static void Multiply( const Matrix44& a, const Matrix44& b, Matrix44& out );
52 
60  static void TransformPoint( const Vec4& vec, const Matrix44& mat, Vec4* out );
61 
69  static void TransformPoint( const Vec3& vec, const Matrix44& mat, Vec3* out );
70 
78  static void TransformDirection( const Vec3& dir, const Matrix44& mat, Vec3* out );
79 
82  {
83  MakeIdentity();
84  }
85 
87  Matrix44( float xDeg, float yDeg, float zDeg )
88  {
89  MakeRotationXYZ( xDeg, yDeg, zDeg );
90  }
91 
97  Matrix44( const Matrix44& other );
98 
100  Matrix44( const float* data );
101 
106  Matrix44& operator=( const Matrix44& other )
107  {
108  InitFrom( other.m );
109  return *this;
110  }
111 
117  void Scale( float x, float y, float z );
118 
120  void InitFrom( const float* data );
121 
123  void MakeIdentity();
124 
132  void MakeLookAt( const Vec3& eye, const Vec3& center, const Vec3& up );
133 
143  void MakeProjection( float fovDegrees, float aspect, float nearDepth, float farDepth );
144 
155  void MakeProjection( float left, float right, float bottom, float top, float nearDepth, float farDepth );
156 
164  void MakeRotationXYZ( float xDeg, float yDeg, float zDeg );
165 
167  void Print() const;
168 
170  void Transpose( Matrix44& out ) const;
171 
173  void Translate( const Vec3& v );
174 
176  float m[16];
177 }
178 #ifdef SIMD_SSE3
179 END_ALIGNED( Matrix44, 16 )
180 #endif
181 ;
182 
183 #endif
static const Matrix44 identity
Identity matrix.
Definition: Matrix.hpp:24
float m[16]
Member data, row-major.
Definition: Matrix.hpp:176
static const Matrix44 bias
Converts depth coordinates from [-1,1] to [0,1]. This is needed to sample the shadow map texture...
Definition: Matrix.hpp:27
4-component vector.
Definition: Vec3.hpp:380
Matrix44 & operator=(const Matrix44 &other)
Definition: Matrix.hpp:106
3-component vector.
Definition: Vec3.hpp:22
Matrix44(float xDeg, float yDeg, float zDeg)
Constructor that makes an XYZ rotation matrix.
Definition: Matrix.hpp:87
Row-major 4x4 Matrix.
Definition: Matrix.hpp:20
Matrix44()
Constructor. Inits to identity.
Definition: Matrix.hpp:81