1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QTUIOOBJECT_P_H
5#define QTUIOOBJECT_P_H
6
7#include <Qt>
8#include <qmath.h>
9
10QT_BEGIN_NAMESPACE
11
12/*!
13 \internal
14
15 A fiducial object, or token, represented by 2Dobj in TUIO 1.x and tok in TUIO 2:
16 a physical object whose position and rotation can be uniquely tracked
17 on the touchscreen surface.
18*/
19class QTuioToken
20{
21public:
22 QTuioToken(int id = -1)
23 : m_id(id)
24 , m_classId(-1)
25 , m_x(0)
26 , m_y(0)
27 , m_vx(0)
28 , m_vy(0)
29 , m_acceleration(0)
30 , m_angle(0)
31 , m_angularVelocity(0)
32 , m_angularAcceleration(0)
33 , m_state(QEventPoint::State::Pressed)
34 {
35 }
36
37 int id() const { return m_id; }
38
39 int classId() const { return m_classId; }
40 void setClassId(int classId) { m_classId = classId; }
41
42 void setX(float x)
43 {
44 if (state() == QEventPoint::State::Stationary &&
45 !qFuzzyCompare(p1: m_x + 2.0, p2: x + 2.0)) { // +2 because 1 is a valid value, and qFuzzyCompare can't cope with 0.0
46 setState(QEventPoint::State::Updated);
47 }
48 m_x = x;
49 }
50 float x() const { return m_x; }
51
52 void setY(float y)
53 {
54 if (state() == QEventPoint::State::Stationary &&
55 !qFuzzyCompare(p1: m_y + 2.0, p2: y + 2.0)) { // +2 because 1 is a valid value, and qFuzzyCompare can't cope with 0.0
56 setState(QEventPoint::State::Updated);
57 }
58 m_y = y;
59 }
60 float y() const { return m_y; }
61
62 void setVX(float vx) { m_vx = vx; }
63 float vx() const { return m_vx; }
64
65 void setVY(float vy) { m_vy = vy; }
66 float vy() const { return m_vy; }
67
68 void setAcceleration(float acceleration) { m_acceleration = acceleration; }
69 float acceleration() const { return m_acceleration; }
70
71 float angle() const { return m_angle; }
72 void setAngle(float angle)
73 {
74 if (angle > M_PI)
75 angle = angle - M_PI * 2.0; // zero is pointing upwards, and is the default; but we want to have negative angles when rotating left
76 if (state() == QEventPoint::State::Stationary &&
77 !qFuzzyCompare(p1: m_angle + 2.0, p2: angle + 2.0)) { // +2 because 1 is a valid value, and qFuzzyCompare can't cope with 0.0
78 setState(QEventPoint::State::Updated);
79 }
80 m_angle = angle;
81 }
82
83 float angularVelocity() const { return m_angularVelocity; }
84 void setAngularVelocity(float angularVelocity) { m_angularVelocity = angularVelocity; }
85
86 float angularAcceleration() const { return m_angularAcceleration; }
87 void setAngularAcceleration(float angularAcceleration) { m_angularAcceleration = angularAcceleration; }
88
89 void setState(const QEventPoint::State &state) { m_state = state; }
90 QEventPoint::State state() const { return m_state; }
91
92private:
93 int m_id; // sessionID, temporary object ID
94 int m_classId; // classID (e.g. marker ID)
95 float m_x;
96 float m_y;
97 float m_vx;
98 float m_vy;
99 float m_acceleration;
100 float m_angle;
101 float m_angularVelocity;
102 float m_angularAcceleration;
103 QEventPoint::State m_state;
104};
105Q_DECLARE_TYPEINFO(QTuioToken, Q_RELOCATABLE_TYPE); // Q_PRIMITIVE_TYPE: not possible: m_id, m_classId == -1
106
107QT_END_NAMESPACE
108
109#endif // QTUIOOBJECT_P_H
110

source code of qtbase/src/plugins/generic/tuiotouch/qtuiotoken_p.h