JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Mat3.hpp
Go to the documentation of this file.
1// Copyright 2021-2023 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include <boost/qvm_lite.hpp>
8#include <initializer_list>
9
10namespace jngl {
11
12class Pixels;
13class Vec2;
14
18class Mat3 {
19public:
27 Mat3() = default;
28
38
42 Mat3& translate(const Vec2& v);
43
48
53 Mat3& scale(float factor);
54
63 Mat3& scale(float xfactor, float yfactor);
64
69 Mat3& scale(const Vec2& v);
70
74 Mat3& rotate(float radian);
75
77 float data[9] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
78};
79
80} // namespace jngl
81
82namespace boost::qvm {
83template <> struct mat_traits<jngl::Mat3> {
84 static int const rows = 3;
85 static int const cols = 3;
86 using scalar_type = float;
87
88 template <int R, int C> static scalar_type read_element(const jngl::Mat3& m) {
89 return m.data[C * 3 + R];
90 }
91 template <int R, int C> static scalar_type& write_element(jngl::Mat3& m) {
92 return m.data[C * 3 + R];
93 }
94};
95} // namespace boost::qvm
3x3 matrix
Definition Mat3.hpp:18
Mat3(std::initializer_list< float >)
construct matrix from row-major array with 9 elements
Mat3()=default
creates identity matrix
Mat3 & translate(const Vec2 &v)
Multiplies the matrix with a translation matrix generated from v.
Mat3 & scale(const Vec2 &v)
Multiplies the matrix by a scaling matrix.
Mat3 & scale(float factor)
Multiplies the matrix by a scaling matrix.
Mat3 & rotate(float radian)
Multiplies the matrix with a rotation matrix.
float data[9]
column-major
Definition Mat3.hpp:77
Mat3 & scale(float xfactor, float yfactor)
Multiplies the matrix by a scaling matrix.
Mat3 & translate(Pixels x, Pixels y)
Multiplies the matrix with a translation matrix generated from (x,y)
Scale-dependent pixels, corresponds to actual pixels on the screen.
Definition Pixels.hpp:14
Two-dimensional vector.
Definition Vec2.hpp:36
JNGL's main namespace.