1 // Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350
2 /****************************************************************************
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
41 ****************************************************************************/
43 #include "qsgtranslate_p.h"
44 #include "qsgitem_p.h"
46 #include <QtCore/qmath.h>
50 class QSGTranslatePrivate : public QSGTransformPrivate
60 QSGTranslate::QSGTranslate(QObject *parent)
61 : QSGTransform(*new QSGTranslatePrivate, parent)
65 QSGTranslate::~QSGTranslate()
69 qreal QSGTranslate::x() const
71 Q_D(const QSGTranslate);
75 void QSGTranslate::setX(qreal x)
85 qreal QSGTranslate::y() const
87 Q_D(const QSGTranslate);
90 void QSGTranslate::setY(qreal y)
100 void QSGTranslate::applyTo(QMatrix4x4 *matrix) const
102 Q_D(const QSGTranslate);
103 matrix->translate(d->x, d->y, 0);
106 class QSGScalePrivate : public QSGTransformPrivate
110 : xScale(1), yScale(1), zScale(1) {}
117 QSGScale::QSGScale(QObject *parent)
118 : QSGTransform(*new QSGScalePrivate, parent)
122 QSGScale::~QSGScale()
126 QVector3D QSGScale::origin() const
131 void QSGScale::setOrigin(const QVector3D &point)
134 if (d->origin == point)
138 emit originChanged();
141 qreal QSGScale::xScale() const
146 void QSGScale::setXScale(qreal scale)
149 if (d->xScale == scale)
153 emit xScaleChanged();
157 qreal QSGScale::yScale() const
162 void QSGScale::setYScale(qreal scale)
165 if (d->yScale == scale)
169 emit yScaleChanged();
173 qreal QSGScale::zScale() const
178 void QSGScale::setZScale(qreal scale)
181 if (d->zScale == scale)
185 emit zScaleChanged();
189 void QSGScale::applyTo(QMatrix4x4 *matrix) const
192 matrix->translate(d->origin);
193 matrix->scale(d->xScale, d->yScale, d->zScale);
194 matrix->translate(-d->origin);
197 class QSGRotationPrivate : public QSGTransformPrivate
201 : angle(0), axis(0, 0, 1) {}
207 QSGRotation::QSGRotation(QObject *parent)
208 : QSGTransform(*new QSGRotationPrivate, parent)
212 QSGRotation::~QSGRotation()
216 QVector3D QSGRotation::origin() const
218 Q_D(const QSGRotation);
222 void QSGRotation::setOrigin(const QVector3D &point)
225 if (d->origin == point)
229 emit originChanged();
232 qreal QSGRotation::angle() const
234 Q_D(const QSGRotation);
237 void QSGRotation::setAngle(qreal angle)
240 if (d->angle == angle)
247 QVector3D QSGRotation::axis() const
249 Q_D(const QSGRotation);
252 void QSGRotation::setAxis(const QVector3D &axis)
262 void QSGRotation::setAxis(Qt::Axis axis)
267 setAxis(QVector3D(1, 0, 0));
270 setAxis(QVector3D(0, 1, 0));
273 setAxis(QVector3D(0, 0, 1));
278 struct QGraphicsRotation {
279 static inline void projectedRotate(QMatrix4x4 *matrix, qreal angle, qreal x, qreal y, qreal z)
281 matrix->projectedRotate(angle, x, y, z);
285 void QSGRotation::applyTo(QMatrix4x4 *matrix) const
287 Q_D(const QSGRotation);
289 if (d->angle == 0. || d->axis.isNull())
292 matrix->translate(d->origin);
293 QGraphicsRotation::projectedRotate(matrix, d->angle, d->axis.x(), d->axis.y(), d->axis.z());
294 matrix->translate(-d->origin);