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
68 Mat3& rotate(float radian);
69
71 float data[9] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
72};
73
74} // namespace jngl
75
76namespace boost::qvm {
77template <> struct mat_traits<jngl::Mat3> {
78 static int const rows = 3;
79 static int const cols = 3;
80 using scalar_type = float;
81
82 template <int R, int C> static scalar_type read_element(const jngl::Mat3& m) {
83 return m.data[C * 3 + R];
84 }
85 template <int R, int C> static scalar_type& write_element(jngl::Mat3& m) {
86 return m.data[C * 3 + R];
87 }
88};
89} // 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:71
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.