Flutter Impeller
matrix.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_IMPELLER_GEOMETRY_MATRIX_H_
6 #define FLUTTER_IMPELLER_GEOMETRY_MATRIX_H_
7 
8 #include <cmath>
9 #include <iomanip>
10 #include <limits>
11 #include <optional>
12 #include <ostream>
13 #include <utility>
14 
20 #include "impeller/geometry/size.h"
22 
23 namespace impeller {
24 
25 //------------------------------------------------------------------------------
26 /// @brief A 4x4 matrix using column-major storage.
27 ///
28 /// Utility methods that need to make assumptions about normalized
29 /// device coordinates must use the following convention:
30 /// * Left-handed coordinate system. Positive rotation is
31 /// clockwise about axis of rotation.
32 /// * Lower left corner is -1.0f, -1.0.
33 /// * Upper right corner is 1.0f, 1.0.
34 /// * Visible z-space is from 0.0 to 1.0.
35 /// * This is NOT the same as OpenGL! Be careful.
36 /// * NDC origin is at (0.0f, 0.0f, 0.5f).
37 struct Matrix {
38  union {
39  Scalar m[16];
40  Scalar e[4][4];
42  };
43 
44  //----------------------------------------------------------------------------
45  /// Constructs a default identity matrix.
46  ///
47  constexpr Matrix()
48  // clang-format off
49  : vec{ Vector4(1.0f, 0.0f, 0.0f, 0.0f),
50  Vector4(0.0f, 1.0f, 0.0f, 0.0f),
51  Vector4(0.0f, 0.0f, 1.0f, 0.0f),
52  Vector4(0.0f, 0.0f, 0.0f, 1.0f)} {}
53  // clang-format on
54 
55  // clang-format off
56  constexpr Matrix(Scalar m0, Scalar m1, Scalar m2, Scalar m3,
57  Scalar m4, Scalar m5, Scalar m6, Scalar m7,
58  Scalar m8, Scalar m9, Scalar m10, Scalar m11,
59  Scalar m12, Scalar m13, Scalar m14, Scalar m15)
60  : vec{Vector4(m0, m1, m2, m3),
61  Vector4(m4, m5, m6, m7),
62  Vector4(m8, m9, m10, m11),
63  Vector4(m12, m13, m14, m15)} {}
64  // clang-format on
65 
66  explicit Matrix(const MatrixDecomposition& decomposition);
67 
68  // clang-format off
69  static constexpr Matrix MakeColumn(
70  Scalar m0, Scalar m1, Scalar m2, Scalar m3,
71  Scalar m4, Scalar m5, Scalar m6, Scalar m7,
72  Scalar m8, Scalar m9, Scalar m10, Scalar m11,
73  Scalar m12, Scalar m13, Scalar m14, Scalar m15){
74  return Matrix(m0, m1, m2, m3,
75  m4, m5, m6, m7,
76  m8, m9, m10, m11,
77  m12, m13, m14, m15);
78 
79  }
80  // clang-format on
81 
82  // clang-format off
83  static constexpr Matrix MakeRow(
84  Scalar m0, Scalar m1, Scalar m2, Scalar m3,
85  Scalar m4, Scalar m5, Scalar m6, Scalar m7,
86  Scalar m8, Scalar m9, Scalar m10, Scalar m11,
87  Scalar m12, Scalar m13, Scalar m14, Scalar m15){
88  return Matrix(m0, m4, m8, m12,
89  m1, m5, m9, m13,
90  m2, m6, m10, m14,
91  m3, m7, m11, m15);
92  }
93  // clang-format on
94 
95  static constexpr Matrix MakeTranslation(const Vector3& t) {
96  // clang-format off
97  return Matrix(1.0f, 0.0f, 0.0f, 0.0f,
98  0.0f, 1.0f, 0.0f, 0.0f,
99  0.0f, 0.0f, 1.0f, 0.0f,
100  t.x, t.y, t.z, 1.0f);
101  // clang-format on
102  }
103 
104  static constexpr Matrix MakeScale(const Vector3& s) {
105  // clang-format off
106  return Matrix(s.x, 0.0f, 0.0f, 0.0f,
107  0.0f, s.y, 0.0f, 0.0f,
108  0.0f, 0.0f, s.z, 0.0f,
109  0.0f, 0.0f, 0.0f, 1.0f);
110  // clang-format on
111  }
112 
113  static constexpr Matrix MakeScale(const Vector2& s) {
114  return MakeScale(Vector3(s.x, s.y, 1.0f));
115  }
116 
117  static constexpr Matrix MakeSkew(Scalar sx, Scalar sy) {
118  // clang-format off
119  return Matrix(1.0f, sy , 0.0f, 0.0f,
120  sx , 1.0f, 0.0f, 0.0f,
121  0.0f, 0.0f, 1.0f, 0.0f,
122  0.0f, 0.0f, 0.0f, 1.0f);
123  // clang-format on
124  }
125 
127  // clang-format off
128  return Matrix(
129  1.0f - 2.0f * q.y * q.y - 2.0f * q.z * q.z,
130  2.0f * q.x * q.y + 2.0f * q.z * q.w,
131  2.0f * q.x * q.z - 2.0f * q.y * q.w,
132  0.0f,
133 
134  2.0f * q.x * q.y - 2.0f * q.z * q.w,
135  1.0f - 2.0f * q.x * q.x - 2.0f * q.z * q.z,
136  2.0f * q.y * q.z + 2.0f * q.x * q.w,
137  0.0f,
138 
139  2.0f * q.x * q.z + 2.0f * q.y * q.w,
140  2.0f * q.y * q.z - 2.0f * q.x * q.w,
141  1.0f - 2.0f * q.x * q.x - 2.0f * q.y * q.y,
142  0.0f,
143 
144  0.0f,
145  0.0f,
146  0.0f,
147  1.0f);
148  // clang-format on
149  }
150 
151  static Matrix MakeRotation(Scalar radians, const Vector4& r) {
152  const Vector4 v = r.Normalize();
153 
154  const Scalar cosine = cos(radians);
155  const Scalar cosp = 1.0f - cosine;
156  const Scalar sine = sin(radians);
157 
158  // clang-format off
159  return Matrix(
160  cosine + cosp * v.x * v.x,
161  cosp * v.x * v.y + v.z * sine,
162  cosp * v.x * v.z - v.y * sine,
163  0.0f,
164 
165  cosp * v.x * v.y - v.z * sine,
166  cosine + cosp * v.y * v.y,
167  cosp * v.y * v.z + v.x * sine,
168  0.0f,
169 
170  cosp * v.x * v.z + v.y * sine,
171  cosp * v.y * v.z - v.x * sine,
172  cosine + cosp * v.z * v.z,
173  0.0f,
174 
175  0.0f,
176  0.0f,
177  0.0f,
178  1.0f);
179  // clang-format on
180  }
181 
183  const Scalar cosine = cos(r.radians);
184  const Scalar sine = sin(r.radians);
185  // clang-format off
186  return Matrix(
187  1.0f, 0.0f, 0.0f, 0.0f,
188  0.0f, cosine, sine, 0.0f,
189  0.0f, -sine, cosine, 0.0f,
190  0.0f, 0.0f, 0.0f, 1.0f
191  );
192  // clang-format on
193  }
194 
196  const Scalar cosine = cos(r.radians);
197  const Scalar sine = sin(r.radians);
198 
199  // clang-format off
200  return Matrix(
201  cosine, 0.0f, -sine, 0.0f,
202  0.0f, 1.0f, 0.0f, 0.0f,
203  sine, 0.0f, cosine, 0.0f,
204  0.0f, 0.0f, 0.0f, 1.0f
205  );
206  // clang-format on
207  }
208 
210  const Scalar cosine = cos(r.radians);
211  const Scalar sine = sin(r.radians);
212 
213  // clang-format off
214  return Matrix (
215  cosine, sine, 0.0f, 0.0f,
216  -sine, cosine, 0.0f, 0.0f,
217  0.0f, 0.0f, 1.0f, 0.0f,
218  0.0f, 0.0f, 0.0f, 1.0
219  );
220  // clang-format on
221  }
222 
223  /// The Matrix without its `w` components (without translation).
224  constexpr Matrix Basis() const {
225  // clang-format off
226  return Matrix(
227  m[0], m[1], m[2], 0.0f,
228  m[4], m[5], m[6], 0.0f,
229  m[8], m[9], m[10], 0.0f,
230  0.0f, 0.0f, 0.0f, 1.0
231  );
232  // clang-format on
233  }
234 
235  constexpr Matrix Translate(const Vector3& t) const {
236  // clang-format off
237  return Matrix(m[0], m[1], m[2], m[3],
238  m[4], m[5], m[6], m[7],
239  m[8], m[9], m[10], m[11],
240  m[0] * t.x + m[4] * t.y + m[8] * t.z + m[12],
241  m[1] * t.x + m[5] * t.y + m[9] * t.z + m[13],
242  m[2] * t.x + m[6] * t.y + m[10] * t.z + m[14],
243  m[15]);
244  // clang-format on
245  }
246 
247  constexpr Matrix Scale(const Vector3& s) const {
248  // clang-format off
249  return Matrix(m[0] * s.x, m[1] * s.x, m[2] * s.x, m[3] * s.x,
250  m[4] * s.y, m[5] * s.y, m[6] * s.y, m[7] * s.y,
251  m[8] * s.z, m[9] * s.z, m[10] * s.z, m[11] * s.z,
252  m[12] , m[13] , m[14] , m[15] );
253  // clang-format on
254  }
255 
256  constexpr Matrix Multiply(const Matrix& o) const {
257  // clang-format off
258  return Matrix(
259  m[0] * o.m[0] + m[4] * o.m[1] + m[8] * o.m[2] + m[12] * o.m[3],
260  m[1] * o.m[0] + m[5] * o.m[1] + m[9] * o.m[2] + m[13] * o.m[3],
261  m[2] * o.m[0] + m[6] * o.m[1] + m[10] * o.m[2] + m[14] * o.m[3],
262  m[3] * o.m[0] + m[7] * o.m[1] + m[11] * o.m[2] + m[15] * o.m[3],
263  m[0] * o.m[4] + m[4] * o.m[5] + m[8] * o.m[6] + m[12] * o.m[7],
264  m[1] * o.m[4] + m[5] * o.m[5] + m[9] * o.m[6] + m[13] * o.m[7],
265  m[2] * o.m[4] + m[6] * o.m[5] + m[10] * o.m[6] + m[14] * o.m[7],
266  m[3] * o.m[4] + m[7] * o.m[5] + m[11] * o.m[6] + m[15] * o.m[7],
267  m[0] * o.m[8] + m[4] * o.m[9] + m[8] * o.m[10] + m[12] * o.m[11],
268  m[1] * o.m[8] + m[5] * o.m[9] + m[9] * o.m[10] + m[13] * o.m[11],
269  m[2] * o.m[8] + m[6] * o.m[9] + m[10] * o.m[10] + m[14] * o.m[11],
270  m[3] * o.m[8] + m[7] * o.m[9] + m[11] * o.m[10] + m[15] * o.m[11],
271  m[0] * o.m[12] + m[4] * o.m[13] + m[8] * o.m[14] + m[12] * o.m[15],
272  m[1] * o.m[12] + m[5] * o.m[13] + m[9] * o.m[14] + m[13] * o.m[15],
273  m[2] * o.m[12] + m[6] * o.m[13] + m[10] * o.m[14] + m[14] * o.m[15],
274  m[3] * o.m[12] + m[7] * o.m[13] + m[11] * o.m[14] + m[15] * o.m[15]);
275  // clang-format on
276  }
277 
278  constexpr Matrix Transpose() const {
279  // clang-format off
280  return {
281  m[0], m[4], m[8], m[12],
282  m[1], m[5], m[9], m[13],
283  m[2], m[6], m[10], m[14],
284  m[3], m[7], m[11], m[15],
285  };
286  // clang-format on
287  }
288 
289  Matrix Invert() const;
290 
291  Scalar GetDeterminant() const;
292 
293  Scalar GetMaxBasisLength() const;
294 
295  constexpr Scalar GetMaxBasisLengthXY() const {
296  return std::sqrt(std::max(e[0][0] * e[0][0] + e[0][1] * e[0][1],
297  e[1][0] * e[1][0] + e[1][1] * e[1][1]));
298  }
299 
300  constexpr Vector3 GetBasisX() const { return Vector3(m[0], m[1], m[2]); }
301 
302  constexpr Vector3 GetBasisY() const { return Vector3(m[4], m[5], m[6]); }
303 
304  constexpr Vector3 GetBasisZ() const { return Vector3(m[8], m[9], m[10]); }
305 
306  constexpr Vector3 GetScale() const {
307  return Vector3(GetBasisX().Length(), GetBasisY().Length(),
308  GetBasisZ().Length());
309  }
310 
311  constexpr Scalar GetDirectionScale(Vector3 direction) const {
312  return 1.0f / (this->Basis().Invert() * direction.Normalize()).Length() *
313  direction.Length();
314  }
315 
316  constexpr bool IsAffine() const {
317  return (m[2] == 0 && m[3] == 0 && m[6] == 0 && m[7] == 0 && m[8] == 0 &&
318  m[9] == 0 && m[10] == 1 && m[11] == 0 && m[14] == 0 && m[15] == 1);
319  }
320 
321  constexpr bool HasPerspective() const {
322  return m[3] != 0 || m[7] != 0 || m[11] != 0 || m[15] != 1;
323  }
324 
325  constexpr bool IsAligned(Scalar tolerance = 0) const {
326  int v[] = {!ScalarNearlyZero(m[0], tolerance), //
327  !ScalarNearlyZero(m[1], tolerance), //
328  !ScalarNearlyZero(m[2], tolerance), //
329  !ScalarNearlyZero(m[4], tolerance), //
330  !ScalarNearlyZero(m[5], tolerance), //
331  !ScalarNearlyZero(m[6], tolerance), //
332  !ScalarNearlyZero(m[8], tolerance), //
333  !ScalarNearlyZero(m[9], tolerance), //
334  !ScalarNearlyZero(m[10], tolerance)};
335  // Check if all three basis vectors are aligned to an axis.
336  if (v[0] + v[1] + v[2] != 1 || //
337  v[3] + v[4] + v[5] != 1 || //
338  v[6] + v[7] + v[8] != 1) {
339  return false;
340  }
341  // Ensure that none of the basis vectors overlap.
342  if (v[0] + v[3] + v[6] != 1 || //
343  v[1] + v[4] + v[7] != 1 || //
344  v[2] + v[5] + v[8] != 1) {
345  return false;
346  }
347  return true;
348  }
349 
350  constexpr bool IsIdentity() const {
351  return (
352  // clang-format off
353  m[0] == 1.0f && m[1] == 0.0f && m[2] == 0.0f && m[3] == 0.0f &&
354  m[4] == 0.0f && m[5] == 1.0f && m[6] == 0.0f && m[7] == 0.0f &&
355  m[8] == 0.0f && m[9] == 0.0f && m[10] == 1.0f && m[11] == 0.0f &&
356  m[12] == 0.0f && m[13] == 0.0f && m[14] == 0.0f && m[15] == 1.0f
357  // clang-format on
358  );
359  }
360 
361  /// @brief Returns true if the matrix has a scale-only basis and is
362  /// non-projective. Note that an identity matrix meets this criteria.
363  constexpr bool IsTranslationScaleOnly() const {
364  return (
365  // clang-format off
366  m[0] != 0.0 && m[1] == 0.0 && m[2] == 0.0 && m[3] == 0.0 &&
367  m[4] == 0.0 && m[5] != 0.0 && m[6] == 0.0 && m[7] == 0.0 &&
368  m[8] == 0.0 && m[9] == 0.0 && m[10] != 0.0 && m[11] == 0.0 &&
369  m[15] == 1.0
370  // clang-format on
371  );
372  }
373 
374  std::optional<MatrixDecomposition> Decompose() const;
375 
376  constexpr bool operator==(const Matrix& m) const {
377  // clang-format off
378  return vec[0] == m.vec[0]
379  && vec[1] == m.vec[1]
380  && vec[2] == m.vec[2]
381  && vec[3] == m.vec[3];
382  // clang-format on
383  }
384 
385  constexpr bool operator!=(const Matrix& m) const {
386  // clang-format off
387  return vec[0] != m.vec[0]
388  || vec[1] != m.vec[1]
389  || vec[2] != m.vec[2]
390  || vec[3] != m.vec[3];
391  // clang-format on
392  }
393 
394  Matrix operator+(const Vector3& t) const { return Translate(t); }
395 
396  Matrix operator-(const Vector3& t) const { return Translate(-t); }
397 
398  Matrix operator*(const Matrix& m) const { return Multiply(m); }
399 
400  Matrix operator+(const Matrix& m) const;
401 
402  constexpr Vector4 operator*(const Vector4& v) const {
403  return Vector4(v.x * m[0] + v.y * m[4] + v.z * m[8] + v.w * m[12],
404  v.x * m[1] + v.y * m[5] + v.z * m[9] + v.w * m[13],
405  v.x * m[2] + v.y * m[6] + v.z * m[10] + v.w * m[14],
406  v.x * m[3] + v.y * m[7] + v.z * m[11] + v.w * m[15]);
407  }
408 
409  constexpr Vector3 operator*(const Vector3& v) const {
410  Scalar w = v.x * m[3] + v.y * m[7] + v.z * m[11] + m[15];
411  Vector3 result(v.x * m[0] + v.y * m[4] + v.z * m[8] + m[12],
412  v.x * m[1] + v.y * m[5] + v.z * m[9] + m[13],
413  v.x * m[2] + v.y * m[6] + v.z * m[10] + m[14]);
414 
415  // This is Skia's behavior, but it may be reasonable to allow UB for the w=0
416  // case.
417  if (w) {
418  w = 1 / w;
419  }
420  return result * w;
421  }
422 
423  constexpr Point operator*(const Point& v) const {
424  Scalar w = v.x * m[3] + v.y * m[7] + m[15];
425  Point result(v.x * m[0] + v.y * m[4] + m[12],
426  v.x * m[1] + v.y * m[5] + m[13]);
427 
428  // This is Skia's behavior, but it may be reasonable to allow UB for the w=0
429  // case.
430  if (w) {
431  w = 1 / w;
432  }
433  return result * w;
434  }
435 
436  constexpr Vector4 TransformDirection(const Vector4& v) const {
437  return Vector4(v.x * m[0] + v.y * m[4] + v.z * m[8],
438  v.x * m[1] + v.y * m[5] + v.z * m[9],
439  v.x * m[2] + v.y * m[6] + v.z * m[10], v.w);
440  }
441 
442  constexpr Vector3 TransformDirection(const Vector3& v) const {
443  return Vector3(v.x * m[0] + v.y * m[4] + v.z * m[8],
444  v.x * m[1] + v.y * m[5] + v.z * m[9],
445  v.x * m[2] + v.y * m[6] + v.z * m[10]);
446  }
447 
448  constexpr Vector2 TransformDirection(const Vector2& v) const {
449  return Vector2(v.x * m[0] + v.y * m[4], v.x * m[1] + v.y * m[5]);
450  }
451 
452  constexpr Quad Transform(const Quad& quad) const {
453  return {
454  *this * quad[0],
455  *this * quad[1],
456  *this * quad[2],
457  *this * quad[3],
458  };
459  }
460 
461  template <class T>
462  static constexpr Matrix MakeOrthographic(TSize<T> size) {
463  // Per assumptions about NDC documented above.
464  const auto scale =
465  MakeScale({2.0f / static_cast<Scalar>(size.width),
466  -2.0f / static_cast<Scalar>(size.height), 0.0f});
467  const auto translate = MakeTranslation({-1.0f, 1.0f, 0.5f});
468  return translate * scale;
469  }
470 
471  static constexpr Matrix MakePerspective(Radians fov_y,
472  Scalar aspect_ratio,
473  Scalar z_near,
474  Scalar z_far) {
475  Scalar height = std::tan(fov_y.radians * 0.5f);
476  Scalar width = height * aspect_ratio;
477 
478  // clang-format off
479  return {
480  1.0f / width, 0.0f, 0.0f, 0.0f,
481  0.0f, 1.0f / height, 0.0f, 0.0f,
482  0.0f, 0.0f, z_far / (z_far - z_near), 1.0f,
483  0.0f, 0.0f, -(z_far * z_near) / (z_far - z_near), 0.0f,
484  };
485  // clang-format on
486  }
487 
488  template <class T>
489  static constexpr Matrix MakePerspective(Radians fov_y,
490  TSize<T> size,
491  Scalar z_near,
492  Scalar z_far) {
493  return MakePerspective(fov_y, static_cast<Scalar>(size.width) / size.height,
494  z_near, z_far);
495  }
496 
497  static constexpr Matrix MakeLookAt(Vector3 position,
498  Vector3 target,
499  Vector3 up) {
500  Vector3 forward = (target - position).Normalize();
501  Vector3 right = up.Cross(forward);
502  up = forward.Cross(right);
503 
504  // clang-format off
505  return {
506  right.x, up.x, forward.x, 0.0f,
507  right.y, up.y, forward.y, 0.0f,
508  right.z, up.z, forward.z, 0.0f,
509  -right.Dot(position), -up.Dot(position), -forward.Dot(position), 1.0f
510  };
511  // clang-format on
512  }
513 };
514 
515 static_assert(sizeof(struct Matrix) == sizeof(Scalar) * 16,
516  "The matrix must be of consistent size.");
517 
518 } // namespace impeller
519 
520 namespace std {
521 inline std::ostream& operator<<(std::ostream& out, const impeller::Matrix& m) {
522  out << "(" << std::endl << std::fixed;
523  for (size_t i = 0; i < 4u; i++) {
524  for (size_t j = 0; j < 4u; j++) {
525  out << std::setw(15) << m.e[j][i] << ",";
526  }
527  out << std::endl;
528  }
529  out << ")";
530  return out;
531 }
532 
533 } // namespace std
534 
535 #endif // FLUTTER_IMPELLER_GEOMETRY_MATRIX_H_
impeller::Matrix::MakeSkew
static constexpr Matrix MakeSkew(Scalar sx, Scalar sy)
Definition: matrix.h:117
impeller::Matrix::HasPerspective
constexpr bool HasPerspective() const
Definition: matrix.h:321
impeller::Matrix::operator+
Matrix operator+(const Vector3 &t) const
Definition: matrix.h:394
impeller::Matrix::m
Scalar m[16]
Definition: matrix.h:39
impeller::Vector3::Dot
constexpr Scalar Dot(const Vector3 &other) const
Definition: vector.h:54
impeller::Matrix::Decompose
std::optional< MatrixDecomposition > Decompose() const
Definition: matrix.cc:209
impeller::Matrix::MakeRotationX
static Matrix MakeRotationX(Radians r)
Definition: matrix.h:182
impeller::Matrix::Matrix
constexpr Matrix()
Definition: matrix.h:47
impeller::Quaternion::z
Scalar z
Definition: quaternion.h:19
point.h
impeller::TPoint::y
Type y
Definition: point.h:31
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::Vector3::Cross
constexpr Vector3 Cross(const Vector3 &other) const
Definition: vector.h:62
impeller::Matrix::MakePerspective
static constexpr Matrix MakePerspective(Radians fov_y, TSize< T > size, Scalar z_near, Scalar z_far)
Definition: matrix.h:489
impeller::Vector4::Normalize
Vector4 Normalize() const
Definition: vector.h:258
impeller::Quaternion::w
Scalar w
Definition: quaternion.h:20
impeller::Matrix::operator-
Matrix operator-(const Vector3 &t) const
Definition: matrix.h:396
impeller::Matrix::operator*
constexpr Point operator*(const Point &v) const
Definition: matrix.h:423
impeller::Vector4
Definition: vector.h:232
impeller::Matrix::MakeRotation
static Matrix MakeRotation(Quaternion q)
Definition: matrix.h:126
impeller::Vector2
Point Vector2
Definition: point.h:320
impeller::Matrix::MakeRotationY
static Matrix MakeRotationY(Radians r)
Definition: matrix.h:195
impeller::Matrix::GetDeterminant
Scalar GetDeterminant() const
Definition: matrix.cc:162
quaternion.h
std::operator<<
std::ostream & operator<<(std::ostream &out, const impeller::Color &c)
Definition: color.h:951
impeller::Matrix::operator*
Matrix operator*(const Matrix &m) const
Definition: matrix.h:398
impeller::Radians::radians
Scalar radians
Definition: scalar.h:39
impeller::Matrix::MakeRow
static constexpr Matrix MakeRow(Scalar m0, Scalar m1, Scalar m2, Scalar m3, Scalar m4, Scalar m5, Scalar m6, Scalar m7, Scalar m8, Scalar m9, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m14, Scalar m15)
Definition: matrix.h:83
impeller::Matrix::MakeTranslation
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition: matrix.h:95
impeller::Vector3::x
Scalar x
Definition: vector.h:23
impeller::Quaternion::x
Scalar x
Definition: quaternion.h:17
impeller::Matrix::e
Scalar e[4][4]
Definition: matrix.h:40
impeller::Matrix::vec
Vector4 vec[4]
Definition: matrix.h:41
impeller::Matrix::MakeLookAt
static constexpr Matrix MakeLookAt(Vector3 position, Vector3 target, Vector3 up)
Definition: matrix.h:497
impeller::Matrix::MakePerspective
static constexpr Matrix MakePerspective(Radians fov_y, Scalar aspect_ratio, Scalar z_near, Scalar z_far)
Definition: matrix.h:471
impeller::Matrix::Basis
constexpr Matrix Basis() const
The Matrix without its w components (without translation).
Definition: matrix.h:224
impeller::TSize
Definition: size.h:19
impeller::Matrix::TransformDirection
constexpr Vector3 TransformDirection(const Vector3 &v) const
Definition: matrix.h:442
impeller::Quaternion
Definition: quaternion.h:14
impeller::Quad
std::array< Point, 4 > Quad
Definition: point.h:321
impeller::Matrix::Multiply
constexpr Matrix Multiply(const Matrix &o) const
Definition: matrix.h:256
impeller::Matrix::GetScale
constexpr Vector3 GetScale() const
Definition: matrix.h:306
impeller::Matrix::operator==
constexpr bool operator==(const Matrix &m) const
Definition: matrix.h:376
impeller::Matrix::Transpose
constexpr Matrix Transpose() const
Definition: matrix.h:278
impeller::Matrix::GetMaxBasisLength
Scalar GetMaxBasisLength() const
Definition: matrix.cc:196
impeller::Matrix::operator*
constexpr Vector4 operator*(const Vector4 &v) const
Definition: matrix.h:402
impeller::Matrix::IsTranslationScaleOnly
constexpr bool IsTranslationScaleOnly() const
Returns true if the matrix has a scale-only basis and is non-projective. Note that an identity matrix...
Definition: matrix.h:363
impeller::Matrix::Translate
constexpr Matrix Translate(const Vector3 &t) const
Definition: matrix.h:235
impeller::Matrix::Matrix
constexpr Matrix(Scalar m0, Scalar m1, Scalar m2, Scalar m3, Scalar m4, Scalar m5, Scalar m6, Scalar m7, Scalar m8, Scalar m9, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m14, Scalar m15)
Definition: matrix.h:56
impeller::Matrix::MakeColumn
static constexpr Matrix MakeColumn(Scalar m0, Scalar m1, Scalar m2, Scalar m3, Scalar m4, Scalar m5, Scalar m6, Scalar m7, Scalar m8, Scalar m9, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m14, Scalar m15)
Definition: matrix.h:69
impeller::Matrix::TransformDirection
constexpr Vector2 TransformDirection(const Vector2 &v) const
Definition: matrix.h:448
impeller::Vector3::z
Scalar z
Definition: vector.h:25
impeller::Matrix::IsAffine
constexpr bool IsAffine() const
Definition: matrix.h:316
impeller::Radians
Definition: scalar.h:38
impeller::ScalarNearlyZero
constexpr bool ScalarNearlyZero(Scalar x, Scalar tolerance=kEhCloseEnough)
Definition: scalar.h:25
impeller::Vector3::Length
constexpr Scalar Length() const
Definition: vector.h:47
impeller::Vector4::x
Scalar x
Definition: vector.h:235
impeller::Vector3::y
Scalar y
Definition: vector.h:24
impeller::Matrix::GetBasisZ
constexpr Vector3 GetBasisZ() const
Definition: matrix.h:304
impeller::TSize::width
Type width
Definition: size.h:22
impeller::Matrix::Transform
constexpr Quad Transform(const Quad &quad) const
Definition: matrix.h:452
impeller::Matrix::Invert
Matrix Invert() const
Definition: matrix.cc:97
impeller::TPoint::x
Type x
Definition: point.h:30
impeller::Matrix::IsIdentity
constexpr bool IsIdentity() const
Definition: matrix.h:350
impeller::Matrix::GetDirectionScale
constexpr Scalar GetDirectionScale(Vector3 direction) const
Definition: matrix.h:311
scalar.h
impeller::Vector3::Normalize
constexpr Vector3 Normalize() const
Definition: vector.h:49
impeller::Matrix::TransformDirection
constexpr Vector4 TransformDirection(const Vector4 &v) const
Definition: matrix.h:436
impeller::Vector4::w
Scalar w
Definition: vector.h:238
impeller::Matrix::MakeRotationZ
static Matrix MakeRotationZ(Radians r)
Definition: matrix.h:209
vector.h
impeller::Matrix::GetMaxBasisLengthXY
constexpr Scalar GetMaxBasisLengthXY() const
Definition: matrix.h:295
std
Definition: comparable.h:95
impeller::Vector4::y
Scalar y
Definition: vector.h:236
impeller::Matrix::MakeRotation
static Matrix MakeRotation(Scalar radians, const Vector4 &r)
Definition: matrix.h:151
shear.h
impeller::TPoint< Scalar >
impeller::Matrix::operator*
constexpr Vector3 operator*(const Vector3 &v) const
Definition: matrix.h:409
impeller::Matrix::operator!=
constexpr bool operator!=(const Matrix &m) const
Definition: matrix.h:385
impeller::Quaternion::y
Scalar y
Definition: quaternion.h:18
scale
const Scalar scale
Definition: stroke_path_geometry.cc:297
impeller::Matrix::MakeOrthographic
static constexpr Matrix MakeOrthographic(TSize< T > size)
Definition: matrix.h:462
matrix_decomposition.h
impeller::TSize::height
Type height
Definition: size.h:23
impeller::Matrix::GetBasisY
constexpr Vector3 GetBasisY() const
Definition: matrix.h:302
impeller::Vector4::z
Scalar z
Definition: vector.h:237
impeller
Definition: aiks_blur_unittests.cc:20
impeller::Matrix::MakeScale
static constexpr Matrix MakeScale(const Vector3 &s)
Definition: matrix.h:104
impeller::Matrix::MakeScale
static constexpr Matrix MakeScale(const Vector2 &s)
Definition: matrix.h:113
impeller::Matrix::GetBasisX
constexpr Vector3 GetBasisX() const
Definition: matrix.h:300
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::Vector3
Definition: vector.h:20
size.h
impeller::Matrix::Scale
constexpr Matrix Scale(const Vector3 &s) const
Definition: matrix.h:247
impeller::Matrix::IsAligned
constexpr bool IsAligned(Scalar tolerance=0) const
Definition: matrix.h:325