1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QTUIOOBJECT_P_H
41#define QTUIOOBJECT_P_H
42
43#include <Qt>
44#include <qmath.h>
45
46QT_BEGIN_NAMESPACE
47
48/*!
49 \internal
50
51 A fiducial object, or token, represented by 2Dobj in TUIO 1.x and tok in TUIO 2:
52 a physical object whose position and rotation can be uniquely tracked
53 on the touchscreen surface.
54*/
55class QTuioToken
56{
57public:
58 QTuioToken(int id = -1)
59 : m_id(id)
60 , m_classId(-1)
61 , m_x(0)
62 , m_y(0)
63 , m_vx(0)
64 , m_vy(0)
65 , m_acceleration(0)
66 , m_angle(0)
67 , m_angularVelocity(0)
68 , m_angularAcceleration(0)
69 , m_state(QEventPoint::State::Pressed)
70 {
71 }
72
73 int id() const { return m_id; }
74
75 int classId() const { return m_classId; }
76 void setClassId(int classId) { m_classId = classId; }
77
78 void setX(float x)
79 {
80 if (state() == QEventPoint::State::Stationary &&
81 !qFuzzyCompare(m_x + 2.0, x + 2.0)) { // +2 because 1 is a valid value, and qFuzzyCompare can't cope with 0.0
82 setState(QEventPoint::State::Updated);
83 }
84 m_x = x;
85 }
86 float x() const { return m_x; }
87
88 void setY(float y)
89 {
90 if (state() == QEventPoint::State::Stationary &&
91 !qFuzzyCompare(m_y + 2.0, y + 2.0)) { // +2 because 1 is a valid value, and qFuzzyCompare can't cope with 0.0
92 setState(QEventPoint::State::Updated);
93 }
94 m_y = y;
95 }
96 float y() const { return m_y; }
97
98 void setVX(float vx) { m_vx = vx; }
99 float vx() const { return m_vx; }
100
101 void setVY(float vy) { m_vy = vy; }
102 float vy() const { return m_vy; }
103
104 void setAcceleration(float acceleration) { m_acceleration = acceleration; }
105 float acceleration() const { return m_acceleration; }
106
107 float angle() const { return m_angle; }
108 void setAngle(float angle)
109 {
110 if (angle > M_PI)
111 angle = angle - M_PI * 2.0; // zero is pointing upwards, and is the default; but we want to have negative angles when rotating left
112 if (state() == QEventPoint::State::Stationary &&
113 !qFuzzyCompare(m_angle + 2.0, angle + 2.0)) { // +2 because 1 is a valid value, and qFuzzyCompare can't cope with 0.0
114 setState(QEventPoint::State::Updated);
115 }
116 m_angle = angle;
117 }
118
119 float angularVelocity() const { return m_angularVelocity; }
120 void setAngularVelocity(float angularVelocity) { m_angularVelocity = angularVelocity; }
121
122 float angularAcceleration() const { return m_angularAcceleration; }
123 void setAngularAcceleration(float angularAcceleration) { m_angularAcceleration = angularAcceleration; }
124
125 void setState(const QEventPoint::State &state) { m_state = state; }
126 QEventPoint::State state() const { return m_state; }
127
128private:
129 int m_id; // sessionID, temporary object ID
130 int m_classId; // classID (e.g. marker ID)
131 float m_x;
132 float m_y;
133 float m_vx;
134 float m_vy;
135 float m_acceleration;
136 float m_angle;
137 float m_angularVelocity;
138 float m_angularAcceleration;
139 QEventPoint::State m_state;
140};
141Q_DECLARE_TYPEINFO(QTuioToken, Q_MOVABLE_TYPE); // Q_PRIMITIVE_TYPE: not possible: m_id, m_classId == -1
142
143QT_END_NAMESPACE
144
145#endif // QTUIOOBJECT_P_H
146