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