VOX
A little voxel engine
Loading...
Searching...
No Matches
Transform.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "define.hpp"
4
5#include <glm/glm.hpp>
6#include <glm/gtc/matrix_transform.hpp>
7
8#include <cstdint>
9
11{
12
13public:
14
16 const glm::vec3 & position = glm::vec3(0.0f, 0.0f, 0.0f),
17 const glm::vec3 & rotation = glm::vec3(0.0f, 0.0f, 0.0f),
18 const glm::vec3 & scale = glm::vec3(1.0f, 1.0f, 1.0f),
19 const Transform * parent = nullptr
20 ):
23 scale(scale),
25 {
26 }
27
28 glm::dmat4 model() const
29 {
30 glm::dmat4 model = glm::dmat4(1.0f);
31 model = glm::translate(model, position);
32 model = glm::rotate(model, rotation.x, glm::dvec3(1.0f, 0.0f, 0.0f));
33 model = glm::rotate(model, rotation.y, glm::dvec3(0.0f, 1.0f, 0.0f));
34 model = glm::rotate(model, rotation.z, glm::dvec3(0.0f, 0.0f, 1.0f));
35 model = glm::scale(model, scale);
36
37 if (parent)
38 {
39 model = parent->model() * model;
40 }
41
42 return model;
43 }
44
45 glm::dvec3 position;
46 glm::dvec3 rotation;
47 glm::dvec3 scale;
48
50
51};
52
53class Mat4
54{
55
56public:
57
58 Mat4(const glm::dmat4 & mat = glm::dmat4(1.0)):
59 m_mat(mat)
60 {
61 }
62
63 glm::dmat4 dmat() const
64 {
65 return m_mat;
66 }
67
68 glm::mat4 mat() const
69 {
70 return glm::mat4(m_mat);
71 }
72
73 Mat4 & translate(const glm::dvec3 & vec)
74 {
75 m_mat = glm::translate(m_mat, vec);
76 return *this;
77 }
78
79 Mat4 & rotate(double angle, const glm::dvec3 & axis)
80 {
81 m_mat = glm::rotate(m_mat, angle, axis);
82 return *this;
83 }
84
85 Mat4 & scale(const glm::dvec3 & vec)
86 {
87 m_mat = glm::scale(m_mat, vec);
88 return *this;
89 }
90
91private:
92
93 glm::dmat4 m_mat;
94};
Definition: Transform.hpp:54
glm::mat4 mat() const
Definition: Transform.hpp:68
Mat4 & rotate(double angle, const glm::dvec3 &axis)
Definition: Transform.hpp:79
Mat4 & scale(const glm::dvec3 &vec)
Definition: Transform.hpp:85
Mat4(const glm::dmat4 &mat=glm::dmat4(1.0))
Definition: Transform.hpp:58
glm::dmat4 dmat() const
Definition: Transform.hpp:63
Mat4 & translate(const glm::dvec3 &vec)
Definition: Transform.hpp:73
Definition: Transform.hpp:11
glm::dvec3 scale
Definition: Transform.hpp:47
const Transform * parent
Definition: Transform.hpp:49
glm::dvec3 rotation
Definition: Transform.hpp:46
glm::dvec3 position
Definition: Transform.hpp:45
Transform(const glm::vec3 &position=glm::vec3(0.0f, 0.0f, 0.0f), const glm::vec3 &rotation=glm::vec3(0.0f, 0.0f, 0.0f), const glm::vec3 &scale=glm::vec3(1.0f, 1.0f, 1.0f), const Transform *parent=nullptr)
Definition: Transform.hpp:15
glm::dmat4 model() const
Definition: Transform.hpp:28