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
4#ifndef QQUICK3DPARTICLEUTILS_H
5#define QQUICK3DPARTICLEUTILS_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <qmath.h>
19#include <qmatrix4x4.h>
20#include <QtQuick3DParticles/qtquick3dparticlesglobal.h>
21#include <private/qglobal_p.h>
22
24
25class QQuaternion;
26class QQuick3DNode;
27
28// Define this to use C++ std::sinf & std::cosf for particles.
29// Those are more accurate, but also potentially less performant
30// than the lookup table versions.
31#ifdef QT_QUICK3D_PARTICLES_USE_STANDARD_SIN
32#define QPSIN sinf
33#define QPCOS cosf
34#else
35#define QPSIN qLookupSin
36#define QPCOS qLookupCos
37#endif
38
39// These sin & cos implementations are copied from qmath.h qFastSin & qFastCos.
40// Changes:
41// - Modified to use float instead of qreal (double).
42// - Use constexpr for optimization.
43//
44// With input values between 0 .. 2*M_PI, the accuracy of qLookupSin is quite good
45// (max delta ~2.5e-06). When the input values grow, accuracy decreases. For example
46// with value 2058, diff is ~0.00014 and with value 9632 diff is ~0.00074.
47// So these methods should not be used with a large input range if accuracy is important.
48
49#define QT_QUICK3D_SINE_TABLE_SIZE 256
50
51// Precalculated constexpr helpers
52static constexpr float QT_QUICK3D_SINE_H1 = 0.5f * float(QT_QUICK3D_SINE_TABLE_SIZE / M_PI);
53static constexpr float QT_QUICK3D_SINE_H2 = 2.0f * float(M_PI / QT_QUICK3D_SINE_TABLE_SIZE);
54
55extern Q_QUICK3DPARTICLES_EXPORT const float qt_quick3d_sine_table[QT_QUICK3D_SINE_TABLE_SIZE];
56
57inline float qLookupSin(float x)
58{
59 int si = int(x * QT_QUICK3D_SINE_H1); // Would be more accurate with qRound, but slower.
60 float d = x - si * QT_QUICK3D_SINE_H2;
61 int ci = si + QT_QUICK3D_SINE_TABLE_SIZE / 4;
64 return qt_quick3d_sine_table[si] + (qt_quick3d_sine_table[ci] - 0.5f * qt_quick3d_sine_table[si] * d) * d;
65}
66
67inline float qLookupCos(float x)
68{
69 int ci = int(x * QT_QUICK3D_SINE_H1); // Would be more accurate with qRound, but slower.
70 float d = x - ci * QT_QUICK3D_SINE_H2;
71 int si = ci + QT_QUICK3D_SINE_TABLE_SIZE / 4;
74 return qt_quick3d_sine_table[si] - (qt_quick3d_sine_table[ci] + 0.5f * qt_quick3d_sine_table[si] * d) * d;
75}
76
77QQuick3DNode *getSharedParentNode(QQuick3DNode *node, QQuick3DNode *system);
78QMatrix4x4 calculateParticleTransform(const QQuick3DNode *parent, const QQuick3DNode *systemSharedParent);
79QQuaternion calculateParticleRotation(const QQuick3DNode *parent, const QQuick3DNode *systemSharedParent);
80
81QT_END_NAMESPACE
82
83#endif // QQUICK3DPARTICLEUTILS_H
#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
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)