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-06-07 05:12:53 +00:00
|
|
|
#include "qsggravity_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
|
|
|
/*!
|
|
|
|
\qmlclass Gravity QSGGravityAffector
|
|
|
|
\inqmlmodule QtQuick.Particles 2
|
|
|
|
\inherits Affector
|
|
|
|
\brief The Gravity element allows you to set a constant accleration in an angle
|
|
|
|
|
|
|
|
This element will set the acceleration of all affected particles to a vector of
|
2011-10-10 09:22:24 +00:00
|
|
|
the specified magnitude in the specified angle. If the angle or acceleration is
|
|
|
|
not varying, 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
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\qmlproperty real QtQuick.Particles2::Gravity::acceleration
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
\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-14 08:51:42 +00:00
|
|
|
QSGGravityAffector::QSGGravityAffector(QQuickItem *parent) :
|
2011-06-07 05:12:53 +00:00
|
|
|
QSGParticleAffector(parent), m_acceleration(-10), m_angle(90), m_xAcc(0), m_yAcc(0)
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
connect(this, SIGNAL(accelerationChanged(qreal)),
|
|
|
|
this, SLOT(recalc()));
|
|
|
|
connect(this, SIGNAL(angleChanged(qreal)),
|
|
|
|
this, SLOT(recalc()));
|
|
|
|
recalc();
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-06-07 05:12:53 +00:00
|
|
|
void QSGGravityAffector::recalc()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-04-27 12:13:26 +00:00
|
|
|
qreal theta = m_angle * CONV;
|
|
|
|
m_xAcc = m_acceleration * cos(theta);
|
|
|
|
m_yAcc = m_acceleration * sin(theta);
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-06-07 05:12:53 +00:00
|
|
|
bool QSGGravityAffector::affectParticle(QSGParticleData *d, qreal dt)
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(dt);
|
|
|
|
bool changed = false;
|
2011-07-04 08:15:28 +00:00
|
|
|
if (d->ax != m_xAcc){
|
2011-04-27 12:13:26 +00:00
|
|
|
d->setInstantaneousAX(m_xAcc);
|
|
|
|
changed = true;
|
|
|
|
}
|
2011-07-04 08:15:28 +00:00
|
|
|
if (d->ay != m_yAcc){
|
2011-04-27 12:13:26 +00:00
|
|
|
d->setInstantaneousAY(m_yAcc);
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
return changed;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_END_NAMESPACE
|