Repository navigation
Expand file tree
/
Copy pathtransformutils.cpp
More file actions
72 lines (63 loc) · 1.63 KB
/
Copy pathtransformutils.cpp
File metadata and controls
72 lines (63 loc) · 1.63 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
#include "transformutils.h"
TransformUtil::TransformUtil()
{
init();
}
void TransformUtil::init()
{
M.setToIdentity();
Mback.setToIdentity();
}
void TransformUtil::identity()
{
M.setToIdentity();
BackTransformReady = false;
}
void TransformUtil::translate(float x, float y, float z)
{
QMatrix4x4 temp = QMatrix4x4(1, 0, 0, x,
0, 1, 0, y,
0, 0, 1, z,
0, 0, 0, 1);
M = temp * M;
BackTransformReady = false;
}
void TransformUtil::resize(float x, float y, float z)
{
QMatrix4x4 temp = QMatrix4x4(x, 0, 0, 0,
0, y, 0, 0,
0, 0, z, 0,
0, 0, 0, 1);
M = temp * M;
BackTransformReady = false;
}
void TransformUtil::rotate(float x, float y, float z)
{
float sincourse = sin(-x);
float coscourse = cos(-x);
float sindifferent = sin(-y);
float cosdifferent = cos(-y);
float sinroll = sin(-z);
float cosroll = cos(-z);
float SBCA = sindifferent * coscourse;
float SBSA = sindifferent * sincourse;
QMatrix4x4 temp = QMatrix4x4(cosdifferent * coscourse, sindifferent, cosdifferent * sincourse, 0,
-SBCA * cosroll + sincourse * sinroll, cosdifferent * cosroll, -SBSA * cosroll - sinroll * coscourse, 0,
-SBCA * sinroll - sincourse * cosroll, cosdifferent * sinroll, -SBSA * sinroll + coscourse * cosroll, 0,
0, 0, 0, 1);
M = temp * M;
BackTransformReady = false;
}
QVector3D TransformUtil::get(const QVector3D& v)
{
return M * v;
}
QVector3D TransformUtil::getBack(const QVector3D& v)
{
if (!BackTransformReady)
{
Mback = M.inverted();
BackTransformReady = true;
}
return Mback * v;
}