-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroup3d.cpp
More file actions
68 lines (56 loc) · 1.52 KB
/
group3d.cpp
File metadata and controls
68 lines (56 loc) · 1.52 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
#include "group3d.h"
Group3D::Group3D() :
m_scale(1.0f)
{
}
void Group3D::draw(QOpenGLShaderProgram *shaderProgram, QOpenGLFunctions *functions)
{
for (auto it = m_objects.cbegin(); it != m_objects.cend(); ++it) {
(*it)->draw(shaderProgram, functions);
}
}
QVector3D Group3D::getPosition() const
{
return QVector3D(0, 0, 0);
}
void Group3D::addObject(Transformational *obj)
{
m_objects.append(obj);
m_formAndSetGlobalTransformForObjects(m_objects.size() - 1);
}
void Group3D::m_formAndSetGlobalTransformForObjects(int pos)
{
QMatrix4x4 localMatrix;
localMatrix.setToIdentity();
localMatrix.translate(m_translate);
localMatrix.rotate(m_rotate);
localMatrix.scale(m_scale);
localMatrix = m_globalTransform * localMatrix;
if (pos != -1) {
m_objects[pos]->setGlobalTransform(localMatrix);
return;
}
for (auto it = m_objects.cbegin(); it != m_objects.cend(); ++it) {
(*it)->setGlobalTransform(localMatrix);
}
}
void Group3D::rotate(const QQuaternion &rotation)
{
m_rotate = rotation * m_rotate;
m_formAndSetGlobalTransformForObjects();
}
void Group3D::translate(const QVector3D &translation)
{
m_translate += translation;
m_formAndSetGlobalTransformForObjects();
}
void Group3D::scale(const float scaleKoef)
{
m_scale *= scaleKoef;
m_formAndSetGlobalTransformForObjects();
}
void Group3D::setGlobalTransform(const QMatrix4x4 &transformMatrix)
{
m_globalTransform = transformMatrix;
m_formAndSetGlobalTransformForObjects();
}