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
qquick3dparticleshape.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
8#include <QtCore/qdir.h>
9#include <QtQml/qqmlfile.h>
10#include <QtQuick3D/private/qquick3dobject_p.h>
11#include <QtQuick3D/private/qquick3dmodel_p.h>
12#include <QtQuick3DRuntimeRender/private/qssgrenderbuffermanager_p.h>
13#include <algorithm>
14
16
35
44{
45 return m_fill;
46}
47
49{
50 if (m_fill == fill)
51 return;
52
53 m_fill = fill;
55}
56
82
91{
92 return m_extents;
93}
94
96{
97 if (m_type == type)
98 return;
99
100 m_type = type;
102}
103
105{
106 if (m_extents == extents)
107 return;
108
109 m_extents = extents;
111}
112
114{
115 if (!parentNode() || !m_system)
116 return QVector3D();
117
118 switch (m_type) {
120 return randomPositionCube(particleIndex);
122 return randomPositionSphere(particleIndex);
124 return randomPositionCylinder(particleIndex);
125 }
126 Q_UNREACHABLE_RETURN(QVector3D());
127}
128
129QVector3D QQuick3DParticleShape::randomPositionCube(int particleIndex) const
130{
131 auto rand = m_system->rand();
132 QVector3D s = m_parentNode->scale() * m_extents;
133 float x = s.x() - (rand->get(particleIndex, QPRand::Shape1) * s.x() * 2.0f);
134 float y = s.y() - (rand->get(particleIndex, QPRand::Shape2) * s.y() * 2.0f);
135 float z = s.z() - (rand->get(particleIndex, QPRand::Shape3) * s.z() * 2.0f);
136 if (!m_fill) {
137 // Random 0..5 for cube sides
138 int side = int(rand->get(particleIndex, QPRand::Shape4) * 6);
139 if (side == 0)
140 x = -s.x();
141 else if (side == 1)
142 x = s.x();
143 else if (side == 2)
144 y = -s.y();
145 else if (side == 3)
146 y = s.y();
147 else if (side == 4)
148 z = -s.z();
149 else
150 z = s.z();
151 }
152 QMatrix4x4 mat;
154 return mat.mapVector(QVector3D(x, y, z));
155}
156
157QVector3D QQuick3DParticleShape::randomPositionSphere(int particleIndex) const
158{
159 auto rand = m_system->rand();
160 QVector3D scale = m_parentNode->scale() * m_extents;
161 float theta = rand->get(particleIndex, QPRand::Shape1) * float(M_PI) * 2.0f;
162 float v = rand->get(particleIndex, QPRand::Shape2);
163 float phi = acos((2.0f * v) - 1.0f);
164 float r = m_fill ? pow(rand->get(particleIndex, QPRand::Shape3), 1.0f / 3.0f) : 1.0f;
165 float x = r * QPSIN(phi) * QPCOS(theta);
166 float y = r * QPSIN(phi) * QPSIN(theta);
167 float z = r * QPCOS(phi);
168 QVector3D pos(x, y, z);
169 pos *= scale;
170 QMatrix4x4 mat;
172 return mat.mapVector(pos);
173}
174
175QVector3D QQuick3DParticleShape::randomPositionCylinder(int particleIndex) const
176{
177 auto rand = m_system->rand();
178 QVector3D scale = m_parentNode->scale() * m_extents;
179 float y = scale.y() - (rand->get(particleIndex, QPRand::Shape1) * scale.y() * 2.0f);
180 float r = 1.0f;
181 if (m_fill)
182 r = sqrt(rand->get(particleIndex, QPRand::Shape2));
183 float theta = rand->get(particleIndex, QPRand::Shape3) * float(M_PI) * 2.0f;
184 float x = r * QPCOS(theta);
185 float z = r * QPSIN(theta);
186 x = x * scale.x();
187 z = z * scale.z();
188 QVector3D pos(x, y, z);
189 QMatrix4x4 mat;
191 return mat.mapVector(pos);
192}
193
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
void rotate(float angle, const QVector3D &vector)
Multiples this matrix by another that rotates coordinates through angle degrees about vector.
\inmodule QtCore
Definition qobject.h:103
QQuaternion rotation
QVector3D scale
QVector3D getPosition(int particleIndex) override
QQuick3DParticleShape(QObject *parent=nullptr)
\qmltype ParticleShape3D \inherits ParticleAbtractShape3D \inqmlmodule QtQuick3D.Particles3D
void setExtents(QVector3D extends)
void setType(QQuick3DParticleShape::ShapeType type)
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
friend constexpr decltype(auto) get(V &&vec) noexcept
Definition qvectornd.h:313
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:671
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:670
Combined button and popup list for selecting options.
#define M_PI
Definition qmath.h:209
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
GLboolean r
[2]
GLenum type
GLint y
GLdouble s
[6]
Definition qopenglext.h:235
GLenum GLenum GLenum GLenum GLenum scale
#define QPSIN
#define QPCOS
#define Q_EMIT
ba fill(true)