1 | // Copyright (C) 2016 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 | |
4 | #include "analogaxisinput_p.h" |
5 | |
6 | #include <Qt3DInput/qanalogaxisinput.h> |
7 | #include <Qt3DInput/qabstractphysicaldevice.h> |
8 | |
9 | #include <Qt3DInput/private/qabstractphysicaldevicebackendnode_p.h> |
10 | #include <Qt3DInput/private/qanalogaxisinput_p.h> |
11 | #include <Qt3DInput/private/utils_p.h> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | namespace Qt3DInput { |
16 | |
17 | namespace Input { |
18 | |
19 | AnalogAxisInput::AnalogAxisInput() |
20 | : AbstractAxisInput() |
21 | , m_axis(0) |
22 | { |
23 | } |
24 | |
25 | void AnalogAxisInput::cleanup() |
26 | { |
27 | m_axis = 0; |
28 | AbstractAxisInput::cleanup(); |
29 | } |
30 | |
31 | void AnalogAxisInput::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) |
32 | { |
33 | AbstractAxisInput::syncFromFrontEnd(frontEnd, firstTime); |
34 | const QAnalogAxisInput *node = qobject_cast<const QAnalogAxisInput *>(object: frontEnd); |
35 | if (!node) |
36 | return; |
37 | |
38 | m_axis = node->axis(); |
39 | } |
40 | |
41 | float AnalogAxisInput::process(InputHandler *inputHandler, qint64 currentTime) |
42 | { |
43 | Q_UNUSED(currentTime); |
44 | |
45 | if (!isEnabled()) |
46 | return 0.0f; |
47 | |
48 | if (m_axis == -1) |
49 | return 0.0f; |
50 | |
51 | QAbstractPhysicalDeviceBackendNode *physicalDeviceBackend = Utils::physicalDeviceForInput(input: this, handler: inputHandler); |
52 | if (!physicalDeviceBackend) |
53 | return 0.0f; |
54 | |
55 | return physicalDeviceBackend->processedAxisValue(axisIdentifier: m_axis); |
56 | } |
57 | |
58 | } // Input |
59 | |
60 | } // Qt3DInput |
61 | |
62 | QT_END_NAMESPACE |
63 |