Aether3D Game Engine
Matrix.hpp
1 #ifndef MATRIX_H
2 #define MATRIX_H
3 
4 #include "Macros.hpp"
5 
6 namespace ae3d
7 {
8  struct Vec3;
9  struct Vec4;
10 
11  /* 4x4 Matrix. */
12  struct ALIGNAS( 16 ) Matrix44
13  {
14  /* Identity matrix. */
15  static const Matrix44 identity;
16 
17  /* Converts depth coordinates from [-1,1] to [0,1]. This is needed to sample the shadow map texture. */
18  static const Matrix44 bias;
19 
26  static void Invert( const Matrix44& matrix, Matrix44& out );
27 
35  static void InverseTranspose( const float m[ 16 ], float* out );
36 
42  static void Multiply( const Matrix44& a, const Matrix44& b, Matrix44& out );
43 
51  static void TransformPoint( const Vec4& vec, const Matrix44& mat, Vec4* out );
52 
60  static void TransformPoint( const Vec3& vec, const Matrix44& mat, Vec3* out );
61 
69  static void TransformDirection( const Vec3& dir, const Matrix44& mat, Vec3* out );
70 
72  Matrix44()
73  {
74  MakeIdentity();
75  }
76 
77  /* Constructor that makes an XYZ rotation matrix. */
78  Matrix44( float xDeg, float yDeg, float zDeg )
79  {
80  MakeRotationXYZ( xDeg, yDeg, zDeg );
81  }
82 
88  Matrix44( const Matrix44& other );
89 
91  explicit Matrix44( const float* data );
92 
97  Matrix44& operator=( const Matrix44& other )
98  {
99  if (this == &other)
100  {
101  return *this;
102  }
103 
104  InitFrom( &other.m[ 0 ] );
105  return *this;
106  }
107 
113  void Scale( float x, float y, float z );
114 
115  /* \param data 4x4 column-major matrix data. */
116  void InitFrom( const float* data );
117 
118  /* Resets this matrix. */
119  void MakeIdentity();
120 
128  void MakeLookAt( const Vec3& eye, const Vec3& center, const Vec3& up );
129 
139  void MakeProjection( float fovDegrees, float aspect, float nearDepth, float farDepth );
140 
151  void MakeProjection( float left, float right, float bottom, float top, float nearDepth, float farDepth );
152 
160  void MakeRotationXYZ( float xDeg, float yDeg, float zDeg );
161 
162  /* \param out Result of transpose. */
163  void Transpose( Matrix44& out ) const;
164 
165  /* \param v Translation. */
166  void Translate( const Vec3& v );
167 
168  /* Member data, row-major. */
169  float m[16];
170  };
171 }
172 #endif
Definition: AudioClip.hpp:4