Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquick3dparticleutils_p.h
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
// Qt-Security score:significant reason:default
4
5
6
#
ifndef
QQUICK3DPARTICLEUTILS_H
7
#
define
QQUICK3DPARTICLEUTILS_H
8
9
//
10
// W A R N I N G
11
// -------------
12
//
13
// This file is not part of the Qt API. It exists purely as an
14
// implementation detail. This header file may change from version to
15
// version without notice, or even be removed.
16
//
17
// We mean it.
18
//
19
20
#
include
<
qmath
.
h
>
21
#
include
<
qmatrix4x4
.
h
>
22
#
include
<
QtQuick3DParticles
/
qtquick3dparticlesglobal
.
h
>
23
#
include
<
private
/
qglobal_p
.
h
>
24
25
QT_BEGIN_NAMESPACE
26
27
class
QQuaternion;
28
class
QQuick3DNode;
29
class
QQuick3DModel;
30
class
QQmlContext;
31
32
// Define this to use C++ std::sinf & std::cosf for particles.
33
// Those are more accurate, but also potentially less performant
34
// than the lookup table versions.
35
#
ifdef
QT_QUICK3D_PARTICLES_USE_STANDARD_SIN
36
#
define
QPSIN
sinf
37
#
define
QPCOS
cosf
38
#
else
39
#
define
QPSIN
qLookupSin
40
#
define
QPCOS
qLookupCos
41
#
endif
42
43
// These sin & cos implementations are copied from qmath.h qFastSin & qFastCos.
44
// Changes:
45
// - Modified to use float instead of qreal (double).
46
// - Use constexpr for optimization.
47
//
48
// With input values between 0 .. 2*M_PI, the accuracy of qLookupSin is quite good
49
// (max delta ~2.5e-06). When the input values grow, accuracy decreases. For example
50
// with value 2058, diff is ~0.00014 and with value 9632 diff is ~0.00074.
51
// So these methods should not be used with a large input range if accuracy is important.
52
53
#
define
QT_QUICK3D_SINE_TABLE_SIZE
256
54
55
// Precalculated constexpr helpers
56
static
constexpr
float
QT_QUICK3D_SINE_H1
= 0.5f *
float
(
QT_QUICK3D_SINE_TABLE_SIZE
/
M_PI
);
57
static
constexpr
float
QT_QUICK3D_SINE_H2
= 2.0f *
float
(
M_PI
/
QT_QUICK3D_SINE_TABLE_SIZE
);
58
59
extern
Q_QUICK3DPARTICLES_EXPORT
const
float
qt_quick3d_sine_table
[
QT_QUICK3D_SINE_TABLE_SIZE
];
60
61
inline
float
qLookupSin
(
float
x)
62
{
63
int
si =
int
(x *
QT_QUICK3D_SINE_H1
);
// Would be more accurate with qRound, but slower.
64
float
d = x - si *
QT_QUICK3D_SINE_H2
;
65
int
ci = si +
QT_QUICK3D_SINE_TABLE_SIZE
/ 4;
66
si &=
QT_QUICK3D_SINE_TABLE_SIZE
- 1;
67
ci &=
QT_QUICK3D_SINE_TABLE_SIZE
- 1;
68
return
qt_quick3d_sine_table[si] + (qt_quick3d_sine_table[ci] - 0.5f * qt_quick3d_sine_table[si] * d) * d;
69
}
70
71
inline
float
qLookupCos
(
float
x)
72
{
73
int
ci =
int
(x *
QT_QUICK3D_SINE_H1
);
// Would be more accurate with qRound, but slower.
74
float
d = x - ci *
QT_QUICK3D_SINE_H2
;
75
int
si = ci +
QT_QUICK3D_SINE_TABLE_SIZE
/ 4;
76
si &=
QT_QUICK3D_SINE_TABLE_SIZE
- 1;
77
ci &=
QT_QUICK3D_SINE_TABLE_SIZE
- 1;
78
return
qt_quick3d_sine_table[si] - (qt_quick3d_sine_table[ci] + 0.5f * qt_quick3d_sine_table[si] * d) * d;
79
}
80
81
QQuick3DNode *
getSharedParentNode
(QQuick3DNode *node, QQuick3DNode *system);
82
QMatrix4x4
calculateParticleTransform
(
const
QQuick3DNode *parent,
const
QQuick3DNode *systemSharedParent);
83
QQuaternion
calculateParticleRotation
(
const
QQuick3DNode *parent,
const
QQuick3DNode *systemSharedParent);
84
QList
<
QVector3D
>
positionsFromModel
(QQuick3DModel *model,
const
QMatrix4x4 *matrix, QQmlContext *context);
85
86
QT_END_NAMESPACE
87
88
#
endif
// QQUICK3DPARTICLEUTILS_H
QQuick3DParticleAffector
Definition
qquick3dparticleaffector_p.h:31
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
M_PI
#define M_PI
Definition
qmath.h:201
getSharedParentNode
QQuick3DNode * getSharedParentNode(QQuick3DNode *node, QQuick3DNode *system)
Definition
qquick3dparticleutils.cpp:280
QT_QUICK3D_SINE_H2
static constexpr float QT_QUICK3D_SINE_H2
Definition
qquick3dparticleutils_p.h:57
qt_quick3d_sine_table
Q_QUICK3DPARTICLES_EXPORT const float qt_quick3d_sine_table[QT_QUICK3D_SINE_TABLE_SIZE]
Definition
qquick3dparticleutils.cpp:20
QT_QUICK3D_SINE_TABLE_SIZE
#define QT_QUICK3D_SINE_TABLE_SIZE
Definition
qquick3dparticleutils_p.h:53
positionsFromModel
QList< QVector3D > positionsFromModel(QQuick3DModel *model, const QMatrix4x4 *matrix, QQmlContext *context)
Definition
qquick3dparticleutils.cpp:339
calculateParticleTransform
QMatrix4x4 calculateParticleTransform(const QQuick3DNode *parent, const QQuick3DNode *systemSharedParent)
Definition
qquick3dparticleutils.cpp:302
calculateParticleRotation
QQuaternion calculateParticleRotation(const QQuick3DNode *parent, const QQuick3DNode *systemSharedParent)
Definition
qquick3dparticleutils.cpp:310
QT_QUICK3D_SINE_H1
static constexpr float QT_QUICK3D_SINE_H1
Definition
qquick3dparticleutils_p.h:56
qLookupSin
float qLookupSin(float x)
Definition
qquick3dparticleutils_p.h:61
qLookupCos
float qLookupCos(float x)
Definition
qquick3dparticleutils_p.h:71
qtquick3d
src
quick3dparticles
qquick3dparticleutils_p.h
Generated on
for Qt by
1.18.0