-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransform3D.cpp
More file actions
103 lines (83 loc) · 1.67 KB
/
Transform3D.cpp
File metadata and controls
103 lines (83 loc) · 1.67 KB
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
#include "Transform3D.h"
QQuaternion Transform3D::GetRotation()
{
return m_Rotation;
}
void Transform3D::SetRotation(QQuaternion rotation)
{
m_Changed = true;
m_Rotation = rotation;
}
QVector3D Transform3D::GetScale()
{
return m_Scale;
}
void Transform3D::SetScale(QVector3D scale)
{
m_Changed = true;
m_Scale = scale;
}
QVector3D Transform3D::GetTranslation()
{
return m_Translation;
}
void Transform3D::SetTranslation(QVector3D translation)
{
m_Changed = true;
m_Translation = translation;
}
Transform3D::Transform3D()
{
}
const QVector3D Transform3D::FORWARD(0,0,1);
QVector3D Transform3D::Forward()
{
return m_Rotation.rotatedVector(FORWARD);
}
void Transform3D::ResetRotation()
{
QQuaternion zero(1,0,0,0);
SetRotation(zero);
}
void Transform3D::ResetTranslation()
{
QVector3D zero(0,0,0);
SetTranslation(zero);
}
const QVector3D Transform3D::RIGHT(1,0,0);
QVector3D Transform3D::Right()
{
return m_Rotation.rotatedVector(RIGHT);
}
void Transform3D::Rotate(QQuaternion rotation)
{
m_Changed = true;
SetRotation(rotation * m_Rotation);
}
void Transform3D::Scale(QVector3D scale)
{
m_Changed = true;
SetScale(m_Scale * scale);
}
QMatrix4x4 Transform3D::ToMatrix()
{
if (m_Changed)
{
m_Changed = false;
m_World.setToIdentity();
m_World.translate(m_Translation);
m_World.rotate(m_Rotation);
m_World.scale(m_Scale);
}
return m_World;
}
void Transform3D::Translate(QVector3D translate)
{
m_Changed = true;
SetTranslation(m_Translation + translate);
}
const QVector3D Transform3D::UP(0,1,0);
QVector3D Transform3D::Up()
{
return m_Rotation.rotatedVector(UP);
}