Qt 6.x
The Qt SDK
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>
73 QQuickParticleAffector(parent), m_strength(0.0), m_x(0), m_y(0)
74 , m_physics(Velocity), m_proportionalToDistance(Linear)
75{
76}
77
79{
80 if (m_strength == 0.0)
81 return false;
82 qreal dx = m_x+m_offset.x() - d->curX(m_system);
83 qreal dy = m_y+m_offset.y() - d->curY(m_system);
84 qreal r = std::sqrt((dx*dx) + (dy*dy));
85 qreal theta = std::atan2(dy,dx);
86 qreal ds = 0;
87 switch (m_proportionalToDistance){
89 ds = (m_strength / qMax<qreal>(1.,r*r));
90 break;
91 case InverseLinear:
92 ds = (m_strength / qMax<qreal>(1.,r));
93 break;
94 case Quadratic:
95 ds = (m_strength * qMax<qreal>(1.,r*r));
96 break;
97 case Linear:
98 ds = (m_strength * qMax<qreal>(1.,r));
99 break;
100 default: //also Constant
101 ds = m_strength;
102 }
103 ds *= dt;
104 dx = ds * std::cos(theta);
105 dy = ds * std::sin(theta);
106 qreal vx,vy;
107 switch (m_physics){
108 case Position:
109 d->x = (d->x + dx);
110 d->y = (d->y + dy);
111 break;
112 case Acceleration:
113 d->setInstantaneousAX(d->ax + dx, m_system);
114 d->setInstantaneousAY(d->ay + dy, m_system);
115 break;
116 case Velocity: //also default
117 default:
118 vx = d->curVX(m_system);
119 vy = d->curVY(m_system);
120 d->setInstantaneousVX(vx + dx, m_system);
121 d->setInstantaneousVY(vy + dy, m_system);
122 }
123
124 return true;
125}
127
128#include "moc_qquickpointattractor_p.cpp"
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:333
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:338
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:64
QQuickParticleSystem * m_system
Combined button and popup list for selecting options.
GLboolean r
[2]
double qreal
Definition qtypes.h:92
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent