JNGL
Mat3.hpp
Go to the documentation of this file.
1 // Copyright 2021 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 Vec2;
15 
19 class Mat3 {
20 public:
22  Mat3() = default;
23 
26 
30  Mat3& translate(const Vec2& v);
31 
36  Mat3& scale(float factor);
37 
46  Mat3& scale(float xfactor, float yfactor);
47 
51  Mat3& rotate(float radian);
52 
54  float data[9] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
55 };
56 
57 } // namespace jngl
58 
59 #if BOOST_VERSION >= 106200 || __has_include("boost/qvm/mat_traits.hpp")
60 #include <boost/qvm/mat_traits.hpp>
61 
62 namespace boost::qvm {
63 template <> struct mat_traits<jngl::Mat3> {
64  static int const rows = 3;
65  static int const cols = 3;
66  using scalar_type = float;
67 
68  template <int R, int C> static scalar_type read_element(const jngl::Mat3& m) {
69  return m.data[C * 3 + R];
70  }
71  template <int R, int C> static scalar_type& write_element(jngl::Mat3& m) {
72  return m.data[C * 3 + R];
73  }
74 };
75 } // namespace boost::qvm
76 #endif
3x3 matrix
Definition: Mat3.hpp:19
Mat3(std::initializer_list< float >)
construct matrix from row-major array with 9 elements
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:54
Mat3 & scale(float factor)
Multiplies the matrix by a scaling matrix.
Two-dimensional vector.
Definition: Vec2.hpp:35
JNGL's main namespace.
Definition: App.hpp:10