-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathglitem.cpp
157 lines (135 loc) · 3.7 KB
/
glitem.cpp
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/****************************************************************************
**
** Copyright (C) 2014 Alexander Rössler
** License: LGPL version 2.1
**
** This file is part of QtQuickVcp.
**
** All rights reserved. This program and the accompanying materials
** are made available under the terms of the GNU Lesser General Public License
** (LGPL) version 2.1 which accompanies this distribution, and is available at
** http://www.gnu.org/licenses/lgpl-2.1.html
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** Contributors:
** Alexander Rössler @ The Cool Tool GmbH <mail DOT aroessler AT gmail DOT com>
**
****************************************************************************/
#include "glitem.h"
namespace qtquickvcp {
GLItem::GLItem(QQuickItem *parent) :
QQuickItem(parent),
m_position(QVector3D(0,0,0)),
m_scale(QVector3D(1,1,1)),
m_rotation(QQuaternion()),
m_rotationAngle(0.0),
m_rotationAxis(QVector3D())
{
connect(this, &GLItem::positionChanged,
this, &GLItem::needsUpdate);
connect(this, &GLItem::scaleChanged,
this, &GLItem::needsUpdate);
connect(this, &GLItem::rotationChanged,
this, &GLItem::needsUpdate);
connect(this, &GLItem::rotationAngleChanged,
this, &GLItem::needsUpdate);
connect(this, &GLItem::rotationAxisChanged,
this, &GLItem::needsUpdate);
connect(this, &GLItem::visibleChanged,
this, &GLItem::needsUpdate);
}
QVector3D GLItem::position() const
{
return m_position;
}
QVector3D GLItem::scale() const
{
return m_scale;
}
QQuaternion GLItem::rotation() const
{
return m_rotation;
}
float GLItem::rotationAngle() const
{
return m_rotationAngle;
}
QVector3D GLItem::rotationAxis() const
{
return m_rotationAxis;
}
void GLItem::requestPaint()
{
emit needsUpdate();
}
void GLItem::setPosition(float x, float y, float z)
{
setPosition(QVector3D(x,y,z));
}
void GLItem::setPosition(const QVector3D &arg)
{
if (m_position != arg) {
m_position = arg;
emit positionChanged(arg);
}
}
void GLItem::setScale(float x, float y, float z)
{
setScale(QVector3D(x,y,z));
}
void GLItem::setScale(const QVector3D &arg)
{
if (m_scale != arg) {
m_scale = arg;
emit scaleChanged(arg);
}
}
void GLItem::setRotation(float angle, float x, float y, float z)
{
setRotation(angle, QVector3D(x,y,z));
}
void GLItem::setRotation(float angle, const QVector3D &axis)
{
setRotation(QQuaternion(angle, axis));
}
void GLItem::setRotation(const QQuaternion &arg)
{
if (m_rotation != arg) {
m_rotation = arg;
emit rotationChanged(arg);
}
}
void GLItem::setRotationAngle(float arg)
{
if (m_rotationAngle != arg) {
m_rotationAngle = arg;
emit rotationAngleChanged(arg);
setRotation(QQuaternion::fromAxisAndAngle(m_rotationAxis, m_rotationAngle));
}
}
void GLItem::setRotationAxis(const QVector3D &arg)
{
if (m_rotationAxis != arg) {
m_rotationAxis = arg;
emit rotationAxisChanged(arg);
setRotation(QQuaternion::fromAxisAndAngle(m_rotationAxis, m_rotationAngle));
}
}
void GLItem::setRotationVector(const QVector3D &rotationVector)
{
if (m_rotationVector == rotationVector) {
return;
}
m_rotationVector = rotationVector;
emit rotationVectorChanged(m_rotationVector);
setRotation(QQuaternion::fromEulerAngles(m_rotationVector));
}
QVector3D qtquickvcp::GLItem::rotationVector() const
{
return m_rotationVector;
}
} // namespace qtquickvcp