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  InitFrom( other.m );
100  return *this;
101  }
102 
108  void Scale( float x, float y, float z );
109 
110  /* \param data 4x4 column-major matrix data. */
111  void InitFrom( const float* data );
112 
113  /* Resets this matrix. */
114  void MakeIdentity();
115 
123  void MakeLookAt( const Vec3& eye, const Vec3& center, const Vec3& up );
124 
134  void MakeProjection( float fovDegrees, float aspect, float nearDepth, float farDepth );
135 
146  void MakeProjection( float left, float right, float bottom, float top, float nearDepth, float farDepth );
147 
155  void MakeRotationXYZ( float xDeg, float yDeg, float zDeg );
156 
157  /* \param out Result of transpose. */
158  void Transpose( Matrix44& out ) const;
159 
160  /* \param v Translation. */
161  void Translate( const Vec3& v );
162 
163  /* Member data, row-major. */
164  float m[16];
165  };
166 }
167 #endif
Definition: AudioClip.hpp:4