lxgui
Loading...
Searching...
No Matches
gui_matrix4.hpp
1#ifndef LXGUI_GUI_MATRIX4_HPP
2#define LXGUI_GUI_MATRIX4_HPP
3
4#include "lxgui/gui_vector2.hpp"
5#include "lxgui/lxgui.hpp"
6
7#include <initializer_list>
8#include <iosfwd>
9
10namespace lxgui::gui {
11
13struct matrix4f {
14 using element_type = float;
15
16 matrix4f() noexcept = default;
17 matrix4f(std::initializer_list<element_type> list) noexcept;
18 explicit matrix4f(const element_type* mat) noexcept;
19
20 element_type& operator()(std::size_t row, std::size_t col) noexcept {
21 return data[col + row * 4];
22 }
23
24 element_type operator()(std::size_t row, std::size_t col) const noexcept {
25 return data[col + row * 4];
26 }
27
28 element_type& operator()(std::size_t i) noexcept {
29 return data[i];
30 }
31
32 element_type operator()(std::size_t i) const noexcept {
33 return data[i];
34 }
35
36 void transpose() noexcept;
37 void invert() noexcept;
38
39 static matrix4f translation(const vector2f& dx) noexcept;
40 static matrix4f scaling(const vector2f& scale) noexcept;
41 static matrix4f rotation(float rot) noexcept;
42 static matrix4f transformation(const vector2f& dx, const vector2f& scale, float rot) noexcept;
43 static matrix4f view(const vector2f& window) noexcept;
44 static matrix4f view(const vector2f& window, const vector2f& center) noexcept;
45
46 static matrix4f transpose(const matrix4f& m) noexcept;
47 static matrix4f invert(const matrix4f& m) noexcept;
48
49 element_type data[16] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
50
51 static const matrix4f identity;
52};
53
54matrix4f operator+(const matrix4f& m1, const matrix4f& m2) noexcept;
55matrix4f operator-(const matrix4f& m1, const matrix4f& m2) noexcept;
56matrix4f operator*(const matrix4f& m1, const matrix4f& m2) noexcept;
57vector2f operator*(const matrix4f& m, const vector2f& v) noexcept;
58vector2f operator*(const vector2f& v, const matrix4f& m) noexcept;
59
60std::ostream& operator<<(std::ostream& o, const matrix4f& m);
61
62} // namespace lxgui::gui
63
64#endif
std::ostream & operator<<(std::ostream &stream, const color &c)
color operator+(const color &c1, const color &c2) noexcept
color operator*(const color &c1, const color &c2) noexcept
color operator-(const color &c1, const color &c2) noexcept
STL namespace.
A 4x4 matrix, used for coordinate transformations.
static matrix4f scaling(const vector2f &scale) noexcept
void invert() noexcept
static const matrix4f identity
element_type data[16]
element_type operator()(std::size_t i) const noexcept
element_type & operator()(std::size_t i) noexcept
void transpose() noexcept
matrix4f() noexcept=default
static matrix4f translation(const vector2f &dx) noexcept
static matrix4f transformation(const vector2f &dx, const vector2f &scale, float rot) noexcept
static matrix4f view(const vector2f &window) noexcept
element_type operator()(std::size_t row, std::size_t col) const noexcept
static matrix4f rotation(float rot) noexcept