1// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "transform_p.h"
5
6#include <Qt3DCore/private/qchangearbiter_p.h>
7#include <Qt3DCore/qtransform.h>
8#include <Qt3DCore/private/qtransform_p.h>
9
10QT_BEGIN_NAMESPACE
11
12using namespace Qt3DCore;
13
14namespace Qt3DRender {
15namespace Render {
16
17Transform::Transform()
18 : BackendNode(ReadWrite)
19 , m_rotation()
20 , m_scale(1.0f, 1.0f, 1.0f)
21 , m_translation()
22{
23}
24
25void Transform::cleanup()
26{
27 m_rotation = QQuaternion();
28 m_scale = QVector3D();
29 m_translation = QVector3D();
30 m_transformMatrix = Matrix4x4();
31 QBackendNode::setEnabled(false);
32}
33
34Matrix4x4 Transform::transformMatrix() const
35{
36 return m_transformMatrix;
37}
38
39QVector3D Transform::scale() const
40{
41 return m_scale;
42}
43
44QQuaternion Transform::rotation() const
45{
46 return m_rotation;
47}
48
49QVector3D Transform::translation() const
50{
51 return m_translation;
52}
53
54void Transform::syncFromFrontEnd(const QNode *frontEnd, bool firstTime)
55{
56 const Qt3DCore::QTransform *transform = qobject_cast<const Qt3DCore::QTransform *>(object: frontEnd);
57 if (!transform)
58 return;
59
60 bool dirty = m_rotation != transform->rotation();
61 m_rotation = transform->rotation();
62 dirty |= m_scale != transform->scale3D();
63 m_scale = transform->scale3D();
64 dirty |= m_translation != transform->translation();
65 m_translation = transform->translation();
66
67 if (dirty || firstTime) {
68 updateMatrix();
69 markDirty(changes: AbstractRenderer::TransformDirty);
70 }
71
72 if (transform->isEnabled() != isEnabled())
73 markDirty(changes: AbstractRenderer::TransformDirty);
74
75 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
76}
77
78void Transform::updateMatrix()
79{
80 QMatrix4x4 m;
81 m.translate(vector: m_translation);
82 m.rotate(quaternion: m_rotation);
83 m.scale(vector: m_scale);
84 m_transformMatrix = Matrix4x4(m);
85}
86
87} // namespace Render
88} // namespace Qt3DRender
89
90QT_END_NAMESPACE
91

source code of qt3d/src/render/backend/transform.cpp