JNGL
Mat3.hpp
Go to the documentation of this file.
1 // Copyright 2021-2022 Jan Niklas Hasse <[email protected]>
2 // For conditions of distribution and use, see copyright notice in LICENSE.txt
5 #pragma once
6 
7 #if !defined(__has_include) || __has_include("boost/version.hpp")
8 #include <boost/version.hpp>
9 #endif
10 #include <initializer_list>
11 
12 namespace jngl {
13 
14 class Pixels;
15 class Vec2;
16 
20 class Mat3 {
21 public:
23  Mat3() = default;
24 
27 
31  Mat3& translate(const Vec2& v);
32 
37 
42  Mat3& scale(float factor);
43 
52  Mat3& scale(float xfactor, float yfactor);
53 
57  Mat3& rotate(float radian);
58 
60  float data[9] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
61 };
62 
63 } // namespace jngl
64 
65 #if BOOST_VERSION >= 106200 || __has_include("boost/qvm/mat_traits.hpp")
66 #include <boost/qvm/mat_traits.hpp>
67 
68 namespace boost::qvm {
69 template <> struct mat_traits<jngl::Mat3> {
70  static int const rows = 3;
71  static int const cols = 3;
72  using scalar_type = float;
73 
74  template <int R, int C> static scalar_type read_element(const jngl::Mat3& m) {
75  return m.data[C * 3 + R];
76  }
77  template <int R, int C> static scalar_type& write_element(jngl::Mat3& m) {
78  return m.data[C * 3 + R];
79  }
80 };
81 } // namespace boost::qvm
82 #endif
3x3 matrix
Definition: Mat3.hpp:20
Mat3(std::initializer_list< float >)
construct matrix from row-major array with 9 elements
Mat3 & translate(Pixels x, Pixels y)
Multiplies the matrix with a translation matrix generated from (x,y)
Mat3()=default
creates identity matrix
Mat3 & scale(float xfactor, float yfactor)
Multiplies the matrix by a scaling matrix.
Mat3 & translate(const Vec2 &v)
Multiplies the matrix with a translation matrix generated from v.
Mat3 & rotate(float radian)
Multiplies the matrix with a rotation matrix.
float data[9]
column-major
Definition: Mat3.hpp:60
Mat3 & scale(float factor)
Multiplies the matrix by a scaling matrix.
Scale-dependent pixels, corresponds to actual pixels on the screen.
Definition: Pixels.hpp:14
Two-dimensional vector.
Definition: Vec2.hpp:35
JNGL's main namespace.
Definition: App.hpp:10