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