YourGameLib
Loading...
Searching...
No Matches
trafo.h
Go to the documentation of this file.
1/*
2Copyright (c) 2019-2024 Alexander Scholz
3
4This software is provided 'as-is', without any express or implied
5warranty. In no event will the authors be held liable for any damages
6arising from the use of this software.
7
8Permission is granted to anyone to use this software for any purpose,
9including commercial applications, and to alter it and redistribute it
10freely, subject to the following restrictions:
11
121. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
162. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
183. This notice may not be removed or altered from any source distribution.
19*/
20#ifndef YOURGAME_TRAFO_H
21#define YOURGAME_TRAFO_H
22
23#define GLM_ENABLE_EXPERIMENTAL
24#include <glm/glm.hpp>
25#include <glm/ext.hpp>
26#include "yourgame/math.h"
27
28namespace yourgame
29{
30 namespace math
31 {
32 class Trafo
33 {
34 public:
35 glm::mat4 mat();
36 void rotateLocal(float angle, math::Axis ax);
37 void rotateLocal(float angle, glm::vec3 const &ax);
38 void rotateGlobal(float angle, math::Axis ax);
39 void rotateGlobal(float angle, glm::vec3 const &ax);
40 void translateLocal(float distance, math::Axis ax);
41 void translateLocal(glm::vec3 const &trans);
42 void translateGlobal(float distance, math::Axis ax);
43 void translateGlobal(glm::vec3 const &trans);
44 void setScaleLocal(glm::vec3 const &scale);
45 void setScaleLocal(float scale);
46 void setRotation(glm::quat const &rot);
47 void setTranslation(glm::vec3 const &trans);
48 void resetScale();
49 void resetRotation();
50 void resetTranslation();
51 void pointTo(glm::vec3 const &eye, glm::vec3 const &center, glm::vec3 const &up);
52 void lookAt(glm::vec3 const &eye, glm::vec3 const &center, glm::vec3 const &up);
53 void lerp(float t, Trafo const &target, Trafo *dst);
54 void setIdentity();
55 glm::vec3 getAxisLocal(math::Axis ax);
56 glm::vec3 getAxisGlobal(math::Axis ax) const;
57 glm::vec3 getEye() const;
58 glm::quat getRotation() const;
59 glm::vec3 getScale() const;
60
61 private:
62 glm::vec3 m_eye = glm::vec3(0.0f, 0.0f, 0.0f);
63 glm::quat m_rot = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
64 glm::vec3 m_scale = glm::vec3(1.0f, 1.0f, 1.0f);
65
66 // Matrixes generated from the above vectors via updateMatrixIfInvalidated()
67 glm::mat4 m_mat = glm::mat4(1.0f); // identity
68 glm::mat4 m_matRot = glm::mat4(1.0f); // identity
69
70 bool m_matInvalidated = false;
71 void updateMatrixIfInvalidated();
72 };
73 } // namespace math
74} // namespace yourgame
75
76#endif
Definition trafo.h:33
glm::vec3 getAxisGlobal(math::Axis ax) const
Definition trafo.cpp:188
void setRotation(glm::quat const &rot)
Definition trafo.cpp:96
glm::quat getRotation() const
Definition trafo.cpp:210
void setTranslation(glm::vec3 const &trans)
Definition trafo.cpp:102
void resetScale()
Definition trafo.cpp:108
glm::mat4 mat()
Definition trafo.cpp:26
glm::vec3 getAxisLocal(math::Axis ax)
Definition trafo.cpp:170
void rotateLocal(float angle, math::Axis ax)
Definition trafo.cpp:32
void translateLocal(float distance, math::Axis ax)
Definition trafo.cpp:58
void setIdentity()
Definition trafo.cpp:162
void pointTo(glm::vec3 const &eye, glm::vec3 const &center, glm::vec3 const &up)
Definition trafo.cpp:123
void setScaleLocal(glm::vec3 const &scale)
Definition trafo.cpp:84
void lerp(float t, Trafo const &target, Trafo *dst)
Definition trafo.cpp:140
glm::vec3 getScale() const
Definition trafo.cpp:215
void rotateGlobal(float angle, math::Axis ax)
Definition trafo.cpp:45
void translateGlobal(float distance, math::Axis ax)
Definition trafo.cpp:72
void resetRotation()
Definition trafo.cpp:113
void lookAt(glm::vec3 const &eye, glm::vec3 const &center, glm::vec3 const &up)
Definition trafo.cpp:132
void resetTranslation()
Definition trafo.cpp:118
glm::vec3 getEye() const
Definition trafo.cpp:205
Axis
Definition math.h:34
Definition audio.h:27