|
10
|
1 |
/* |
|
|
2 |
TUIO Java backend - part of the reacTIVision project |
|
|
3 |
http://reactivision.sourceforge.net/ |
|
|
4 |
|
|
|
5 |
Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu> |
|
|
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 |
package TUIO; |
|
|
22 |
|
|
|
23 |
import java.util.*; |
|
|
24 |
|
|
|
25 |
/** |
|
|
26 |
* The abstract TuioContainer class defines common attributes that apply to both subclasses {@link TuioObject} and {@link TuioCursor}. |
|
|
27 |
* |
|
|
28 |
* @author Martin Kaltenbrunner |
|
|
29 |
* @version 1.4 |
|
|
30 |
*/ |
|
|
31 |
abstract class TuioContainer extends TuioPoint { |
|
|
32 |
|
|
|
33 |
/** |
|
|
34 |
* The unique session ID number that is assigned to each TUIO object or cursor. |
|
|
35 |
*/ |
|
|
36 |
protected long session_id; |
|
|
37 |
/** |
|
|
38 |
* The X-axis velocity value. |
|
|
39 |
*/ |
|
|
40 |
protected float x_speed; |
|
|
41 |
/** |
|
|
42 |
* The Y-axis velocity value. |
|
|
43 |
*/ |
|
|
44 |
protected float y_speed; |
|
|
45 |
/** |
|
|
46 |
* The motion speed value. |
|
|
47 |
*/ |
|
|
48 |
protected float motion_speed; |
|
|
49 |
/** |
|
|
50 |
* The motion acceleration value. |
|
|
51 |
*/ |
|
|
52 |
protected float motion_accel; |
|
|
53 |
/** |
|
|
54 |
* A Vector of TuioPoints containing all the previous positions of the TUIO component. |
|
|
55 |
*/ |
|
|
56 |
protected Vector<TuioPoint> path; |
|
|
57 |
/** |
|
|
58 |
* Defines the ADDED state. |
|
|
59 |
*/ |
|
|
60 |
public static final int TUIO_ADDED = 0; |
|
|
61 |
/** |
|
|
62 |
* Defines the ACCELERATING state. |
|
|
63 |
*/ |
|
|
64 |
public static final int TUIO_ACCELERATING = 1; |
|
|
65 |
/** |
|
|
66 |
* Defines the DECELERATING state. |
|
|
67 |
*/ |
|
|
68 |
public static final int TUIO_DECELERATING = 2; |
|
|
69 |
/** |
|
|
70 |
* Defines the STOPPED state. |
|
|
71 |
*/ |
|
|
72 |
public static final int TUIO_STOPPED = 3; |
|
|
73 |
/** |
|
|
74 |
* Defines the REMOVED state. |
|
|
75 |
*/ |
|
|
76 |
public static final int TUIO_REMOVED = 4; |
|
|
77 |
/** |
|
|
78 |
* Reflects the current state of the TuioComponent |
|
|
79 |
*/ |
|
|
80 |
protected int state; |
|
|
81 |
|
|
|
82 |
/** |
|
|
83 |
* This constructor takes a TuioTime argument and assigns it along with the provided |
|
|
84 |
* Session ID, X and Y coordinate to the newly created TuioContainer. |
|
|
85 |
* |
|
|
86 |
* @param ttime the TuioTime to assign |
|
|
87 |
* @param si the Session ID to assign |
|
|
88 |
* @param xp the X coordinate to assign |
|
|
89 |
* @param yp the Y coordinate to assign |
|
|
90 |
*/ |
|
|
91 |
TuioContainer(TuioTime ttime, long si, float xp, float yp) { |
|
|
92 |
super(ttime,xp,yp); |
|
|
93 |
|
|
|
94 |
session_id = si; |
|
|
95 |
x_speed = 0.0f; |
|
|
96 |
y_speed = 0.0f; |
|
|
97 |
motion_speed = 0.0f; |
|
|
98 |
motion_accel = 0.0f; |
|
|
99 |
|
|
|
100 |
path = new Vector<TuioPoint>(); |
|
|
101 |
path.addElement(new TuioPoint(currentTime,xpos,ypos)); |
|
|
102 |
state = TUIO_ADDED; |
|
|
103 |
} |
|
|
104 |
|
|
|
105 |
/** |
|
|
106 |
* This constructor takes a TuioTime argument and assigns it along with the provided |
|
|
107 |
* Session ID, X, Y and Z coordinate to the newly created TuioContainer. |
|
|
108 |
* |
|
|
109 |
* @param ttime the TuioTime to assign |
|
|
110 |
* @param si the Session ID to assign |
|
|
111 |
* @param xp the X coordinate to assign |
|
|
112 |
* @param yp the Y coordinate to assign |
|
|
113 |
* @param zp the Z coordinate to assign |
|
|
114 |
*/ |
|
|
115 |
TuioContainer(TuioTime ttime, long si, float xp, float yp, float zp) { |
|
|
116 |
super(ttime,xp,yp, zp); |
|
|
117 |
|
|
|
118 |
session_id = si; |
|
|
119 |
x_speed = 0.0f; |
|
|
120 |
y_speed = 0.0f; |
|
|
121 |
motion_speed = 0.0f; |
|
|
122 |
motion_accel = 0.0f; |
|
|
123 |
|
|
|
124 |
path = new Vector<TuioPoint>(); |
|
|
125 |
path.addElement(new TuioPoint(currentTime,xpos,ypos,zpos)); |
|
|
126 |
state = TUIO_ADDED; |
|
|
127 |
} |
|
|
128 |
|
|
|
129 |
/** |
|
|
130 |
* This constructor takes the provided Session ID, X and Y coordinate |
|
|
131 |
* and assigs these values to the newly created TuioContainer. |
|
|
132 |
* |
|
|
133 |
* @param si the Session ID to assign |
|
|
134 |
* @param xp the X coordinate to assign |
|
|
135 |
* @param yp the Y coordinate to assign |
|
|
136 |
*/ |
|
|
137 |
TuioContainer(long si, float xp, float yp) { |
|
|
138 |
super(xp,yp); |
|
|
139 |
|
|
|
140 |
session_id = si; |
|
|
141 |
x_speed = 0.0f; |
|
|
142 |
y_speed = 0.0f; |
|
|
143 |
motion_speed = 0.0f; |
|
|
144 |
motion_accel = 0.0f; |
|
|
145 |
|
|
|
146 |
path = new Vector<TuioPoint>(); |
|
|
147 |
path.addElement(new TuioPoint(currentTime,xpos,ypos)); |
|
|
148 |
state = TUIO_ADDED; |
|
|
149 |
} |
|
|
150 |
|
|
|
151 |
/** |
|
|
152 |
* This constructor takes the provided Session ID, X, Y and Z coordinate |
|
|
153 |
* and assigs these values to the newly created TuioContainer. |
|
|
154 |
* |
|
|
155 |
* @param si the Session ID to assign |
|
|
156 |
* @param xp the X coordinate to assign |
|
|
157 |
* @param yp the Y coordinate to assign |
|
|
158 |
* @param zp the Z coordinate to assign |
|
|
159 |
*/ |
|
|
160 |
TuioContainer(long si, float xp, float yp, float zp) { |
|
|
161 |
super(xp,yp,zp); |
|
|
162 |
|
|
|
163 |
session_id = si; |
|
|
164 |
x_speed = 0.0f; |
|
|
165 |
y_speed = 0.0f; |
|
|
166 |
motion_speed = 0.0f; |
|
|
167 |
motion_accel = 0.0f; |
|
|
168 |
|
|
|
169 |
path = new Vector<TuioPoint>(); |
|
|
170 |
path.addElement(new TuioPoint(currentTime,xpos,ypos,zpos)); |
|
|
171 |
state = TUIO_ADDED; |
|
|
172 |
} |
|
|
173 |
|
|
|
174 |
/** |
|
|
175 |
* This constructor takes the atttibutes of the provided TuioContainer |
|
|
176 |
* and assigs these values to the newly created TuioContainer. |
|
|
177 |
* |
|
|
178 |
* @param tcon the TuioContainer to assign |
|
|
179 |
*/ |
|
|
180 |
TuioContainer(TuioContainer tcon) { |
|
|
181 |
super(tcon); |
|
|
182 |
|
|
|
183 |
session_id = tcon.getSessionID(); |
|
|
184 |
x_speed = 0.0f; |
|
|
185 |
y_speed = 0.0f; |
|
|
186 |
motion_speed = 0.0f; |
|
|
187 |
motion_accel = 0.0f; |
|
|
188 |
|
|
|
189 |
path = new Vector<TuioPoint>(); |
|
|
190 |
path.addElement(new TuioPoint(currentTime,xpos,ypos,zpos)); |
|
|
191 |
state = TUIO_ADDED; |
|
|
192 |
} |
|
|
193 |
|
|
|
194 |
/** |
|
|
195 |
* Takes a TuioTime argument and assigns it along with the provided |
|
|
196 |
* X and Y coordinate to the private TuioContainer attributes. |
|
|
197 |
* The speed and accleration values are calculated accordingly. |
|
|
198 |
* |
|
|
199 |
* @param ttime the TuioTime to assign |
|
|
200 |
* @param xp the X coordinate to assign |
|
|
201 |
* @param yp the Y coordinate to assign |
|
|
202 |
*/ |
|
|
203 |
public void update(TuioTime ttime, float xp, float yp) { |
|
|
204 |
TuioPoint lastPoint = path.lastElement(); |
|
|
205 |
super.update(ttime,xp,yp); |
|
|
206 |
|
|
|
207 |
TuioTime diffTime = currentTime.subtract(lastPoint.getTuioTime()); |
|
|
208 |
float dt = diffTime.getTotalMilliseconds()/1000.0f; |
|
|
209 |
float dx = this.xpos - lastPoint.getX(); |
|
|
210 |
float dy = this.ypos - lastPoint.getY(); |
|
|
211 |
float dist = (float)Math.sqrt(dx*dx+dy*dy); |
|
|
212 |
float last_motion_speed = this.motion_speed; |
|
|
213 |
|
|
|
214 |
this.x_speed = dx/dt; |
|
|
215 |
this.y_speed = dy/dt; |
|
|
216 |
this.motion_speed = dist/dt; |
|
|
217 |
this.motion_accel = (motion_speed - last_motion_speed)/dt; |
|
|
218 |
|
|
|
219 |
path.addElement(new TuioPoint(currentTime,xpos,ypos)); |
|
|
220 |
if (motion_accel>0) state = TUIO_ACCELERATING; |
|
|
221 |
else if (motion_accel<0) state = TUIO_DECELERATING; |
|
|
222 |
else state = TUIO_STOPPED; |
|
|
223 |
} |
|
|
224 |
|
|
|
225 |
/** |
|
|
226 |
* Takes a TuioTime argument and assigns it along with the provided |
|
|
227 |
* X, Y and Z coordinate to the private TuioContainer attributes. |
|
|
228 |
* The speed and accleration values are calculated accordingly. |
|
|
229 |
* |
|
|
230 |
* @param ttime the TuioTime to assign |
|
|
231 |
* @param xp the X coordinate to assign |
|
|
232 |
* @param yp the Y coordinate to assign |
|
|
233 |
* @param zp the Z coordinate to assign |
|
|
234 |
*/ |
|
|
235 |
public void update(TuioTime ttime, float xp, float yp, float zp) { |
|
|
236 |
TuioPoint lastPoint = path.lastElement(); |
|
|
237 |
super.update(ttime,xp,yp,zp); |
|
|
238 |
|
|
|
239 |
TuioTime diffTime = currentTime.subtract(lastPoint.getTuioTime()); |
|
|
240 |
float dt = diffTime.getTotalMilliseconds()/1000.0f; |
|
|
241 |
float dx = this.xpos - lastPoint.getX(); |
|
|
242 |
float dy = this.ypos - lastPoint.getY(); |
|
|
243 |
float dz = this.zpos - lastPoint.getZ(); |
|
|
244 |
float dist = (float)Math.sqrt(dx*dx+dy*dy+dz*dz); |
|
|
245 |
float last_motion_speed = this.motion_speed; |
|
|
246 |
|
|
|
247 |
this.x_speed = dx/dt; |
|
|
248 |
this.y_speed = dy/dt; |
|
|
249 |
this.motion_speed = dist/dt; |
|
|
250 |
this.motion_accel = (motion_speed - last_motion_speed)/dt; |
|
|
251 |
|
|
|
252 |
path.addElement(new TuioPoint(currentTime,xpos,ypos,zpos)); |
|
|
253 |
if (motion_accel>0) state = TUIO_ACCELERATING; |
|
|
254 |
else if (motion_accel<0) state = TUIO_DECELERATING; |
|
|
255 |
else state = TUIO_STOPPED; |
|
|
256 |
} |
|
|
257 |
|
|
|
258 |
/** |
|
|
259 |
* This method is used to calculate the speed and acceleration values of |
|
|
260 |
* TuioContainers with unchanged positions. |
|
|
261 |
*/ |
|
|
262 |
public void stop(TuioTime ttime) { |
|
|
263 |
update(ttime,xpos,ypos,zpos); |
|
|
264 |
} |
|
|
265 |
|
|
|
266 |
/** |
|
|
267 |
* Takes a TuioTime argument and assigns it along with the provided |
|
|
268 |
* X and Y coordinate, X and Y velocity and acceleration |
|
|
269 |
* to the private TuioContainer attributes. |
|
|
270 |
* |
|
|
271 |
* @param ttime the TuioTime to assign |
|
|
272 |
* @param xp the X coordinate to assign |
|
|
273 |
* @param yp the Y coordinate to assign |
|
|
274 |
* @param xs the X velocity to assign |
|
|
275 |
* @param ys the Y velocity to assign |
|
|
276 |
* @param ma the acceleration to assign |
|
|
277 |
*/ |
|
|
278 |
public void update(TuioTime ttime, float xp, float yp , float xs, float ys, float ma) { |
|
|
279 |
super.update(ttime,xp,yp); |
|
|
280 |
x_speed = xs; |
|
|
281 |
y_speed = ys; |
|
|
282 |
motion_speed = (float)Math.sqrt(x_speed*x_speed+y_speed*y_speed); |
|
|
283 |
motion_accel = ma; |
|
|
284 |
path.addElement(new TuioPoint(currentTime,xpos,ypos)); |
|
|
285 |
if (motion_accel>0) state = TUIO_ACCELERATING; |
|
|
286 |
else if (motion_accel<0) state = TUIO_DECELERATING; |
|
|
287 |
else state = TUIO_STOPPED; |
|
|
288 |
} |
|
|
289 |
|
|
|
290 |
/** |
|
|
291 |
* Takes a TuioTime argument and assigns it along with the provided |
|
|
292 |
* X, Y and Z coordinate, X and Y velocity and acceleration |
|
|
293 |
* to the private TuioContainer attributes. |
|
|
294 |
* |
|
|
295 |
* @param ttime the TuioTime to assign |
|
|
296 |
* @param xp the X coordinate to assign |
|
|
297 |
* @param yp the Y coordinate to assign |
|
|
298 |
* @param zp the Z coordinate to assign |
|
|
299 |
* @param xs the X velocity to assign |
|
|
300 |
* @param ys the Y velocity to assign |
|
|
301 |
* @param ma the acceleration to assign |
|
|
302 |
*/ |
|
|
303 |
public void update(TuioTime ttime, float xp, float yp, float zp , float xs, float ys, float ma) { |
|
|
304 |
super.update(ttime,xp,yp,zp); |
|
|
305 |
x_speed = xs; |
|
|
306 |
y_speed = ys; |
|
|
307 |
motion_speed = (float)Math.sqrt(x_speed*x_speed+y_speed*y_speed); |
|
|
308 |
motion_accel = ma; |
|
|
309 |
path.addElement(new TuioPoint(currentTime,xpos,ypos,zpos)); |
|
|
310 |
if (motion_accel>0) state = TUIO_ACCELERATING; |
|
|
311 |
else if (motion_accel<0) state = TUIO_DECELERATING; |
|
|
312 |
else state = TUIO_STOPPED; |
|
|
313 |
} |
|
|
314 |
|
|
|
315 |
/** |
|
|
316 |
* Assigns the provided X and Y coordinate, X and Y velocity and acceleration |
|
|
317 |
* to the private TuioContainer attributes. The TuioTime time stamp remains unchanged. |
|
|
318 |
* |
|
|
319 |
* @param xp the X coordinate to assign |
|
|
320 |
* @param yp the Y coordinate to assign |
|
|
321 |
* @param xs the X velocity to assign |
|
|
322 |
* @param ys the Y velocity to assign |
|
|
323 |
* @param ma the acceleration to assign |
|
|
324 |
*/ |
|
|
325 |
public void update(float xp, float yp,float xs,float ys,float ma) { |
|
|
326 |
super.update(xp,yp); |
|
|
327 |
x_speed = xs; |
|
|
328 |
y_speed = ys; |
|
|
329 |
motion_speed = (float)Math.sqrt(x_speed*x_speed+y_speed*y_speed); |
|
|
330 |
motion_accel = ma; |
|
|
331 |
path.addElement(new TuioPoint(currentTime,xpos,ypos)); |
|
|
332 |
if (motion_accel>0) state = TUIO_ACCELERATING; |
|
|
333 |
else if (motion_accel<0) state = TUIO_DECELERATING; |
|
|
334 |
else state = TUIO_STOPPED; |
|
|
335 |
} |
|
|
336 |
|
|
|
337 |
/** |
|
|
338 |
* Assigns the provided X, Y and Z coordinate, X and Y velocity and acceleration |
|
|
339 |
* to the private TuioContainer attributes. The TuioTime time stamp remains unchanged. |
|
|
340 |
* |
|
|
341 |
* @param xp the X coordinate to assign |
|
|
342 |
* @param yp the Y coordinate to assign |
|
|
343 |
* @param zp the Z coordinate to assign |
|
|
344 |
* @param xs the X velocity to assign |
|
|
345 |
* @param ys the Y velocity to assign |
|
|
346 |
* @param ma the acceleration to assign |
|
|
347 |
*/ |
|
|
348 |
public void update(float xp, float yp, float zp,float xs,float ys,float ma) { |
|
|
349 |
super.update(xp,yp,zp); |
|
|
350 |
x_speed = xs; |
|
|
351 |
y_speed = ys; |
|
|
352 |
motion_speed = (float)Math.sqrt(x_speed*x_speed+y_speed*y_speed); |
|
|
353 |
motion_accel = ma; |
|
|
354 |
path.addElement(new TuioPoint(currentTime,xpos,ypos,zpos)); |
|
|
355 |
if (motion_accel>0) state = TUIO_ACCELERATING; |
|
|
356 |
else if (motion_accel<0) state = TUIO_DECELERATING; |
|
|
357 |
else state = TUIO_STOPPED; |
|
|
358 |
} |
|
|
359 |
|
|
|
360 |
/** |
|
|
361 |
* Takes the atttibutes of the provided TuioContainer |
|
|
362 |
* and assigs these values to this TuioContainer. |
|
|
363 |
* The TuioTime time stamp of this TuioContainer remains unchanged. |
|
|
364 |
* |
|
|
365 |
* @param tcon the TuioContainer to assign |
|
|
366 |
*/ |
|
|
367 |
public void update (TuioContainer tcon) { |
|
|
368 |
super.update(tcon); |
|
|
369 |
x_speed = tcon.getXSpeed(); |
|
|
370 |
y_speed = tcon.getYSpeed(); |
|
|
371 |
motion_speed = tcon.getMotionSpeed(); |
|
|
372 |
motion_accel = tcon.getMotionAccel(); |
|
|
373 |
path.addElement(new TuioPoint(currentTime,xpos,ypos,zpos)); |
|
|
374 |
if (motion_accel>0) state = TUIO_ACCELERATING; |
|
|
375 |
else if (motion_accel<0) state = TUIO_DECELERATING; |
|
|
376 |
else state = TUIO_STOPPED; |
|
|
377 |
} |
|
|
378 |
|
|
|
379 |
/** |
|
|
380 |
* Assigns the REMOVE state to this TuioContainer and sets |
|
|
381 |
* its TuioTime time stamp to the provided TuioTime argument. |
|
|
382 |
* |
|
|
383 |
* @param ttime the TuioTime to assign |
|
|
384 |
*/ |
|
|
385 |
public void remove(TuioTime ttime) { |
|
|
386 |
currentTime = new TuioTime(ttime); |
|
|
387 |
state = TUIO_REMOVED; |
|
|
388 |
} |
|
|
389 |
|
|
|
390 |
/** |
|
|
391 |
* Returns the Session ID of this TuioContainer. |
|
|
392 |
* @return the Session ID of this TuioContainer |
|
|
393 |
*/ |
|
|
394 |
public long getSessionID() { |
|
|
395 |
return session_id; |
|
|
396 |
} |
|
|
397 |
|
|
|
398 |
/** |
|
|
399 |
* Returns the X velocity of this TuioContainer. |
|
|
400 |
* @return the X velocity of this TuioContainer |
|
|
401 |
*/ |
|
|
402 |
public float getXSpeed() { |
|
|
403 |
return x_speed; |
|
|
404 |
} |
|
|
405 |
|
|
|
406 |
/** |
|
|
407 |
* Returns the Y velocity of this TuioContainer. |
|
|
408 |
* @return the Y velocity of this TuioContainer |
|
|
409 |
*/ |
|
|
410 |
public float getYSpeed() { |
|
|
411 |
return y_speed; |
|
|
412 |
} |
|
|
413 |
|
|
|
414 |
/** |
|
|
415 |
* Returns the position of this TuioContainer. |
|
|
416 |
* @return the position of this TuioContainer |
|
|
417 |
*/ |
|
|
418 |
public TuioPoint getPosition() { |
|
|
419 |
return new TuioPoint(xpos,ypos,zpos); |
|
|
420 |
} |
|
|
421 |
|
|
|
422 |
/** |
|
|
423 |
* Returns the path of this TuioContainer. |
|
|
424 |
* @return the path of this TuioContainer |
|
|
425 |
*/ |
|
|
426 |
public Vector<TuioPoint> getPath() { |
|
|
427 |
return path; |
|
|
428 |
} |
|
|
429 |
|
|
|
430 |
/** |
|
|
431 |
* Returns the motion speed of this TuioContainer. |
|
|
432 |
* @return the motion speed of this TuioContainer |
|
|
433 |
*/ |
|
|
434 |
public float getMotionSpeed() { |
|
|
435 |
return motion_speed; |
|
|
436 |
} |
|
|
437 |
|
|
|
438 |
/** |
|
|
439 |
* Returns the motion acceleration of this TuioContainer. |
|
|
440 |
* @return the motion acceleration of this TuioContainer |
|
|
441 |
*/ |
|
|
442 |
public float getMotionAccel() { |
|
|
443 |
return motion_accel; |
|
|
444 |
} |
|
|
445 |
|
|
|
446 |
/** |
|
|
447 |
* Returns the TUIO state of this TuioContainer. |
|
|
448 |
* @return the TUIO state of this TuioContainer |
|
|
449 |
*/ |
|
|
450 |
public int getTuioState() { |
|
|
451 |
return state; |
|
|
452 |
} |
|
|
453 |
|
|
|
454 |
/** |
|
|
455 |
* Returns true of this TuioContainer is moving. |
|
|
456 |
* @return true of this TuioContainer is moving |
|
|
457 |
*/ |
|
|
458 |
public boolean isMoving() { |
|
|
459 |
if ((state==TUIO_ACCELERATING) || (state==TUIO_DECELERATING)) return true; |
|
|
460 |
else return false; |
|
|
461 |
} |
|
|
462 |
|
|
|
463 |
} |