1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the Declarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qquickangledirection_p.h"
45 const qreal CONV = 0.017453292519943295;
47 \qmlclass AngleDirection QQuickAngleDirection
48 \inqmlmodule QtQuick.Particles 2
50 \brief The AngleDirection element allows you to specify a direction that varies in angle
52 The AngledDirection element allows both the specification of a direction by angle and magnitude,
53 as well as varying the parameters by angle or magnitude.
56 \qmlproperty real QtQuick.Particles2::AngleDirection::angle
57 This property specifies the base angle for the direction.
58 The angle of this direction will vary by no more than angleVariation
61 Angle is specified by degrees clockwise from straight right.
63 The default value is zero.
66 \qmlproperty real QtQuick.Particles2::AngleDirection::magnitude
67 This property specifies the base magnitude for the direction.
68 The magnitude of this direction will vary by no more than magnitudeVariation
71 Magnitude is specified in units of pixels per second.
73 The default value is zero.
76 \qmlproperty real QtQuick.Particles2::AngleDirection::angleVariation
77 This property specifies the maximum angle variation for the direction.
78 The angle of the direction will vary by up to angleVariation clockwise
79 and anticlockwise from the value specified in angle.
81 Angle is specified by degrees clockwise from straight right.
83 The default value is zero.
86 \qmlproperty real QtQuick.Particles2::AngleDirection::magnitudeVariation
87 This property specifies the base magnitude for the direction.
88 The magnitude of this direction will vary by no more than magnitudeVariation
89 from the base magnitude.
91 Magnitude is specified in units of pixels per second.
93 The default value is zero.
95 QQuickAngleDirection::QQuickAngleDirection(QObject *parent) :
96 QQuickDirection(parent)
100 , m_magnitudeVariation(0)
105 const QPointF QQuickAngleDirection::sample(const QPointF &from)
109 qreal theta = m_angle*CONV - m_angleVariation*CONV + rand()/float(RAND_MAX) * m_angleVariation*CONV * 2;
110 qreal mag = m_magnitude- m_magnitudeVariation + rand()/float(RAND_MAX) * m_magnitudeVariation * 2;
111 ret.setX(mag * cos(theta));
112 ret.setY(mag * sin(theta));