This union represents 4x4-component floating point matrix. It is widely used in transformation calculations.
You can find more information in comments below.
union Matrix
{
struct
{
float _11, _12, _13, _14;
float _21, _22, _23, _24;
float _31, _32, _33, _34;
float _41, _42, _43, _44;
};
Vector Columns[4];
float Elements[16];
Matrix() = default;
Matrix(const Matrix &other) = default;
Matrix(Matrix &&other) = default;
Matrix(const Vector &column1, const Vector &column2, const Vector &column3, const Vector &column4); // Create and populate with specified values
Matrix &operator=(const Matrix &other) = default;
Matrix &operator=(Matrix &&other) = default;
const Vector &operator[](const int index) const; // Get column
Vector &operator[](const int index); // Get/set column
void transpose(); // Transpose this matrix
Matrix transposed() const; // Return transposed matrix
float determinant() const; // Return determinant of matrix
void inverse(); // Inverse this matrix
Matrix inversed() const; // Return inversed matrix
void identity(); // Makes identity matrix
void diagonal(const float value); // Make this matrix diagonal with all diagonal elements equal to specified value
void diagonal(const float v11, const float v22, const float v33, const float v44); // Make this matrix diagonal with diagonal elements equal to specified values
void translate(const float x, const float y, const float z); // Make translation matrix
void scale(const float x, const float y, const float z); // Make scaling matrix
void rotate_x(const float angle); // Make rotation around X-axis matrix
void rotate_y(const float angle); // Make rotation around Y-axis matrix
void rotate_z(const float angle); // Make rotation around Z-axis matrix
void rotate(const float angle_z, const float angle_y, const float angle_x); // Make rotation matrix with spaceified rotation angles around axes
void rotate(const float angle, const Vector &v); // Make rotation matrix around specified vector/axes
void lookat(const Vector &camera, const Vector &target, const Vector &up); // Make "look at" projection matrix
void frustum(const float l, const float t, const float r, const float b, const float n, const float f); // Make "frustum" projection matrix
void perspective(const float fov, const float aspect, const float n, const float f); // Make "perspective" projection matrix
void ortho(const float l, const float t, const float r, const float b, const float n, const float f); // Make orthogonal projection matrix
#ifdef _DEBUG
void print() const;
#endif
};
Following operators are also available.
Matrix operator+(const Matrix &a, const float value); // Add scalar value to all elements
Matrix operator-(const Matrix &a, const float value); // Subtract scalar value from all elements
Matrix operator*(const Matrix &a, const float value); // Multiply all elements on scalar value
Matrix operator/(const Matrix &a, const float value); // Divide all elements on scalar value
Matrix operator+(const float value, const Matrix &a); // Add scalar value to each element and build from them new matrix
Matrix operator-(const float value, const Matrix &a); // Subtract from value each element and build from them new matrix
Matrix operator*(const float value, const Matrix &a); // Multiply scalar value on each element and build from them new matrix
Matrix operator/(const float value, const Matrix &a); // Divide scalar value on each element and build from them new matrix
Matrix &operator+=(Matrix &a, const float value); // Add scalar value to all elements of this matrix
Matrix &operator-=(Matrix &a, const float value); // Subtract scalar value from all elements of this matrix
Matrix &operator*=(Matrix &a, const float value); // Multiply all elements of this matrix on scalar value
Matrix &operator/=(Matrix &a, const float value); // Divide all elements of this matrix on scalar value
Vector operator*(const Vector &v, const Matrix &m); // Multiply vector by matrix
Vector &operator*=(Vector &v, const Matrix &m); // Multiply vector by matrix and store result in the vector
Matrix operator*(const Matrix &a, const Matrix &b); // Multiply matrices
Matrix &operator*=(Matrix &a, const Matrix &b); // Multiply matrices and store result in first one
std::wostream &operator<<(std::wostream &stream, const Matrix &a); // Output as source code
Namespace: | nitisa |
Include: |
Nitisa/Core/Math/Matrix.h (For union declaration) Nitisa/Core/Math/MatrixUtils.h (For standalone operators) |