Repository navigation
Expand file tree
/
Copy pathTuioPoint.java
More file actions
266 lines (237 loc) · 7.58 KB
/
Copy pathTuioPoint.java
File metadata and controls
266 lines (237 loc) · 7.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
TUIO Java backend - part of the reacTIVision project
http://reactivision.sourceforge.net/
Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package TUIO;
/**
* The TuioPoint class on the one hand is a simple container and utility class to handle TUIO positions in general,
* on the other hand the TuioPoint is the base class for the TuioCursor and TuioObject classes.
*
* @author Martin Kaltenbrunner
* @version 1.4
*/
public class TuioPoint {
/**
* X coordinate, representated as a floating point value in a range of 0..1
*/
protected float xpos;
/**
* Y coordinate, representated as a floating point value in a range of 0..1
*/
protected float ypos;
/**
* The time stamp of the last update represented as TuioTime (time since session start)
*/
protected TuioTime currentTime;
/**
* The creation time of this TuioPoint represented as TuioTime (time since session start)
*/
protected TuioTime startTime;
/**
* The default constructor takes no arguments and sets
* its coordinate attributes to zero and its time stamp to the current session time.
*/
public TuioPoint() {
xpos = 0.0f;
ypos = 0.0f;
currentTime = TuioTime.getSessionTime();
startTime = new TuioTime(currentTime);
}
/**
* This constructor takes two floating point coordinate arguments and sets
* its coordinate attributes to these values and its time stamp to the current session time.
*
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
*/
public TuioPoint(float xp, float yp) {
xpos = xp;
ypos = yp;
currentTime = TuioTime.getSessionTime();
startTime = new TuioTime(currentTime);
}
/**
* This constructor takes a TuioPoint argument and sets its coordinate attributes
* to the coordinates of the provided TuioPoint and its time stamp to the current session time.
*
* @param tpoint the TuioPoint to assign
*/
public TuioPoint(TuioPoint tpoint) {
xpos = tpoint.getX();
ypos = tpoint.getY();
currentTime = TuioTime.getSessionTime();
startTime = new TuioTime(currentTime);
}
/**
* This constructor takes a TuioTime object and two floating point coordinate arguments and sets
* its coordinate attributes to these values and its time stamp to the provided TUIO time object.
*
* @param ttime the TuioTime to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
*/
public TuioPoint(TuioTime ttime, float xp, float yp) {
xpos = xp;
ypos = yp;
currentTime = new TuioTime(ttime);
startTime = new TuioTime(currentTime);
}
/**
* Takes a TuioPoint argument and updates its coordinate attributes
* to the coordinates of the provided TuioPoint and leaves its time stamp unchanged.
*
* @param tpoint the TuioPoint to assign
*/
public void update(TuioPoint tpoint) {
xpos = tpoint.getX();
ypos = tpoint.getY();
}
/**
* Takes two floating point coordinate arguments and updates its coordinate attributes
* to the coordinates of the provided TuioPoint and leaves its time stamp unchanged.
*
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
*/
public void update(float xp, float yp) {
xpos = xp;
ypos = yp;
}
/**
* Takes a TuioTime object and two floating point coordinate arguments and updates its coordinate attributes
* to the coordinates of the provided TuioPoint and its time stamp to the provided TUIO time object.
*
* @param ttime the TuioTime to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
*/
public void update(TuioTime ttime, float xp, float yp) {
xpos = xp;
ypos = yp;
currentTime = new TuioTime(ttime);
}
/**
* Returns the X coordinate of this TuioPoint.
* @return the X coordinate of this TuioPoint
*/
public float getX() {
return xpos;
}
/**
* Returns the Y coordinate of this TuioPoint.
* @return the Y coordinate of this TuioPoint
*/
public float getY() {
return ypos;
}
/**
* Returns the distance to the provided coordinates
*
* @param xp the X coordinate of the distant point
* @param yp the Y coordinate of the distant point
* @return the distance to the provided coordinates
*/
public float getDistance(float xp, float yp) {
float dx = xpos-xp;
float dy = ypos-yp;
return (float)Math.sqrt(dx*dx+dy*dy);
}
/**
* Returns the distance to the provided TuioPoint
*
* @param tpoint the distant TuioPoint
* @return the distance to the provided TuioPoint
*/
public float getDistance(TuioPoint tpoint) {
return getDistance(tpoint.getX(),tpoint.getY());
}
/**
* Returns the angle to the provided coordinates
*
* @param xp the X coordinate of the distant point
* @param yp the Y coordinate of the distant point
* @return the angle to the provided coordinates
*/
public float getAngle(float xp, float yp) {
float side = xpos-xp;
float height = ypos-yp;
float distance = getDistance(xp,yp);
float angle = (float)(Math.asin(side/distance)+Math.PI/2);
if (height<0) angle = 2.0f*(float)Math.PI-angle;
return angle;
}
/**
* Returns the angle to the provided TuioPoint
*
* @param tpoint the distant TuioPoint
* @return the angle to the provided TuioPoint
*/
public float getAngle(TuioPoint tpoint) {
return getAngle(tpoint.getX(),tpoint.getY());
}
/**
* Returns the angle in degrees to the provided coordinates
*
* @param xp the X coordinate of the distant point
* @param yp the Y coordinate of the distant point
* @return the angle in degrees to the provided TuioPoint
*/
public float getAngleDegrees(float xp, float yp) {
return (getAngle(xp,yp)/(float)Math.PI)*180.0f;
}
/**
* Returns the angle in degrees to the provided TuioPoint
*
* @param tpoint the distant TuioPoint
* @return the angle in degrees to the provided TuioPoint
*/
public float getAngleDegrees(TuioPoint tpoint) {
return (getAngle(tpoint)/(float)Math.PI)*180.0f;
}
/**
* Returns the X coordinate in pixels relative to the provided screen width.
*
* @param width the screen width
* @return the X coordinate of this TuioPoint in pixels relative to the provided screen width
*/
public int getScreenX(int width) {
return (int)Math.round(xpos*width);
}
/**
* Returns the Y coordinate in pixels relative to the provided screen height.
*
* @param height the screen height
* @return the Y coordinate of this TuioPoint in pixels relative to the provided screen height
*/
public int getScreenY(int height) {
return (int)Math.round(ypos*height);
}
/**
* Returns the time stamp of this TuioPoint as TuioTime.
*
* @return the time stamp of this TuioPoint as TuioTime
*/
public TuioTime getTuioTime() {
return new TuioTime(currentTime);
}
/**
* Returns the start time of this TuioPoint as TuioTime.
*
* @return the start time of this TuioPoint as TuioTime
*/
public TuioTime getStartTime() {
return new TuioTime(startTime);
}
}