Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
26
27class QQuaternion;
28class QQuick3DNode;
29class QQuick3DModel;
30class 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
56static constexpr float QT_QUICK3D_SINE_H1 = 0.5f * float(QT_QUICK3D_SINE_TABLE_SIZE / M_PI);
57static constexpr float QT_QUICK3D_SINE_H2 = 2.0f * float(M_PI / QT_QUICK3D_SINE_TABLE_SIZE);
58
59extern Q_QUICK3DPARTICLES_EXPORT const float qt_quick3d_sine_table[QT_QUICK3D_SINE_TABLE_SIZE];
60
61inline 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;
68 return qt_quick3d_sine_table[si] + (qt_quick3d_sine_table[ci] - 0.5f * qt_quick3d_sine_table[si] * d) * d;
69}
70
71inline 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;
78 return qt_quick3d_sine_table[si] - (qt_quick3d_sine_table[ci] + 0.5f * qt_quick3d_sine_table[si] * d) * d;
79}
80
81QQuick3DNode *getSharedParentNode(QQuick3DNode *node, QQuick3DNode *system);
82QMatrix4x4 calculateParticleTransform(const QQuick3DNode *parent, const QQuick3DNode *systemSharedParent);
83QQuaternion calculateParticleRotation(const QQuick3DNode *parent, const QQuick3DNode *systemSharedParent);
84QList<QVector3D> positionsFromModel(QQuick3DModel *model, const QMatrix4x4 *matrix, QQmlContext *context);
85
86QT_END_NAMESPACE
87
88#endif // QQUICK3DPARTICLEUTILS_H
Combined button and popup list for selecting options.
#define M_PI
Definition qmath.h:200
QQuick3DNode * getSharedParentNode(QQuick3DNode *node, QQuick3DNode *system)
static constexpr float QT_QUICK3D_SINE_H2
Q_QUICK3DPARTICLES_EXPORT const float qt_quick3d_sine_table[QT_QUICK3D_SINE_TABLE_SIZE]
#define QT_QUICK3D_SINE_TABLE_SIZE
QList< QVector3D > positionsFromModel(QQuick3DModel *model, const QMatrix4x4 *matrix, QQmlContext *context)
QMatrix4x4 calculateParticleTransform(const QQuick3DNode *parent, const QQuick3DNode *systemSharedParent)
QQuaternion calculateParticleRotation(const QQuick3DNode *parent, const QQuick3DNode *systemSharedParent)
static constexpr float QT_QUICK3D_SINE_H1
float qLookupSin(float x)
float qLookupCos(float x)