-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransform.hpp
110 lines (93 loc) · 2.63 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef TRANSFORM_HPP
#define TRANSFORM_HPP
#include <glbinding/gl/gl.h>
#include <glbinding/Binding.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include <iostream>
#include <vector>
/*
Axis x -> from left(-) to right(+)
Axis y -> from bottom(-) to top(+)
Axis z -> from to user(-) to screen(+)
*/
enum Space{
LOCAL = 1,
GLOBAL = 2
};
class Transform
{
public:
Transform();
~Transform();
/*get transform in local space*/
glm::mat4 getLocalTransformMatrix();
/*get transform in global space (scene)*/
glm::mat4 getGlobalTransformMatrix();
void setParent(Transform* t);
void setPosition(float x, float y, float z=0.f);
void setPosition(glm::vec3);
void setRotation(float x, float y, float z);
void setRotation(glm::vec3);
void setScale(float dx, float dy, float dz=1.0f);
void setScale(glm::vec3);
/* -###- move by d -###- */
void translate(float dx, float dy, float dz=0.f);
void translate(glm::vec3);
void rotate(float dx, float dy, float dz=0.f);
void rotate(glm::vec3);
void scaleUp(float dx, float dy, float dz=0.f);
void scaleUp(glm::vec3);
void rotateX(float dx);
void rotateY(float dy);
void rotateZ(float dz);
void moveX(float dx);
void moveY(float dy);
void moveZ(float dz);
void scaleUpX(float dx);
void scaleUpY(float dy);
void scaleUpZ(float dz);
/* -###- getters -###- */
float getX();
float getY();
float getZ();
float getScaleX();
float getScaleY();
float getScaleZ();
float getRotX();
float getRotY();
float getRotZ();
/* -###- setters -###- */
void setX(float x);
void setY(float y);
void setZ(float z);
void setScaleX(float x);
void setScaleY(float y);
void setScaleZ(float z);
void setRotX(float x);
void setRotY(float y);
void setRotZ(float z);
glm::vec3 getPosition();
glm::vec3 getRotation();
glm::vec3 getScale();
glm::vec3 getFront(); //z
glm::vec3 getRight(); //x
glm::vec3 getUp(); //y
Transform* getParent();
void print();
protected:
glm::mat4 mxTransform;
bool needUpdate=false;
float posX, posY, posZ;
float scaleX, scaleY, scaleZ;
float rotX, rotY, rotZ;
Transform* parent;
float keyX, keyY, keyZ;
glm::quat quatStorage;
std::vector<Transform* > vecChildren;
};
#endif // TRANSFORM_HPP