1 | // Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | #ifndef QT3DINPUT_MOVINGAVERAGE_P_H |
4 | #define QT3DINPUT_MOVINGAVERAGE_P_H |
5 | |
6 | // |
7 | // W A R N I N G |
8 | // ------------- |
9 | // |
10 | // This file is not part of the Qt API. It exists for the convenience |
11 | // of other Qt classes. This header file may change from version to |
12 | // version without notice, or even be removed. |
13 | // |
14 | // We mean it. |
15 | // |
16 | |
17 | #include <QtCore/private/qglobal_p.h> |
18 | |
19 | #include <vector> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | namespace Qt3DInput { |
24 | namespace Input { |
25 | |
26 | class MovingAverage |
27 | { |
28 | public: |
29 | MovingAverage(unsigned int samples = 3); |
30 | |
31 | void addSample(float sample); |
32 | |
33 | float average() const; |
34 | |
35 | private: |
36 | unsigned int m_maxSampleCount; |
37 | unsigned int m_sampleCount; |
38 | unsigned int m_currentSample; |
39 | float m_total; |
40 | std::vector<float> m_samples; |
41 | }; |
42 | |
43 | } // Input |
44 | } // Qt3DInput |
45 | |
46 | QT_END_NAMESPACE |
47 | |
48 | #endif // QT3DINPUT_MOVINGAVERAGE_H |
49 | |