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
qquickpointattractor.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
5#include <cmath>
6#include <QDebug>
69 QQuickParticleAffector(parent), m_strength(0.0), m_x(0), m_y(0)
70 , m_physics(Velocity), m_proportionalToDistance(Linear)
71{
72}
73
75{
76 if (m_strength == 0.0)
77 return false;
78 qreal dx = m_x+m_offset.x() - d->curX(m_system);
79 qreal dy = m_y+m_offset.y() - d->curY(m_system);
80 qreal r = std::sqrt((dx*dx) + (dy*dy));
81 qreal theta = std::atan2(dy,dx);
82 qreal ds = 0;
83 switch (m_proportionalToDistance){
85 ds = (m_strength / qMax<qreal>(1.,r*r));
86 break;
87 case InverseLinear:
88 ds = (m_strength / qMax<qreal>(1.,r));
89 break;
90 case Quadratic:
91 ds = (m_strength * qMax<qreal>(1.,r*r));
92 break;
93 case Linear:
94 ds = (m_strength * qMax<qreal>(1.,r));
95 break;
96 default: //also Constant
97 ds = m_strength;
98 }
99 ds *= dt;
100 dx = ds * std::cos(theta);
101 dy = ds * std::sin(theta);
102 qreal vx,vy;
103 switch (m_physics){
104 case Position:
105 d->x = (d->x + dx);
106 d->y = (d->y + dy);
107 break;
108 case Acceleration:
109 d->setInstantaneousAX(d->ax + dx, m_system);
110 d->setInstantaneousAY(d->ay + dy, m_system);
111 break;
112 case Velocity: //also default
113 default:
114 vx = d->curVX(m_system);
115 vy = d->curVY(m_system);
116 d->setInstantaneousVX(vx + dx, m_system);
117 d->setInstantaneousVY(vy + dy, m_system);
118 }
119
120 return true;
121}
123
124#include "moc_qquickpointattractor_p.cpp"
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
bool affectParticle(QQuickParticleData *d, qreal dt) override
QQuickAttractorAffector(QQuickItem *parent=nullptr)
\qmltype Attractor \instantiates QQuickAttractorAffector \inqmlmodule QtQuick.Particles\inherits Affe...
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.
GLboolean r
[2]
double qreal
Definition qtypes.h:187