Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / quick / particles / qquickangledirection.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the Declarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qquickangledirection_p.h"
43 #include <cmath>
44 QT_BEGIN_NAMESPACE
45 const qreal CONV = 0.017453292519943295;
46 /*!
47     \qmlclass AngleDirection QQuickAngleDirection
48     \inqmlmodule QtQuick.Particles 2
49     \inherits Direction
50     \brief The AngleDirection element allows you to specify a direction that varies in angle
51
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.
54 */
55 /*!
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
59     from this angle.
60
61     Angle is specified by degrees clockwise from straight right.
62
63     The default value is zero.
64 */
65 /*!
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
69     from this magnitude.
70
71     Magnitude is specified in units of pixels per second.
72
73     The default value is zero.
74 */
75 /*!
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.
80
81     Angle is specified by degrees clockwise from straight right.
82
83     The default value is zero.
84 */
85 /*!
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.
90
91     Magnitude is specified in units of pixels per second.
92
93     The default value is zero.
94 */
95 QQuickAngleDirection::QQuickAngleDirection(QObject *parent) :
96     QQuickDirection(parent)
97   , m_angle(0)
98   , m_magnitude(0)
99   , m_angleVariation(0)
100   , m_magnitudeVariation(0)
101 {
102
103 }
104
105 const QPointF QQuickAngleDirection::sample(const QPointF &from)
106 {
107     Q_UNUSED(from);
108     QPointF ret;
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));
113     return ret;
114 }
115
116 QT_END_NAMESPACE