Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickfriction.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qquickfriction_p.h"
5#include <qmath.h>
6
32{
33 return a >= 0 ? 1 : -1;
34}
35
36static const qreal epsilon = 0.00001;
37
39 QQuickParticleAffector(parent), m_factor(0.0), m_threshold(0.0)
40{
41}
42
44{
45 if (!m_factor)
46 return false;
47 qreal curVX = d->curVX(m_system);
48 qreal curVY = d->curVY(m_system);
49 if (!curVX && !curVY)
50 return false;
51 qreal newVX = curVX + (curVX * m_factor * -1 * dt);
52 qreal newVY = curVY + (curVY * m_factor * -1 * dt);
53
54 if (!m_threshold) {
55 if (sign(curVX) != sign(newVX))
56 newVX = 0;
57 if (sign(curVY) != sign(newVY))
58 newVY = 0;
59 } else {
60 qreal curMag = qSqrt(curVX*curVX + curVY*curVY);
61 if (curMag <= m_threshold + epsilon)
62 return false;
63 qreal newMag = qSqrt(newVX*newVX + newVY*newVY);
64 if (newMag <= m_threshold + epsilon || //went past the threshold, stop there instead
65 sign(curVX) != sign(newVX) || //went so far past maybe it came out the other side!
66 sign(curVY) != sign(newVY)) {
67 qreal theta = qAtan2(curVY, curVX);
68 newVX = m_threshold * qCos(theta);
69 newVY = m_threshold * qSin(theta);
70 }
71 }
72
73 d->setInstantaneousVX(newVX, m_system);
74 d->setInstantaneousVY(newVY, m_system);
75 return true;
76}
78
79#include "moc_qquickfriction_p.cpp"
QQuickFrictionAffector(QQuickItem *parent=nullptr)
bool affectParticle(QQuickParticleData *d, qreal dt) override
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
QQuickParticleSystem * m_system
Combined button and popup list for selecting options.
qfloat16 qSqrt(qfloat16 f)
Definition qfloat16.h:289
auto qAtan2(T1 y, T2 x)
Definition qmath.h:90
auto qCos(T v)
Definition qmath.h:60
auto qSin(T v)
Definition qmath.h:54
GLboolean GLboolean GLboolean GLboolean a
[7]
static QT_BEGIN_NAMESPACE qreal sign(qreal a)
\qmltype Friction \instantiates QQuickFrictionAffector \inqmlmodule QtQuick.Particles\inherits Affect...
static const qreal epsilon
double qreal
Definition qtypes.h:187
static int sign(int x)