Euphoria
mat3.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "base/vec2.h"
4 #include "base/vec3.h"
5 #include "base/mat2.h"
6 #include "base/angle.h"
7 #include "base/axisangle.h"
8 
9 namespace eu
10 {
11  struct mat3f
12  {
13  explicit mat3f(const mat2f& mat);
14 
15  bool operator==(const mat3f& rhs) = delete;
16 
17  [[nodiscard]] static mat3f from_major(const Scale3f& major);
18  [[nodiscard]] static mat3f from_scale(const Scale3f& scale);
19  [[nodiscard]] static mat3f from_translation2d(const vec2f& t);
20  [[nodiscard]] static mat3f from_rot_x(const Angle& a);
21  [[nodiscard]] static mat3f from_rot_y(const Angle& a);
22  [[nodiscard]] static mat3f from_rot_z(const Angle& a);
23  [[nodiscard]] static mat3f from_axis_angle(const AxisAngle& aa);
24  [[nodiscard]] constexpr static mat3f from_scalar(float scalar)
25  {
26  const float z = 0;
27  return from_row_major
28  (
29  scalar, z, z,
30  z, scalar, z,
31  z, z, scalar
32  );
33  }
34 
35  [[nodiscard]] static mat3f from_col_major
36  (
37  float t00, float t01, float t02,
38  float t10, float t11, float t12,
39  float t20, float t21, float t22
40  );
41 
42  [[nodiscard]] constexpr static mat3f from_row_major
43  (
44  float t00, float t10, float t20,
45  float t01, float t11, float t21,
46  float t02, float t12, float t22
47  )
48  {
49  return
50  {
51  t00, t01, t02,
52  t10, t11, t12,
53  t20, t21, t22
54  };
55  }
56 
57  float* get_data_ptr();
58 
59  [[nodiscard]] float get(int row, int col) const;
60  [[nodiscard]] vec3f get_axis(int col) const;
61  [[nodiscard]] mat3f get_rotated(const AxisAngle& aa) const;
62  [[nodiscard]] mat3f get_scaled(const Scale3f& scale) const;
63  [[nodiscard]] vec3f get_column(int c) const;
64  [[nodiscard]] vec3f get_row(int r) const;
65 
66  [[nodiscard]] vec3f get_major() const;
67  [[nodiscard]] vec3f get_x_axis() const;
68  [[nodiscard]] vec3f get_y_axis() const;
69  [[nodiscard]] vec3f get_z_axis() const;
70  [[nodiscard]] mat3f get_transposed() const;
71  [[nodiscard]] const float* get_data_ptr() const;
72 
73  void operator+=(const mat3f& rhs);
74  void operator-=(const mat3f& rhs);
75 
76  private:
77  float data[9]; // col-major
78 
79  mat3f() = default;
80 
81  constexpr mat3f
82  (
83  float t00, float t01, float t02,
84  float t10, float t11, float t12,
85  float t20, float t21, float t22
86  )
87  : data
88  {
89  t00, t01, t02,
90  t10, t11, t12,
91  t20, t21, t22
92  }
93  {
94  }
95  };
96 
98 
99  std::string to_string(const mat3f& m);
100  mat3f operator+(const mat3f& lhs, const mat3f& rhs);
101  mat3f operator-(const mat3f& lhs, const mat3f& rhs);
102  mat3f operator*(const mat3f& lhs, const mat3f& rhs);
103  vec3f operator*(const mat3f& lhs, const vec3f& rhs);
104 }
105 
ADD_DEFAULT_FORMATTER(eu::mat3f, std::string, eu::to_string)
Definition: assert.h:90
Angle operator+(const Angle &lhs, const Angle &rhs)
Definition: angle.cc:123
Angle operator-(const Angle &lhs, const Angle &rhs)
Definition: angle.cc:132
std::string to_string(const Aabb &a)
Definition: aabb.cc:110
Angle operator*(const Angle &lhs, float rhs)
Definition: angle.cc:149
constexpr mat3f m3_identity
Definition: mat3.h:97
Definition: mat2.h:10
Definition: mat3.h:12
static mat3f from_rot_z(const Angle &a)
Definition: mat3.cc:103
mat3f get_rotated(const AxisAngle &aa) const
Definition: mat3.cc:209
float get(int row, int col) const
Definition: mat3.cc:237
static mat3f from_axis_angle(const AxisAngle &aa)
Definition: mat3.cc:113
vec3f get_major() const
Definition: mat3.cc:140
vec3f get_axis(int col) const
Definition: mat3.cc:147
void operator-=(const mat3f &rhs)
Definition: mat3.cc:198
static mat3f from_col_major(float t00, float t01, float t02, float t10, float t11, float t12, float t20, float t21, float t22)
Definition: mat3.cc:21
vec3f get_y_axis() const
Definition: mat3.cc:161
static mat3f from_rot_x(const Angle &a)
Definition: mat3.cc:73
static mat3f from_translation2d(const vec2f &t)
Definition: mat3.cc:60
constexpr static mat3f from_row_major(float t00, float t10, float t20, float t01, float t11, float t21, float t02, float t12, float t22)
Definition: mat3.h:43
constexpr static mat3f from_scalar(float scalar)
Definition: mat3.h:24
static mat3f from_major(const Scale3f &major)
Definition: mat3.cc:38
static mat3f from_scale(const Scale3f &scale)
Definition: mat3.cc:52
vec3f get_row(int r) const
Definition: mat3.cc:251
vec3f get_column(int c) const
Definition: mat3.cc:244
mat3f get_transposed() const
Definition: mat3.cc:175
float * get_data_ptr()
Definition: mat3.cc:230
static mat3f from_rot_y(const Angle &a)
Definition: mat3.cc:88
void operator+=(const mat3f &rhs)
Definition: mat3.cc:187
mat3f get_scaled(const Scale3f &scale) const
Definition: mat3.cc:216
vec3f get_z_axis() const
Definition: mat3.cc:168
bool operator==(const mat3f &rhs)=delete
vec3f get_x_axis() const
Definition: mat3.cc:154
Definition: vec2.h:33
Definition: vec3.h:48