-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransform.hpp
42 lines (31 loc) · 1.29 KB
/
transform.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
class Transform {
public:
Transform(const glm::vec3& pos = glm::vec3(),
const glm::vec3& rot = glm::vec3(),
const glm::vec3 scale = glm::vec3(1.0f, 1.0f, 1.0f))
: m_pos(pos), m_rot(rot), m_scale(scale)
{
}
inline glm::mat4 GetModel() const {
glm::mat4 posMatrix = glm::translate(m_pos);
glm::mat4 scaleMatrix = glm::scale(m_scale);
glm::mat4 rotXMatrix = glm::rotate(m_rot.x, glm::vec3(1,0,0));
glm::mat4 rotYMatrix = glm::rotate(m_rot.y, glm::vec3(0,1,0));
glm::mat4 rotZMatrix = glm::rotate(m_rot.z, glm::vec3(0,0,1));
glm::mat4 rotMatrix = rotZMatrix * rotYMatrix * rotXMatrix;
return posMatrix * rotMatrix * scaleMatrix;
}
inline glm::vec3& GetRot() { return m_rot; }
inline glm::vec3& GetPos() { return m_pos; }
inline glm::vec3& GetScale() { return m_scale; }
inline void SetPos(const glm::vec3& pos) { m_pos = pos; }
inline void SetRot(const glm::vec3& rot) { m_rot = rot; }
inline void SetScale(const glm::vec3& scale) { m_scale = scale; }
private:
glm::vec3 m_pos;
glm::vec3 m_rot;
glm::vec3 m_scale;
};