26 static_assert (
sizeof (
Matrix4x4 ) ==
sizeof ( float ) * 16,
"Size of Matrix4x4 is not the same as float[16]." );
38 memcpy (
mMatrix, aMatrix4x4,
sizeof (
float ) * 16 );
43 const float* scalar = aList.begin();
44 for (
size_t i = 0; i < 16; ++i )
46 mMatrix[i] = ( scalar != aList.end() ) ? *scalar++ : ( i % 5 ) ? 0.0f : 1.0f;
69 void Matrix4x4::Frustum (
float aLeft,
float aRight,
float aBottom,
float aTop,
float aNear,
float aFar )
73 mMatrix[0] = ( 2 * aNear ) / ( aRight - aLeft );
79 mMatrix[4] = - ( ( aRight + aLeft ) / ( aRight - aLeft ) );
80 mMatrix[5] = - ( ( aBottom + aTop ) / ( aBottom - aTop ) );
81 mMatrix[6] = ( ( aFar + aNear ) / ( aFar - aNear ) );
86 mMatrix[9] = ( 2 * aNear ) / ( aBottom - aTop );
93 mMatrix[14] = - ( ( 2 * aFar * aNear ) / ( aFar - aNear ) );
97 void Matrix4x4::Ortho (
float aLeft,
float aRight,
float aBottom,
float aTop,
float aNear,
float aFar )
103 mMatrix[0] = ( 2.0f / ( aRight - aLeft ) );
111 mMatrix[6] = - ( 2.0f / ( aFar - aNear ) );
116 mMatrix[9] = ( 2.0f / ( aTop - aBottom ) );
121 mMatrix[12] = - ( ( aRight + aLeft ) / ( aRight - aLeft ) );
122 mMatrix[13] = - ( ( aTop + aBottom ) / ( aTop - aBottom ) );
123 mMatrix[14] = - ( ( aFar + aNear ) / ( aFar - aNear ) );
129 float fH = std::tan ( aFieldOfVision *
static_cast<float> ( M_PI ) / 360.0f ) * aNear;
130 float fW = fH * aAspect;
131 Frustum ( -fW, fW, -fH, fH, aNear, aFar );
176 assert ( aIndex < 16 );
182 auto radians = float ( ( angle / 180.0f ) * M_PI );
183 float c = cosf ( radians );
184 float s = sinf ( radians );
187 x * x * ( 1 - c ) + c,
188 x * y * ( 1 - c ) - z * s,
189 x * z * ( 1 - c ) + y * s,
191 y * x * ( 1 - c ) + z * s,
192 y * y * ( 1 - c ) + c,
193 y * z * ( 1 - c ) - x * s,
195 x * z * ( 1 - c ) - y * s,
196 y * z * ( 1 - c ) + x * s,
197 z * z * ( 1 - c ) + c,
215 rhs[0] * lhs[0] + rhs[1] * lhs[4] + rhs[2] * lhs[8] + lhs[12],
216 rhs[0] * lhs[1] + rhs[1] * lhs[5] + rhs[2] * lhs[9] + lhs[13],
217 rhs[0] * lhs[2] + rhs[1] * lhs[6] + rhs[2] * lhs[10] + lhs[14]
230 std::abs ( aMatrix4x4[0] ),
231 std::abs ( aMatrix4x4[1] ),
232 std::abs ( aMatrix4x4[2] ),
233 std::abs ( aMatrix4x4[3] ),
234 std::abs ( aMatrix4x4[4] ),
235 std::abs ( aMatrix4x4[5] ),
236 std::abs ( aMatrix4x4[6] ),
237 std::abs ( aMatrix4x4[7] ),
238 std::abs ( aMatrix4x4[8] ),
239 std::abs ( aMatrix4x4[9] ),
240 std::abs ( aMatrix4x4[10] ),
241 std::abs ( aMatrix4x4[11] ),
242 std::abs ( aMatrix4x4[12] ),
243 std::abs ( aMatrix4x4[13] ),
244 std::abs ( aMatrix4x4[14] ),
245 std::abs ( aMatrix4x4[15] )
252 os << std::fixed << std::setprecision ( 4 );
254 for (
int row = 0; row < 4; ++row )
257 for (
int col = 0; col < 4; ++col )
259 os << std::setw ( 10 ) << m[col * 4 + row];
260 if ( col < 3 ) os <<
", ";
Inline functions related to 3D Math.
float * SetIdentityMatrix4x4(float *M)
Set a matrix to the Identity.
float * InvertMatrix(float *mat, float *dest)
Invert a 4x4 matrix.
Header for 4x4 matrix class.
Header for the 3D vector class.
4 by 4 matrix in colum mayor order.
DLL const float *const GetMatrix4x4() const
Get a pointer to the internal matrix data.
DLL Matrix4x4()
Default constructor.
DLL void Frustum(float aLeft, float aRight, float aBottom, float aTop, float aNear, float aFar)
Set up a perspective projection matrix defined by a frustum.
DLL void Perspective(float aFieldOfVision, float aAspect, float aNear, float aFar)
Set up a symmetric perspective projection matrix.
DLL const float operator[](size_t aIndex) const
Access a matrix element by index.
static DLL const Matrix4x4 GetRotationMatrix(float angle, float x, float y, float z)
Constructs the rotation matrix defined by the axis-angle provided.
DLL Matrix4x4 & operator*=(const Matrix4x4 &lhs)
Multiply this matrix by another matrix.
DLL const Matrix4x4 GetInvertedMatrix4x4()
Get the inverted matrix.
float mMatrix[16]
Lineal row mayor matrix.
DLL Matrix4x4 & Invert()
Invert this matrix in place.
static DLL const Matrix4x4 Identity
The 4x4 identity matrix constant.
DLL void Ortho(float aLeft, float aRight, float aBottom, float aTop, float aNear, float aFar)
Set up an orthographic projection matrix.
DLL ~Matrix4x4()
destructor.
DLL Matrix4x4 & Rotate(float angle, float x, float y, float z)
Apply a rotation to this matrix.
<- This is here just for the literals
std::ostream & operator<<(std::ostream &os, LogLevel level)
Inserts a color-coded log level tag into an output stream.
DLL const Matrix3x3 operator*(const Matrix3x3 &lhs, const Matrix3x3 &rhs)
Multiplies two 3x3 matrices. Multiplies two 3x3 matrices.
DLL const Matrix3x3 Abs(const Matrix3x3 &aMatrix3x3)
Compute the element-wise absolute value of a matrix.
DLL const bool operator==(const Matrix3x3 &lhs, const Matrix3x3 &rhs)
Compare two 3x3 matrices for equality.