27 * |
27 * |
28 * @author Martin Kaltenbrunner |
28 * @author Martin Kaltenbrunner |
29 * @version 1.4 |
29 * @version 1.4 |
30 */ |
30 */ |
31 public class TuioPoint { |
31 public class TuioPoint { |
32 |
32 |
33 public String comm; |
33 public String comm; |
34 |
34 |
35 /** |
35 /** |
36 * X coordinate, representated as a floating point value in a range of 0..1 |
36 * X coordinate, representated as a floating point value in a range of 0..1 |
37 */ |
37 */ |
38 protected float xpos; |
38 protected float xpos; |
39 /** |
39 /** |
40 * Y coordinate, representated as a floating point value in a range of 0..1 |
40 * Y coordinate, representated as a floating point value in a range of 0..1 |
41 */ |
41 */ |
42 protected float ypos; |
42 protected float ypos; |
43 /** |
43 /** |
44 * Z coordinate, representated as a floating point value in a range of 0..1 |
44 * Z coordinate, representated as a floating point value in a range of 0..1 |
45 */ |
45 */ |
46 protected float zpos; |
46 protected float zpos; |
47 /** |
47 /** |
48 * The time stamp of the last update represented as TuioTime (time since session start) |
48 * The time stamp of the last update represented as TuioTime (time since session start) |
49 */ |
49 */ |
50 protected TuioTime currentTime; |
50 protected TuioTime currentTime; |
51 /** |
51 /** |
52 * The creation time of this TuioPoint represented as TuioTime (time since session start) |
52 * The creation time of this TuioPoint represented as TuioTime (time since session start) |
53 */ |
53 */ |
54 protected TuioTime startTime; |
54 protected TuioTime startTime; |
55 |
55 |
56 /** |
56 /** |
57 * The default constructor takes no arguments and sets |
57 * The default constructor takes no arguments and sets |
58 * its coordinate attributes to zero and its time stamp to the current session time. |
58 * its coordinate attributes to zero and its time stamp to the current session time. |
59 */ |
59 */ |
60 public TuioPoint() { |
60 public TuioPoint() { |
61 xpos = 0.0f; |
61 xpos = 0.0f; |
62 ypos = 0.0f; |
62 ypos = 0.0f; |
63 zpos = 0.0f; |
63 zpos = 0.0f; |
64 currentTime = TuioTime.getSessionTime(); |
64 currentTime = TuioTime.getSessionTime(); |
65 startTime = new TuioTime(currentTime); |
65 startTime = new TuioTime(currentTime); |
66 } |
66 } |
67 |
67 |
68 /** |
68 /** |
69 * This constructor takes two floating point coordinate arguments and sets |
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. |
70 * its coordinate attributes to these values and its time stamp to the current session time. |
71 * |
71 * |
72 * @param xp the X coordinate to assign |
72 * @param xp the X coordinate to assign |
73 * @param yp the Y coordinate to assign |
73 * @param yp the Y coordinate to assign |
74 */ |
74 */ |
75 public TuioPoint(float xp, float yp) { |
75 public TuioPoint(float xp, float yp) { |
76 xpos = xp; |
76 xpos = xp; |
77 ypos = yp; |
77 ypos = yp; |
78 zpos = 0.0f; |
78 zpos = 0.0f; |
79 currentTime = TuioTime.getSessionTime(); |
79 currentTime = TuioTime.getSessionTime(); |
80 startTime = new TuioTime(currentTime); |
80 startTime = new TuioTime(currentTime); |
81 } |
81 } |
82 |
82 |
83 /** |
83 /** |
84 * This constructor takes three floating point coordinate arguments and sets |
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. |
85 * its coordinate attributes to these values and its time stamp to the current session time. |
86 * |
86 * |
87 * @param xp the X coordinate to assign |
87 * @param xp the X coordinate to assign |
88 * @param yp the Y coordinate to assign |
88 * @param yp the Y coordinate to assign |
89 * @param zp the Z coordinate to assign |
89 * @param zp the Z coordinate to assign |
90 */ |
90 */ |
91 public TuioPoint(float xp, float yp, float zp) { |
91 public TuioPoint(float xp, float yp, float zp) { |
92 xpos = xp; |
92 xpos = xp; |
93 ypos = yp; |
93 ypos = yp; |
94 zpos = zp; |
94 zpos = zp; |
95 currentTime = TuioTime.getSessionTime(); |
95 currentTime = TuioTime.getSessionTime(); |
96 startTime = new TuioTime(currentTime); |
96 startTime = new TuioTime(currentTime); |
97 } |
97 } |
98 |
98 |
99 /** |
99 /** |
100 * This constructor takes a TuioPoint argument and sets its coordinate attributes |
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. |
101 * to the coordinates of the provided TuioPoint and its time stamp to the current session time. |
102 * |
102 * |
103 * @param tpoint the TuioPoint to assign |
103 * @param tpoint the TuioPoint to assign |
104 */ |
104 */ |
105 public TuioPoint(TuioPoint tpoint) { |
105 public TuioPoint(TuioPoint tpoint) { |
106 xpos = tpoint.getX(); |
106 xpos = tpoint.getX(); |
107 ypos = tpoint.getY(); |
107 ypos = tpoint.getY(); |
108 zpos = tpoint.getZ(); |
108 zpos = tpoint.getZ(); |
109 currentTime = TuioTime.getSessionTime(); |
109 currentTime = TuioTime.getSessionTime(); |
110 startTime = new TuioTime(currentTime); |
110 startTime = new TuioTime(currentTime); |
111 } |
111 } |
112 |
112 |
113 /** |
113 /** |
114 * This constructor takes a TuioTime object and two floating point coordinate arguments and sets |
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. |
115 * its coordinate attributes to these values and its time stamp to the provided TUIO time object. |
116 * |
116 * |
117 * @param ttime the TuioTime to assign |
117 * @param ttime the TuioTime to assign |
118 * @param xp the X coordinate to assign |
118 * @param xp the X coordinate to assign |
119 * @param yp the Y coordinate to assign |
119 * @param yp the Y coordinate to assign |
120 */ |
120 */ |
121 public TuioPoint(TuioTime ttime, float xp, float yp) { |
121 public TuioPoint(TuioTime ttime, float xp, float yp) { |
122 xpos = xp; |
122 xpos = xp; |
123 ypos = yp; |
123 ypos = yp; |
124 zpos = 0.0f; |
124 zpos = 0.0f; |
125 currentTime = new TuioTime(ttime); |
125 currentTime = new TuioTime(ttime); |
126 startTime = new TuioTime(currentTime); |
126 startTime = new TuioTime(currentTime); |
127 } |
127 } |
128 |
128 |
129 /** |
129 /** |
130 * This constructor takes a TuioTime object and three floating point coordinate arguments and sets |
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. |
131 * its coordinate attributes to these values and its time stamp to the provided TUIO time object. |
132 * |
132 * |
133 * @param ttime the TuioTime to assign |
133 * @param ttime the TuioTime to assign |
134 * @param xp the X coordinate to assign |
134 * @param xp the X coordinate to assign |
135 * @param yp the Y coordinate to assign |
135 * @param yp the Y coordinate to assign |
136 * @param zp the Z coordinate to assign |
136 * @param zp the Z coordinate to assign |
137 */ |
137 */ |
138 public TuioPoint(TuioTime ttime, float xp, float yp, float zp) { |
138 public TuioPoint(TuioTime ttime, float xp, float yp, float zp) { |
139 xpos = xp; |
139 xpos = xp; |
140 ypos = yp; |
140 ypos = yp; |
141 zpos = zp; |
141 zpos = zp; |
142 currentTime = new TuioTime(ttime); |
142 currentTime = new TuioTime(ttime); |
143 startTime = new TuioTime(currentTime); |
143 startTime = new TuioTime(currentTime); |
144 } |
144 } |
145 |
145 |
146 /** |
146 /** |
147 * Takes a TuioPoint argument and updates its coordinate attributes |
147 * Takes a TuioPoint argument and updates its coordinate attributes |
148 * to the coordinates of the provided TuioPoint and leaves its time stamp unchanged. |
148 * to the coordinates of the provided TuioPoint and leaves its time stamp unchanged. |
149 * |
149 * |
150 * @param tpoint the TuioPoint to assign |
150 * @param tpoint the TuioPoint to assign |
151 */ |
151 */ |
152 public void update(TuioPoint tpoint) { |
152 public void update(TuioPoint tpoint) { |
153 xpos = tpoint.getX(); |
153 xpos = tpoint.getX(); |
154 ypos = tpoint.getY(); |
154 ypos = tpoint.getY(); |
155 zpos = tpoint.getZ(); |
155 zpos = tpoint.getZ(); |
156 } |
156 } |
157 |
157 |
158 /** |
158 /** |
159 * Takes two floating point coordinate arguments and updates its coordinate attributes |
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. |
160 * to the coordinates of the provided TuioPoint and leaves its time stamp unchanged. |
161 * |
161 * |
162 * @param xp the X coordinate to assign |
162 * @param xp the X coordinate to assign |
163 * @param yp the Y coordinate to assign |
163 * @param yp the Y coordinate to assign |
164 */ |
164 */ |
165 public void update(float xp, float yp) { |
165 public void update(float xp, float yp) { |
166 xpos = xp; |
166 xpos = xp; |
167 ypos = yp; |
167 ypos = yp; |
168 } |
168 } |
169 |
169 |
170 /** |
170 /** |
171 * Takes three floating point coordinate arguments and updates its coordinate attributes |
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. |
172 * to the coordinates of the provided TuioPoint and leaves its time stamp unchanged. |
173 * |
173 * |
174 * @param xp the X coordinate to assign |
174 * @param xp the X coordinate to assign |
175 * @param yp the Y coordinate to assign |
175 * @param yp the Y coordinate to assign |
176 * @param zp the Z coordinate to assign |
176 * @param zp the Z coordinate to assign |
177 */ |
177 */ |
178 public void update(float xp, float yp, float zp) { |
178 public void update(float xp, float yp, float zp) { |
179 xpos = xp; |
179 xpos = xp; |
180 ypos = yp; |
180 ypos = yp; |
181 zpos = zp; |
181 zpos = zp; |
182 } |
182 } |
183 |
183 |
184 /** |
184 /** |
185 * Takes a TuioTime object and two floating point coordinate arguments and updates its coordinate attributes |
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. |
186 * to the coordinates of the provided TuioPoint and its time stamp to the provided TUIO time object. |
187 * |
187 * |
188 * @param ttime the TuioTime to assign |
188 * @param ttime the TuioTime to assign |
189 * @param xp the X coordinate to assign |
189 * @param xp the X coordinate to assign |
190 * @param yp the Y coordinate to assign |
190 * @param yp the Y coordinate to assign |
191 */ |
191 */ |
192 public void update(TuioTime ttime, float xp, float yp) { |
192 public void update(TuioTime ttime, float xp, float yp) { |
193 xpos = xp; |
193 xpos = xp; |
194 ypos = yp; |
194 ypos = yp; |
195 currentTime = new TuioTime(ttime); |
195 currentTime = new TuioTime(ttime); |
196 } |
196 } |
197 |
197 |
198 /** |
198 /** |
199 * Takes a TuioTime object and three floating point coordinate arguments and updates its coordinate attributes |
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. |
200 * to the coordinates of the provided TuioPoint and its time stamp to the provided TUIO time object. |
201 * |
201 * |
202 * @param ttime the TuioTime to assign |
202 * @param ttime the TuioTime to assign |
203 * @param xp the X coordinate to assign |
203 * @param xp the X coordinate to assign |
204 * @param yp the Y coordinate to assign |
204 * @param yp the Y coordinate to assign |
205 * @param zp the Z coordinate to assign |
205 * @param zp the Z coordinate to assign |
206 */ |
206 */ |
207 public void update(TuioTime ttime, float xp, float yp, float zp) { |
207 public void update(TuioTime ttime, float xp, float yp, float zp) { |
208 xpos = xp; |
208 xpos = xp; |
209 ypos = yp; |
209 ypos = yp; |
210 zpos = zp; |
210 zpos = zp; |
211 currentTime = new TuioTime(ttime); |
211 currentTime = new TuioTime(ttime); |
212 } |
212 } |
213 |
213 |
214 /** |
214 /** |
215 * Returns the X coordinate of this TuioPoint. |
215 * Returns the X coordinate of this TuioPoint. |
216 * @return the X coordinate of this TuioPoint |
216 * @return the X coordinate of this TuioPoint |
217 */ |
217 */ |
218 public float getX() { |
218 public float getX() { |
219 return xpos; |
219 return xpos; |
220 } |
220 } |
221 |
221 |
222 /** |
222 /** |
223 * Returns the Y coordinate of this TuioPoint. |
223 * Returns the Y coordinate of this TuioPoint. |
224 * @return the Y coordinate of this TuioPoint |
224 * @return the Y coordinate of this TuioPoint |
225 */ |
225 */ |
226 public float getY() { |
226 public float getY() { |
227 return ypos; |
227 return ypos; |
228 } |
228 } |
229 |
229 |
230 /** |
230 /** |
231 * Returns the Z coordinate of this TuioPoint. |
231 * Returns the Z coordinate of this TuioPoint. |
232 * @return the Z coordinate of this TuioPoint |
232 * @return the Z coordinate of this TuioPoint |
233 */ |
233 */ |
234 public float getZ() { |
234 public float getZ() { |
235 return zpos; |
235 return zpos; |
236 } |
236 } |
237 |
237 |
238 /** |
238 /** |
239 * Returns the distance to the provided coordinates |
239 * Returns the distance to the provided coordinates |
240 * |
240 * |
241 * @param xp the X coordinate of the distant point |
241 * @param xp the X coordinate of the distant point |
242 * @param yp the Y coordinate of the distant point |
242 * @param yp the Y coordinate of the distant point |
243 * @return the distance to the provided coordinates |
243 * @return the distance to the provided coordinates |
244 */ |
244 */ |
245 public float getDistance(float xp, float yp) { |
245 public float getDistance(float xp, float yp) { |
246 float dx = xpos-xp; |
246 float dx = xpos-xp; |
247 float dy = ypos-yp; |
247 float dy = ypos-yp; |
248 return (float)Math.sqrt(dx*dx+dy*dy); |
248 return (float)Math.sqrt(dx*dx+dy*dy); |
249 } |
249 } |
250 |
250 |
251 /** |
251 /** |
252 * Returns the distance to the provided coordinates |
252 * Returns the distance to the provided coordinates |
253 * |
253 * |
254 * @param xp the X coordinate of the distant point |
254 * @param xp the X coordinate of the distant point |
255 * @param yp the Y 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 |
256 * @param zp the Y coordinate of the distant point |
257 * @return the distance to the provided coordinates |
257 * @return the distance to the provided coordinates |
258 */ |
258 */ |
259 public float getDistance(float xp, float yp, float zp) { |
259 public float getDistance(float xp, float yp, float zp) { |
260 float dx = xpos-xp; |
260 float dx = xpos-xp; |
261 float dy = ypos-yp; |
261 float dy = ypos-yp; |
262 float dz = zpos-zp; |
262 float dz = zpos-zp; |
263 return (float)Math.sqrt(dx*dx+dy*dy+dz*dz); |
263 return (float)Math.sqrt(dx*dx+dy*dy+dz*dz); |
264 } |
264 } |
265 |
265 |
266 /** |
266 /** |
267 * Returns the distance to the provided TuioPoint |
267 * Returns the distance to the provided TuioPoint |
268 * |
268 * |
269 * @param tpoint the distant TuioPoint |
269 * @param tpoint the distant TuioPoint |
270 * @return the distance to the provided TuioPoint |
270 * @return the distance to the provided TuioPoint |
271 */ |
271 */ |
272 public float getDistance(TuioPoint tpoint) { |
272 public float getDistance(TuioPoint tpoint) { |
273 return getDistance(tpoint.getX(),tpoint.getY(), tpoint.getZ()); |
273 return getDistance(tpoint.getX(),tpoint.getY(), tpoint.getZ()); |
274 } |
274 } |
275 |
275 |
276 /** |
276 /** |
277 * Returns the angle to the provided coordinates |
277 * Returns the angle to the provided coordinates |
278 * |
278 * |
279 * @param xp the X coordinate of the distant point |
279 * @param xp the X coordinate of the distant point |
280 * @param yp the Y coordinate of the distant point |
280 * @param yp the Y coordinate of the distant point |
281 * @return the angle to the provided coordinates |
281 * @return the angle to the provided coordinates |
282 */ |
282 */ |
283 public float getAngle(float xp, float yp) { |
283 public float getAngle(float xp, float yp) { |
284 |
284 |
285 float side = xpos-xp; |
285 float side = xpos-xp; |
286 float height = ypos-yp; |
286 float height = ypos-yp; |
287 float distance = getDistance(xp,yp); |
287 float distance = getDistance(xp,yp); |
288 |
288 |
289 float angle = (float)(Math.asin(side/distance)+Math.PI/2); |
289 float angle = (float)(Math.asin(side/distance)+Math.PI/2); |
290 if (height<0) angle = 2.0f*(float)Math.PI-angle; |
290 if (height<0) angle = 2.0f*(float)Math.PI-angle; |
291 |
291 |
292 return angle; |
292 return angle; |
293 } |
293 } |
294 |
294 |
295 /** |
295 /** |
296 * Returns the angle to the provided TuioPoint |
296 * Returns the angle to the provided TuioPoint |
297 * |
297 * |
298 * @param tpoint the distant TuioPoint |
298 * @param tpoint the distant TuioPoint |
299 * @return the angle to the provided TuioPoint |
299 * @return the angle to the provided TuioPoint |
300 */ |
300 */ |
301 public float getAngle(TuioPoint tpoint) { |
301 public float getAngle(TuioPoint tpoint) { |
302 return getAngle(tpoint.getX(),tpoint.getY()); |
302 return getAngle(tpoint.getX(),tpoint.getY()); |
303 } |
303 } |
304 |
304 |
305 /** |
305 /** |
306 * Returns the angle in degrees to the provided coordinates |
306 * Returns the angle in degrees to the provided coordinates |
307 * |
307 * |
308 * @param xp the X coordinate of the distant point |
308 * @param xp the X coordinate of the distant point |
309 * @param yp the Y 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 |
310 * @return the angle in degrees to the provided TuioPoint |
311 */ |
311 */ |
312 public float getAngleDegrees(float xp, float yp) { |
312 public float getAngleDegrees(float xp, float yp) { |
313 return (getAngle(xp,yp)/(float)Math.PI)*180.0f; |
313 return (getAngle(xp,yp)/(float)Math.PI)*180.0f; |
314 } |
314 } |
315 |
315 |
316 /** |
316 /** |
317 * Returns the angle in degrees to the provided TuioPoint |
317 * Returns the angle in degrees to the provided TuioPoint |
318 * |
318 * |
319 * @param tpoint the distant TuioPoint |
319 * @param tpoint the distant TuioPoint |
320 * @return the angle in degrees to the provided TuioPoint |
320 * @return the angle in degrees to the provided TuioPoint |
321 */ |
321 */ |
322 public float getAngleDegrees(TuioPoint tpoint) { |
322 public float getAngleDegrees(TuioPoint tpoint) { |
323 return (getAngle(tpoint)/(float)Math.PI)*180.0f; |
323 return (getAngle(tpoint)/(float)Math.PI)*180.0f; |
324 } |
324 } |
325 |
325 |
326 /** |
326 /** |
327 * Returns the X coordinate in pixels relative to the provided screen width. |
327 * Returns the X coordinate in pixels relative to the provided screen width. |
328 * |
328 * |
329 * @param width the screen width |
329 * @param width the screen width |
330 * @return the X coordinate of this TuioPoint in pixels relative to the provided screen width |
330 * @return the X coordinate of this TuioPoint in pixels relative to the provided screen width |
331 */ |
331 */ |
332 public int getScreenX(int width) { |
332 public int getScreenX(int width) { |
333 return (int)Math.round(xpos*width); |
333 return (int)Math.round(xpos*width); |
334 } |
334 } |
335 |
335 |
336 /** |
336 /** |
337 * Returns the Y coordinate in pixels relative to the provided screen height. |
337 * Returns the Y coordinate in pixels relative to the provided screen height. |
338 * |
338 * |
339 * @param height the screen height |
339 * @param height the screen height |
340 * @return the Y coordinate of this TuioPoint in pixels relative to the provided screen height |
340 * @return the Y coordinate of this TuioPoint in pixels relative to the provided screen height |
341 */ |
341 */ |
342 public int getScreenY(int height) { |
342 public int getScreenY(int height) { |
343 return (int)Math.round(ypos*height); |
343 return (int)Math.round(ypos*height); |
344 } |
344 } |
345 |
345 |
346 /** |
346 /** |
347 * Returns the time stamp of this TuioPoint as TuioTime. |
347 * Returns the time stamp of this TuioPoint as TuioTime. |
348 * |
348 * |
349 * @return the time stamp of this TuioPoint as TuioTime |
349 * @return the time stamp of this TuioPoint as TuioTime |
350 */ |
350 */ |
351 public TuioTime getTuioTime() { |
351 public TuioTime getTuioTime() { |
352 return new TuioTime(currentTime); |
352 return new TuioTime(currentTime); |
353 } |
353 } |
354 |
354 |
355 /** |
355 /** |
356 * Returns the start time of this TuioPoint as TuioTime. |
356 * Returns the start time of this TuioPoint as TuioTime. |
357 * |
357 * |
358 * @return the start time of this TuioPoint as TuioTime |
358 * @return the start time of this TuioPoint as TuioTime |
359 */ |
359 */ |
360 public TuioTime getStartTime() { |
360 public TuioTime getStartTime() { |
361 return new TuioTime(startTime); |
361 return new TuioTime(startTime); |
362 } |
362 } |
363 } |
363 } |