2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2011-04-27 12:13:26 +00:00
|
|
|
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2011-04-27 10:05:43 +00:00
|
|
|
** All rights reserved.
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
**
|
2011-04-27 12:13:26 +00:00
|
|
|
** This file is part of the Declarative module of the Qt Toolkit.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
** GNU Lesser General Public License Usage
|
2011-07-07 12:52:03 +00:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU Lesser
|
|
|
|
** General Public License version 2.1 requirements will be met:
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-07-07 12:52:03 +00:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-07-07 12:52:03 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
|
|
** Public License version 3.0 as published by the Free Software Foundation
|
|
|
|
** and appearing in the file LICENSE.GPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU General
|
|
|
|
** Public License version 3.0 requirements will be met:
|
|
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
|
|
|
**
|
|
|
|
** Other Usage
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-10-24 21:57:54 +00:00
|
|
|
#include "qquickgravity_p.h"
|
2011-04-27 12:13:26 +00:00
|
|
|
#include <cmath>
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
2011-04-27 12:13:26 +00:00
|
|
|
const qreal CONV = 0.017453292520444443;
|
2011-07-11 01:20:58 +00:00
|
|
|
/*!
|
2011-10-24 21:57:54 +00:00
|
|
|
\qmlclass Gravity QQuickGravityAffector
|
2011-07-11 01:20:58 +00:00
|
|
|
\inqmlmodule QtQuick.Particles 2
|
|
|
|
\inherits Affector
|
2011-10-20 08:03:37 +00:00
|
|
|
\brief The Gravity element allows you to set an accleration in an angle
|
2011-07-11 01:20:58 +00:00
|
|
|
|
2011-10-20 08:03:37 +00:00
|
|
|
This element will accelerate all affected particles to a vector of
|
|
|
|
the specified magnitude in the specified angle. If the angle and acceleration do
|
|
|
|
not vary, it is more efficient to set the specified acceleration on the Emitter.
|
2011-09-01 11:43:20 +00:00
|
|
|
|
|
|
|
This element models the gravity of a massive object whose center of
|
|
|
|
gravity is far away (and thus the gravitational pull is effectively constant
|
|
|
|
across the scene). To model the gravity of an object near or inside the scene,
|
|
|
|
use PointAttractor.
|
2011-07-11 01:20:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
2011-10-20 08:03:37 +00:00
|
|
|
\qmlproperty real QtQuick.Particles2::Gravity::magnitude
|
2011-07-11 01:20:58 +00:00
|
|
|
|
2011-09-01 11:43:20 +00:00
|
|
|
Pixels per second that objects will be accelerated by.
|
2011-07-11 01:20:58 +00:00
|
|
|
*/
|
2011-10-20 08:03:37 +00:00
|
|
|
/*!
|
|
|
|
\qmlproperty real QtQuick.Particles2::Gravity::acceleration
|
|
|
|
|
|
|
|
Name changed to magnitude, will be removed soon.
|
|
|
|
*/
|
2011-07-11 01:20:58 +00:00
|
|
|
/*!
|
|
|
|
\qmlproperty real QtQuick.Particles2::Gravity::angle
|
2011-09-01 11:43:20 +00:00
|
|
|
|
|
|
|
Angle of acceleration.
|
2011-07-11 01:20:58 +00:00
|
|
|
*/
|
|
|
|
|
2011-10-24 21:57:54 +00:00
|
|
|
QQuickGravityAffector::QQuickGravityAffector(QQuickItem *parent) :
|
2011-10-20 08:03:37 +00:00
|
|
|
QQuickParticleAffector(parent), m_magnitude(-10), m_angle(90), m_needRecalc(true)
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-10-24 21:57:54 +00:00
|
|
|
bool QQuickGravityAffector::affectParticle(QQuickParticleData *d, qreal dt)
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-20 08:03:37 +00:00
|
|
|
if (!m_magnitude)
|
|
|
|
return false;
|
|
|
|
if (m_needRecalc) {
|
|
|
|
m_needRecalc = false;
|
|
|
|
m_dx = m_magnitude * cos(m_angle * CONV);
|
|
|
|
m_dy = m_magnitude * sin(m_angle * CONV);
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
2011-10-20 08:03:37 +00:00
|
|
|
|
|
|
|
d->setInstantaneousVX(d->curVX() + m_dx*dt);
|
|
|
|
d->setInstantaneousVY(d->curVY() + m_dy*dt);
|
|
|
|
return true;
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_END_NAMESPACE
|