Debian Codegraph @

tests/manual/rendertarget-cpp/orbittransformcontroller.cpp

raw symbols SCIP
1 // Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
2 // Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
3 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4
5 #include "orbittransformcontroller.h"
6
7 #include <Qt3DCore/qtransform.h>
8
9 QT_BEGIN_NAMESPACE
10
11 OrbitTransformController::OrbitTransformController(QObject *parent)
12 : QObject(parent)
13 , m_target(nullptr)
14 , m_matrix()
15 , m_radius(1.0f)
16 , m_angle(0.0f)
17 {
18 }
19
20 void OrbitTransformController::setTarget(Qt3DCore::QTransform *target)
21 {
22 if (m_target != target) {
23 m_target = target;
24 emit targetChanged();
25 }
26 }
27
28 Qt3DCore::QTransform *OrbitTransformController::target() const
29 {
30 return m_target;
31 }
32
33 void OrbitTransformController::setRadius(float radius)
34 {
35 if (!qFuzzyCompare(radius, m_radius)) {
36 m_radius = radius;
37 updateMatrix();
38 emit radiusChanged();
39 }
40 }
41
42 float OrbitTransformController::radius() const
43 {
44 return m_radius;
45 }
46
47 void OrbitTransformController::setAngle(float angle)
48 {
49 if (!qFuzzyCompare(angle, m_angle)) {
50 m_angle = angle;
51 updateMatrix();
52 emit angleChanged();
53 }
54 }
55
56 float OrbitTransformController::angle() const
57 {
58 return m_angle;
59 }
60
61 void OrbitTransformController::updateMatrix()
62 {
63 m_matrix.setToIdentity();
64 m_matrix.rotate(m_angle, QVector3D(0.0f, 1.0f, 0.0f));
65 m_matrix.translate(m_radius, 0.0f, 0.0f);
66 m_target->setMatrix(m_matrix);
67 }
68
69 QT_END_NAMESPACE