1/****************************************************************************
2**
3** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QT3DCORE_QTRANSFORM_H
41#define QT3DCORE_QTRANSFORM_H
42
43#include <Qt3DCore/qcomponent.h>
44#include <QtGui/qmatrix4x4.h>
45#include <QtGui/qquaternion.h>
46#include <QtGui/qvector3d.h>
47
48QT_BEGIN_NAMESPACE
49
50namespace Qt3DCore {
51
52class QTransformPrivate;
53class Q_3DCORESHARED_EXPORT QTransform : public QComponent
54{
55 Q_OBJECT
56 Q_PROPERTY(QMatrix4x4 matrix READ matrix WRITE setMatrix NOTIFY matrixChanged)
57 Q_PROPERTY(float scale READ scale WRITE setScale NOTIFY scaleChanged)
58 Q_PROPERTY(QVector3D scale3D READ scale3D WRITE setScale3D NOTIFY scale3DChanged)
59 Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
60 Q_PROPERTY(QVector3D translation READ translation WRITE setTranslation NOTIFY translationChanged)
61 Q_PROPERTY(float rotationX READ rotationX WRITE setRotationX NOTIFY rotationXChanged)
62 Q_PROPERTY(float rotationY READ rotationY WRITE setRotationY NOTIFY rotationYChanged)
63 Q_PROPERTY(float rotationZ READ rotationZ WRITE setRotationZ NOTIFY rotationZChanged)
64
65public:
66 explicit QTransform(QNode *parent = nullptr);
67 ~QTransform();
68
69 float scale() const;
70 QVector3D scale3D() const;
71 QQuaternion rotation() const;
72 QVector3D translation() const;
73
74 Q_INVOKABLE static QQuaternion fromAxisAndAngle(const QVector3D &axis, float angle);
75 Q_INVOKABLE static QQuaternion fromAxisAndAngle(float x, float y, float z, float angle);
76
77 Q_INVOKABLE static QQuaternion fromAxesAndAngles(const QVector3D &axis1, float angle1,
78 const QVector3D &axis2, float angle2);
79 Q_INVOKABLE static QQuaternion fromAxesAndAngles(const QVector3D &axis1, float angle1,
80 const QVector3D &axis2, float angle2,
81 const QVector3D &axis3, float angle3);
82 Q_INVOKABLE static QQuaternion fromAxes(const QVector3D &xAxis, const QVector3D &yAxis, const QVector3D &zAxis);
83
84 Q_INVOKABLE static QQuaternion fromEulerAngles(const QVector3D &eulerAngles);
85 Q_INVOKABLE static QQuaternion fromEulerAngles(float pitch, float yaw, float roll);
86
87 Q_INVOKABLE static QMatrix4x4 rotateAround(const QVector3D &point, float angle, const QVector3D &axis);
88 Q_INVOKABLE static QMatrix4x4 rotateFromAxes(const QVector3D &xAxis, const QVector3D &yAxis, const QVector3D &zAxis);
89
90 QMatrix4x4 matrix() const;
91
92 float rotationX() const;
93 float rotationY() const;
94 float rotationZ() const;
95
96public Q_SLOTS:
97 void setScale(float scale);
98 void setScale3D(const QVector3D &scale);
99 void setRotation(const QQuaternion &rotation);
100 void setTranslation(const QVector3D &translation);
101 void setMatrix(const QMatrix4x4 &matrix);
102
103 void setRotationX(float rotationX);
104 void setRotationY(float rotationY);
105 void setRotationZ(float rotationZ);
106
107Q_SIGNALS:
108 void scaleChanged(float scale);
109 void scale3DChanged(const QVector3D &scale);
110 void rotationChanged(const QQuaternion &rotation);
111 void translationChanged(const QVector3D &translation);
112 void matrixChanged();
113 void rotationXChanged(float rotationX);
114 void rotationYChanged(float rotationY);
115 void rotationZChanged(float rotationZ);
116
117protected:
118 explicit QTransform(QTransformPrivate &dd, QNode *parent = nullptr);
119
120private:
121 Q_DECLARE_PRIVATE(QTransform)
122 QNodeCreatedChangeBasePtr createNodeCreationChange() const override;
123};
124
125} // namespace Qt3DCore
126
127QT_END_NAMESPACE
128
129#endif // QT3DCORE_QTRANSFORM_H
130