18 for (
int i = 0;
i < 4;
i++) {
19 e[
i][3] =
d.perspective.
e[
i];
25 for (
int i = 0;
i < 3;
i++) {
26 for (
int j = 0; j < 3; j++) {
27 e[3][
i] +=
d.translation.e[j] *
e[j][
i];
37 const auto x = -
d.rotation.x;
38 const auto y = -
d.rotation.y;
39 const auto z = -
d.rotation.z;
40 const auto w =
d.rotation.w;
46 rotation.
e[0][0] = 1.0 - 2.0 * (
y *
y + z * z);
47 rotation.
e[0][1] = 2.0 * (
x *
y - z * w);
48 rotation.
e[0][2] = 2.0 * (
x * z +
y * w);
49 rotation.
e[1][0] = 2.0 * (
x *
y + z * w);
50 rotation.
e[1][1] = 1.0 - 2.0 * (
x *
x + z * z);
51 rotation.
e[1][2] = 2.0 * (
y * z -
x * w);
52 rotation.
e[2][0] = 2.0 * (
x * z -
y * w);
53 rotation.
e[2][1] = 2.0 * (
y * z +
x * w);
54 rotation.
e[2][2] = 1.0 - 2.0 * (
x *
x +
y *
y);
56 *
this = *
this * rotation;
63 if (
d.shear.e[2] != 0) {
64 shear.
e[2][1] =
d.shear.e[2];
65 *
this = *
this * shear;
68 if (
d.shear.e[1] != 0) {
70 shear.
e[2][0] =
d.shear.e[1];
71 *
this = *
this * shear;
74 if (
d.shear.e[0] != 0) {
76 shear.
e[1][0] =
d.shear.e[0];
77 *
this = *
this * shear;
83 for (
int i = 0;
i < 3;
i++) {
84 for (
int j = 0; j < 3; j++) {
85 e[
i][j] *=
d.scale.
e[
i];
92 m[0] + o.
m[0],
m[1] + o.
m[1],
m[2] + o.
m[2],
m[3] + o.
m[3],
93 m[4] + o.
m[4],
m[5] + o.
m[5],
m[6] + o.
m[6],
m[7] + o.
m[7],
94 m[8] + o.
m[8],
m[9] + o.
m[9],
m[10] + o.
m[10],
m[11] + o.
m[11],
95 m[12] + o.
m[12],
m[13] + o.
m[13],
m[14] + o.
m[14],
m[15] + o.
m[15]
101 m[5] *
m[10] *
m[15] -
m[5] *
m[11] *
m[14] -
m[9] *
m[6] *
m[15] +
102 m[9] *
m[7] *
m[14] +
m[13] *
m[6] *
m[11] -
m[13] *
m[7] *
m[10],
104 -
m[1] *
m[10] *
m[15] +
m[1] *
m[11] *
m[14] +
m[9] *
m[2] *
m[15] -
105 m[9] *
m[3] *
m[14] -
m[13] *
m[2] *
m[11] +
m[13] *
m[3] *
m[10],
107 m[1] *
m[6] *
m[15] -
m[1] *
m[7] *
m[14] -
m[5] *
m[2] *
m[15] +
108 m[5] *
m[3] *
m[14] +
m[13] *
m[2] *
m[7] -
m[13] *
m[3] *
m[6],
110 -
m[1] *
m[6] *
m[11] +
m[1] *
m[7] *
m[10] +
m[5] *
m[2] *
m[11] -
111 m[5] *
m[3] *
m[10] -
m[9] *
m[2] *
m[7] +
m[9] *
m[3] *
m[6],
113 -
m[4] *
m[10] *
m[15] +
m[4] *
m[11] *
m[14] +
m[8] *
m[6] *
m[15] -
114 m[8] *
m[7] *
m[14] -
m[12] *
m[6] *
m[11] +
m[12] *
m[7] *
m[10],
116 m[0] *
m[10] *
m[15] -
m[0] *
m[11] *
m[14] -
m[8] *
m[2] *
m[15] +
117 m[8] *
m[3] *
m[14] +
m[12] *
m[2] *
m[11] -
m[12] *
m[3] *
m[10],
119 -
m[0] *
m[6] *
m[15] +
m[0] *
m[7] *
m[14] +
m[4] *
m[2] *
m[15] -
120 m[4] *
m[3] *
m[14] -
m[12] *
m[2] *
m[7] +
m[12] *
m[3] *
m[6],
122 m[0] *
m[6] *
m[11] -
m[0] *
m[7] *
m[10] -
m[4] *
m[2] *
m[11] +
123 m[4] *
m[3] *
m[10] +
m[8] *
m[2] *
m[7] -
m[8] *
m[3] *
m[6],
125 m[4] *
m[9] *
m[15] -
m[4] *
m[11] *
m[13] -
m[8] *
m[5] *
m[15] +
126 m[8] *
m[7] *
m[13] +
m[12] *
m[5] *
m[11] -
m[12] *
m[7] *
m[9],
128 -
m[0] *
m[9] *
m[15] +
m[0] *
m[11] *
m[13] +
m[8] *
m[1] *
m[15] -
129 m[8] *
m[3] *
m[13] -
m[12] *
m[1] *
m[11] +
m[12] *
m[3] *
m[9],
131 m[0] *
m[5] *
m[15] -
m[0] *
m[7] *
m[13] -
m[4] *
m[1] *
m[15] +
132 m[4] *
m[3] *
m[13] +
m[12] *
m[1] *
m[7] -
m[12] *
m[3] *
m[5],
134 -
m[0] *
m[5] *
m[11] +
m[0] *
m[7] *
m[9] +
m[4] *
m[1] *
m[11] -
135 m[4] *
m[3] *
m[9] -
m[8] *
m[1] *
m[7] +
m[8] *
m[3] *
m[5],
137 -
m[4] *
m[9] *
m[14] +
m[4] *
m[10] *
m[13] +
m[8] *
m[5] *
m[14] -
138 m[8] *
m[6] *
m[13] -
m[12] *
m[5] *
m[10] +
m[12] *
m[6] *
m[9],
140 m[0] *
m[9] *
m[14] -
m[0] *
m[10] *
m[13] -
m[8] *
m[1] *
m[14] +
141 m[8] *
m[2] *
m[13] +
m[12] *
m[1] *
m[10] -
m[12] *
m[2] *
m[9],
143 -
m[0] *
m[5] *
m[14] +
m[0] *
m[6] *
m[13] +
m[4] *
m[1] *
m[14] -
144 m[4] *
m[2] *
m[13] -
m[12] *
m[1] *
m[6] +
m[12] *
m[2] *
m[5],
146 m[0] *
m[5] *
m[10] -
m[0] *
m[6] *
m[9] -
m[4] *
m[1] *
m[10] +
147 m[4] *
m[2] *
m[9] +
m[8] *
m[1] *
m[6] -
m[8] *
m[2] *
m[5]};
150 m[0] * tmp.
m[0] +
m[1] * tmp.m[4] +
m[2] * tmp.m[8] +
m[3] * tmp.m[12];
158 return {tmp.m[0] * det, tmp.m[1] * det, tmp.m[2] * det, tmp.m[3] * det,
159 tmp.m[4] * det, tmp.m[5] * det, tmp.m[6] * det, tmp.m[7] * det,
160 tmp.m[8] * det, tmp.m[9] * det, tmp.m[10] * det, tmp.m[11] * det,
161 tmp.m[12] * det, tmp.m[13] * det, tmp.m[14] * det, tmp.m[15] * det};
182 auto b00 = a00 * a11 - a01 * a10;
183 auto b01 = a00 * a12 - a02 * a10;
184 auto b02 = a00 * a13 - a03 * a10;
185 auto b03 = a01 * a12 - a02 * a11;
186 auto b04 = a01 * a13 - a03 * a11;
187 auto b05 = a02 * a13 - a03 * a12;
188 auto b06 = a20 * a31 - a21 * a30;
189 auto b07 = a20 * a32 - a22 * a30;
190 auto b08 = a20 * a33 - a23 * a30;
191 auto b09 = a21 * a32 - a22 * a31;
192 auto b10 = a21 * a33 - a23 * a31;
193 auto b11 = a22 * a33 - a23 * a32;
195 return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
208 if (
self.e[3][3] == 0) {
212 for (
int i = 0;
i < 4;
i++) {
213 for (
int j = 0; j < 4; j++) {
223 for (
int i = 0;
i < 3;
i++) {
224 perpectiveMatrix.
e[
i][3] = 0;
227 perpectiveMatrix.
e[3][3] = 1;
240 if (
self.e[0][3] != 0.0 ||
self.e[1][3] != 0.0 ||
self.e[2][3] != 0.0) {
277 for (
int i = 0;
i < 3;
i++) {
324 if (row[0].Dot(row[1].Cross(row[2])) < 0) {
329 for (
int i = 0;
i < 3;
i++) {
342 0.5 * sqrt(fmax(1.0 + row[0].
x - row[1].
y - row[2].z, 0.0));
344 0.5 * sqrt(fmax(1.0 - row[0].
x + row[1].
y - row[2].z, 0.0));
346 0.5 * sqrt(fmax(1.0 - row[0].
x - row[1].
y + row[2].z, 0.0));
348 0.5 * sqrt(fmax(1.0 + row[0].
x + row[1].
y + row[2].z, 0.0));
350 if (row[2].
y > row[1].z) {
353 if (row[0].z > row[2].
x) {
356 if (row[1].
x > row[0].
y) {
377 if (b == 0.0f && c == 0.0f) {
378 return {{std::abs(a), std::abs(
d)}};
381 if (a == 0.0f &&
d == 0.0f) {
382 return {{std::abs(b), std::abs(c)}};
389 double a2 = a * a + b * b;
390 double b2 = a * c + b *
d;
392 double d2 = c * c +
d *
d;
410 double minus_B = a2 + d2;
411 double C = a2 * d2 - b2 * c2;
412 double B_squared_minus_4AC = minus_B * minus_B - 4 * 1.0f * C;
414 double quadratic_sqrt;
415 if (B_squared_minus_4AC <= 0.0f) {
420 quadratic_sqrt = 0.0f;
422 quadratic_sqrt = std::sqrt(B_squared_minus_4AC);
429 return {{std::sqrt((minus_B - quadratic_sqrt) / 2.0f),
430 std::sqrt((minus_B + quadratic_sqrt) / 2.0f)}};
441 Vector4 defaultPerspective(0.0, 0.0, 0.0, 1.0);
446 Shear noShear(0.0, 0.0, 0.0);
447 if (
shear != noShear) {
451 Vector3 defaultScale(1.0, 1.0, 1.0);
452 if (
scale != defaultScale) {
456 Vector3 defaultTranslation(0.0, 0.0, 0.0);
#define FML_DCHECK(condition)
constexpr float kEhCloseEnough
uint64_t GetComponentsMask() const
A 4x4 matrix using column-major storage.
bool IsInvertible() const
Matrix operator+(const Vector3 &t) const
std::optional< MatrixDecomposition > Decompose() const
constexpr bool HasPerspective2D() const
std::optional< std::pair< Scalar, Scalar > > GetScales2D() const
Compute the two non-negative scales applied by this matrix to 2D coordinates and return them as an op...
Scalar GetDeterminant() const
constexpr Matrix Transpose() const
Vector3 Normalize() const
static constexpr Vector3 Combine(const Vector3 &a, Scalar aScale, const Vector3 &b, Scalar bScale)
constexpr Scalar Dot(const Vector3 &other) const