1#include "EulerRotation.hpp"
2#include "Matrix3x3.hpp"
13#define n11 elements[0]
14#define n12 elements[1]
15#define n13 elements[2]
16#define n14 elements[3]
17#define n21 elements[4]
18#define n22 elements[5]
19#define n23 elements[6]
20#define n24 elements[7]
21#define n31 elements[8]
22#define n32 elements[9]
23#define n33 elements[10]
24#define n34 elements[11]
25#define n41 elements[12]
26#define n42 elements[13]
27#define n43 elements[14]
28#define n44 elements[15]
102 0, std::cos(angle.
x), -std::sin(angle.
x), 0,
103 0, std::sin(angle.
x), std::cos(angle.
x), 0,
106 auto rotationY =
Matrix4x4(std::cos(angle.
y), 0, std::sin(angle.
y), 0,
108 -std::sin(angle.
y), 0, std::cos(angle.
y), 0,
111 auto rotationZ =
Matrix4x4(std::cos(angle.
z), -std::sin(angle.
z), 0, 0,
112 std::sin(angle.
z), std::cos(angle.
z), 0, 0,
117 auto const &firstRotation =
118 getRotationMatrix(rotationX, rotationY, rotationZ, angle.
order, 0);
119 auto const &secondRotation =
120 getRotationMatrix(rotationX, rotationY, rotationZ, angle.
order, 1);
121 auto const &thirdRotation =
122 getRotationMatrix(rotationX, rotationY, rotationZ, angle.
order, 2);
124 return thirdRotation * secondRotation * firstRotation;
136 0, scaleFactor.
y, 0, 0,
137 0, 0, scaleFactor.
z, 0,
162 Matrix4x4(
double _n11,
double _n12,
double _n13,
double _n14,
double _n21,
163 double _n22,
double _n23,
double _n24,
double _n31,
double _n32,
164 double _n33,
double _n34,
double _n41,
double _n42,
double _n43,
166 :
elements({_n11, _n12, _n13, _n14, _n21, _n22, _n23, _n24, _n31, _n32,
167 _n33, _n34, _n41, _n42, _n43, _n44}) {}
190 for (
auto i = 0; i < 16; ++i) {
219 double _n21,
double _n22,
double _n23,
double _n24,
220 double _n31,
double _n32,
double _n33,
double _n34,
221 double _n41,
double _n42,
double _n43,
double _n44) {
252 double get(
int row,
int column)
const {
253 return elements.at(row * 4 + column);
266 elements.at(row * 4 + column) = value;
277 return set(1, 0, 0, 0,
293 n14 * n23 * n32 * n41 - n13 * n24 * n32 * n41 - n14 * n22 * n33 * n41 + n12 * n24 * n33 * n41 +
294 n13 * n22 * n34 * n41 - n12 * n23 * n34 * n41 - n14 * n23 * n31 * n42 + n13 * n24 * n31 * n42 +
295 n14 * n21 * n33 * n42 - n11 * n24 * n33 * n42 - n13 * n21 * n34 * n42 + n11 * n23 * n34 * n42 +
296 n14 * n22 * n31 * n43 - n12 * n24 * n31 * n43 - n14 * n21 * n32 * n43 + n11 * n24 * n32 * n43 +
297 n12 * n21 * n34 * n43 - n11 * n22 * n34 * n43 - n13 * n22 * n31 * n44 + n12 * n23 * n31 * n44 +
298 n13 * n21 * n32 * n44 - n11 * n23 * n32 * n44 - n12 * n21 * n33 * n44 + n11 * n22 * n33 * n44;
340 n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
341 n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
342 n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
343 n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34,
344 n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44,
345 n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44,
346 n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44,
347 n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34,
348 n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44,
349 n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44,
350 n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44,
351 n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34,
352 n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43,
353 n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43,
354 n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43,
355 n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33
359 return (1.0 / det) * adjoint;
372 return Matrix3x3(n11, n12, n13, n21, n22, n23, n31, n32, n33);
396 for (
auto i = 0; i < 16; ++i) {
424 for (
auto i = 0; i < 16; ++i) {
479 for (
auto i = 0; i < 16; ++i) {
518 return Matrix4x4(a.n11 + b.n11, a.n12 + b.n12, a.n13 + b.n13, a.n14 + b.n14,
519 a.n21 + b.n21, a.n22 + b.n22, a.n23 + b.n23, a.n24 + b.n24,
520 a.n31 + b.n31, a.n32 + b.n32, a.n33 + b.n33, a.n34 + b.n34,
521 a.n41 + b.n41, a.n42 + b.n42, a.n43 + b.n43, a.n44 + b.n44);
534 return Matrix4x4(a.n11 + s, a.n12 + s, a.n13 + s, a.n14 + s,
535 a.n21 + s, a.n22 + s, a.n23 + s, a.n24 + s,
536 a.n31 + s, a.n32 + s, a.n33 + s, a.n34 + s,
537 a.n41 + s, a.n42 + s, a.n43 + s, a.n44 + s);
559 return Matrix4x4(a.n11 - b.n11, a.n12 - b.n12, a.n13 - b.n13, a.n14 - b.n14,
560 a.n21 - b.n21, a.n22 - b.n22, a.n23 - b.n23, a.n24 - b.n24,
561 a.n31 - b.n31, a.n32 - b.n32, a.n33 - b.n33, a.n34 - b.n34,
562 a.n41 - b.n41, a.n42 - b.n42, a.n43 - b.n43, a.n44 - b.n44);
576 return Matrix4x4(a.n11 - s, a.n12 - s, a.n13 - s, a.n14 - s,
577 a.n21 - s, a.n22 - s, a.n23 - s, a.n24 - s,
578 a.n31 - s, a.n32 - s, a.n33 - s, a.n34 - s,
579 a.n41 - s, a.n42 - s, a.n43 - s, a.n44 - s);
594 return Matrix4x4(s - a.n11, s - a.n12, s - a.n13, s - a.n14,
595 s - a.n21, s - a.n22, s - a.n23, s - a.n24,
596 s - a.n31, s - a.n32, s - a.n33, s - a.n34,
597 s - a.n41, s - a.n42, s - a.n43, s - a.n44);
613 a.n11 * b.n11 + a.n12 * b.n21 + a.n13 * b.n31 + a.n14 * b.n41,
614 a.n11 * b.n12 + a.n12 * b.n22 + a.n13 * b.n32 + a.n14 * b.n42,
615 a.n11 * b.n13 + a.n12 * b.n23 + a.n13 * b.n33 + a.n14 * b.n43,
616 a.n11 * b.n14 + a.n12 * b.n24 + a.n13 * b.n34 + a.n14 * b.n44,
617 a.n21 * b.n11 + a.n22 * b.n21 + a.n23 * b.n31 + a.n24 * b.n41,
618 a.n21 * b.n12 + a.n22 * b.n22 + a.n23 * b.n32 + a.n24 * b.n42,
619 a.n21 * b.n13 + a.n22 * b.n23 + a.n23 * b.n33 + a.n24 * b.n43,
620 a.n21 * b.n14 + a.n22 * b.n24 + a.n23 * b.n34 + a.n24 * b.n44,
621 a.n31 * b.n11 + a.n32 * b.n21 + a.n33 * b.n31 + a.n34 * b.n41,
622 a.n31 * b.n12 + a.n32 * b.n22 + a.n33 * b.n32 + a.n34 * b.n42,
623 a.n31 * b.n13 + a.n32 * b.n23 + a.n33 * b.n33 + a.n34 * b.n43,
624 a.n31 * b.n14 + a.n32 * b.n24 + a.n33 * b.n34 + a.n34 * b.n44,
625 a.n41 * b.n11 + a.n42 * b.n21 + a.n43 * b.n31 + a.n44 * b.n41,
626 a.n41 * b.n12 + a.n42 * b.n22 + a.n43 * b.n32 + a.n44 * b.n42,
627 a.n41 * b.n13 + a.n42 * b.n23 + a.n43 * b.n33 + a.n44 * b.n43,
628 a.n41 * b.n14 + a.n42 * b.n24 + a.n43 * b.n34 + a.n44 * b.n44);
641 return Matrix4x4(a.n11 * s, a.n12 * s, a.n13 * s, a.n14 * s,
642 a.n21 * s, a.n22 * s, a.n23 * s, a.n24 * s,
643 a.n31 * s, a.n32 * s, a.n33 * s, a.n34 * s,
644 a.n41 * s, a.n42 * s, a.n43 * s, a.n44 * s);
666 return Vector4(a.n11 * v.x + a.n12 * v.y + a.n13 * v.z + a.n14 * v.w,
667 a.n21 * v.x + a.n22 * v.y + a.n23 * v.z + a.n24 * v.w,
668 a.n31 * v.x + a.n32 * v.y + a.n33 * v.z + a.n34 * v.w,
669 a.n41 * v.x + a.n42 * v.y + a.n43 * v.z + a.n44 * v.w);
681 return Matrix4x4(a.n11 / b.n11, a.n12 / b.n12, a.n13 / b.n13, a.n14 / b.n14,
682 a.n21 / b.n21, a.n22 / b.n22, a.n23 / b.n23, a.n24 / b.n24,
683 a.n31 / b.n31, a.n32 / b.n32, a.n33 / b.n33, a.n34 / b.n34,
684 a.n41 / b.n41, a.n42 / b.n42, a.n43 / b.n43, a.n44 / b.n44);
697 return Matrix4x4(a.n11 / s, a.n12 / s, a.n13 / s, a.n14 / s,
698 a.n21 / s, a.n22 / s, a.n23 / s, a.n24 / s,
699 a.n31 / s, a.n32 / s, a.n33 / s, a.n34 / s,
700 a.n41 / s, a.n42 / s, a.n43 / s, a.n44 / s);
714 return Matrix4x4(s / a.n11, s / a.n12, s / a.n13, s / a.n14,
715 s / a.n21, s / a.n22, s / a.n23, s / a.n24,
716 s / a.n31, s / a.n32, s / a.n33, s / a.n34,
717 s / a.n41, s / a.n42, s / a.n43, s / a.n44);
The Euler rotation class.
Definition EulerRotation.hpp:17
double x
The amount of rotation about the local X axis in radians.
Definition EulerRotation.hpp:19
double y
The amount of rotation about the local Y axis in radians.
Definition EulerRotation.hpp:20
double z
The amount of rotation about the local Z axis in radians.
Definition EulerRotation.hpp:21
EulerRotationOrder order
The order to perform the rotations around individual axes.
Definition EulerRotation.hpp:23
The matrix class.
Definition Matrix3x3.hpp:24
The matrix class.
Definition Matrix4x4.hpp:35
Matrix4x4 & operator/=(const Matrix4x4 &m)
Divides the elements of this matrix by the corresponding elements of the specified matrix.
Definition Matrix4x4.hpp:478
Matrix4x4 inverse() const
Returns the inverse of this matrix or the zero matrix if this matrix does not have an inverse.
Definition Matrix4x4.hpp:331
Matrix4x4 & operator+=(double s)
Adds the specified constant to all elements in this matrix.
Definition Matrix4x4.hpp:409
Matrix4x4 transpose() const
Returns the transpose of this matrix.
Definition Matrix4x4.hpp:310
Matrix4x4 & operator*=(double s)
Multiplies the elements of this matrix with the specified constant.
Definition Matrix4x4.hpp:463
Matrix4x4 & set(int row, int column, int value)
Sets the element at the specified row and column of this matrix to the specified value.
Definition Matrix4x4.hpp:265
double get(int row, int column) const
Gets the element at the specified row and column of this matrix with bounds checking.
Definition Matrix4x4.hpp:252
friend Matrix4x4 operator-(double s, const Matrix4x4 &a)
Substracts a matrix from a constant matrix.
Definition Matrix4x4.hpp:592
static Matrix4x4 fromTranslation(const Vector3 &distance)
Returns a translation matrix for the specified translation for post-multiplication ( where is the h...
Definition Matrix4x4.hpp:79
Matrix3x3 topLeft3x3Matrix() const
Returns the top-left matrix of this matrix.
Definition Matrix4x4.hpp:371
Matrix4x4(double _n11, double _n12, double _n13, double _n14, double _n21, double _n22, double _n23, double _n24, double _n31, double _n32, double _n33, double _n34, double _n41, double _n42, double _n43, double _n44)
Creates a new matrix with the specified elements.
Definition Matrix4x4.hpp:162
friend Matrix4x4 operator/(const Matrix4x4 &a, double s)
Divides all elements of a matrix by a constant.
Definition Matrix4x4.hpp:695
friend Matrix4x4 operator*(double s, const Matrix4x4 &a)
Multiplies all elements of a matrix with a constant.
Definition Matrix4x4.hpp:656
double determinant() const
Returns the determinant of this matrix.
Definition Matrix4x4.hpp:290
static Matrix4x4 identity()
Returns a identity matrix.
Definition Matrix4x4.hpp:45
double operator[](std::size_t index) const
Returns the element at the specified index of this matrix without bounds checking and assuming row-ma...
Definition Matrix4x4.hpp:387
friend Matrix4x4 operator/(const Matrix4x4 &a, const Matrix4x4 &b)
Returns the element-wise division of two matrices.
Definition Matrix4x4.hpp:679
static Matrix4x4 fromRotation(const EulerRotation &angle)
Returns a rotation matrix for the specified rotation for post-multiplication ( where is the homogen...
Definition Matrix4x4.hpp:99
static Matrix4x4 fromScale(const Vector3 &scaleFactor)
Returns a scale matrix for the specified scale factor.
Definition Matrix4x4.hpp:133
Matrix4x4 & operator-=(double s)
Substracts the specified constant from all elements in this matrix.
Definition Matrix4x4.hpp:437
Matrix4x4 & reset()
Resets this matrix to the identity matrix.
Definition Matrix4x4.hpp:275
Matrix4x4 & operator/=(double s)
Divides the elements of this matrix with the specified constant.
Definition Matrix4x4.hpp:492
Matrix4x4 & operator*=(const Matrix4x4 &m)
Multiplies this matrix with another matrix and copies the result into this instance.
Definition Matrix4x4.hpp:455
friend Matrix4x4 operator-(const Matrix4x4 &a, double s)
Substracts a constant from all elements of a matrix.
Definition Matrix4x4.hpp:574
Matrix4x4 & operator-=(const Matrix4x4 &m)
Substracts the specified matrix from this matrix.
Definition Matrix4x4.hpp:423
Matrix4x4 & set(double _n11, double _n12, double _n13, double _n14, double _n21, double _n22, double _n23, double _n24, double _n31, double _n32, double _n33, double _n34, double _n41, double _n42, double _n43, double _n44)
Sets the elements of this matrix.
Definition Matrix4x4.hpp:218
Matrix4x4 clone() const
Returns a copy of this matrix.
Definition Matrix4x4.hpp:174
static Matrix4x4 zero()
Returns a zero matrix.
Definition Matrix4x4.hpp:59
friend Vector4 operator*(const Matrix4x4 &a, const Vector4 &v)
Multiplies a matrix with a four-dimensional vector.
Definition Matrix4x4.hpp:665
Matrix4x4 & operator+=(const Matrix4x4 &m)
Adds the specified matrix to this matrix.
Definition Matrix4x4.hpp:395
friend bool operator==(const Matrix4x4 &a, const Matrix4x4 &b)=default
Returns whether two matrices are equal.
friend Matrix4x4 operator*(const Matrix4x4 &a, const Matrix4x4 &b)
Multiplies two matrices.
Definition Matrix4x4.hpp:611
friend Matrix4x4 operator+(const Matrix4x4 &a, const Matrix4x4 &b)
Adds two matrices.
Definition Matrix4x4.hpp:516
Matrix4x4 & copy(const Matrix4x4 &source)
Copies the elements of another matrix into this matrix.
Definition Matrix4x4.hpp:189
friend Matrix4x4 operator+(const Matrix4x4 &a, double s)
Adds a constant to all elements of a matrix.
Definition Matrix4x4.hpp:532
friend Matrix4x4 operator*(const Matrix4x4 &a, double s)
Multiplies all elements of a matrix with a constant.
Definition Matrix4x4.hpp:639
friend Matrix4x4 operator/(double s, const Matrix4x4 &a)
Returns the element-wise division of a constant matrix and a matrix.
Definition Matrix4x4.hpp:712
friend Matrix4x4 operator-(const Matrix4x4 &a, const Matrix4x4 &b)
Substracts 2 matrices.
Definition Matrix4x4.hpp:557
friend Matrix4x4 operator+(double s, const Matrix4x4 &a)
Adds a constant to all elements of a matrix.
Definition Matrix4x4.hpp:548
std::array< double, 16 > elements
The array containing the elements of this matrix in row-major order.
Definition Matrix4x4.hpp:37
The 3D vector class.
Definition Vector3.hpp:20
double z
The z component of this 3D vector.
Definition Vector3.hpp:24
double y
The y component of this 3D vector.
Definition Vector3.hpp:23
double x
The x component of this 3D vector.
Definition Vector3.hpp:22
The 4D vector class.
Definition Vector4.hpp:20
The t software 3D graphics library namespace.
Definition algorithms.hpp:12
EulerRotationOrder
The Euler rotation order.
Definition constants.hpp:19