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:
21 Mat3() = default;
22
25
29 Mat3& translate(const Vec2& v);
30
35
40 Mat3& scale(float factor);
41
50 Mat3& scale(float xfactor, float yfactor);
51
55 Mat3& rotate(float radian);
56
58 float data[9] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
59};
60
61} // namespace jngl
62
63namespace boost::qvm {
64template <> struct mat_traits<jngl::Mat3> {
65 static int const rows = 3;
66 static int const cols = 3;
67 using scalar_type = float;
68
69 template <int R, int C> static scalar_type read_element(const jngl::Mat3& m) {
70 return m.data[C * 3 + R];
71 }
72 template <int R, int C> static scalar_type& write_element(jngl::Mat3& m) {
73 return m.data[C * 3 + R];
74 }
75};
76} // 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(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:58
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:32
JNGL's main namespace.
Definition: Achievement.hpp:10