|
1 |
|
2 // add hooks |
|
3 (function(){ |
|
4 this.Processing.addTuioObject = undefined; |
|
5 this.Processing.updateTuioObject = undefined; |
|
6 this.Processing.removeTuioObject = undefined; |
|
7 this.Processing.addTuioCursor = undefined; |
|
8 this.Processing.updateTuioCursor = undefined; |
|
9 this.Processing.removeTuioCursor = undefined; |
|
10 })(); |
|
11 |
|
12 (function(){ |
|
13 |
|
14 var tuio = this.tuio; |
|
15 |
|
16 function wrapPath(d) { |
|
17 var i, len = d.path.length; |
|
18 var res = []; |
|
19 for (i=0; i<len; i++) { |
|
20 var pos = d.path[i]; |
|
21 res.push({ |
|
22 getX: function() { return pos[0]; }, |
|
23 getY: function() { return pos[1]; }, |
|
24 |
|
25 getScreenX: function(width) { return width * pos[0]; }, |
|
26 getScreenY: function(height) { return height * pos[1]; }, |
|
27 }); |
|
28 } |
|
29 return res; |
|
30 } |
|
31 |
|
32 function wrapObject(d) { |
|
33 return { |
|
34 getSessionID: function() { return d.sid; }, |
|
35 getSymbolID: function() { return d.fid; }, |
|
36 getX: function() { return d.x; }, |
|
37 getY: function() { return d.y; }, |
|
38 getAngle: function() { return d.angle; }, |
|
39 |
|
40 getScreenX: function(width) { return width * d.x; }, |
|
41 getScreenY: function(height) { return height * d.y; }, |
|
42 |
|
43 getPath: function() { return wrapPath(d); }, |
|
44 }; |
|
45 } |
|
46 |
|
47 function wrapCursor(d) { |
|
48 return { |
|
49 getSessionID: function() { return d.sid; }, |
|
50 getCursorId: function() { return d.fid; }, |
|
51 getX: function() { return d.x; }, |
|
52 getY: function() { return d.y; }, |
|
53 |
|
54 getScreenX: function(width) { return width * d.x; }, |
|
55 getScreenY: function(height) { return height * d.y; }, |
|
56 |
|
57 getPath: function() { return wrapPath(d); }, |
|
58 }; |
|
59 } |
|
60 |
|
61 tuio.TuioProcessing = function(p) { |
|
62 var listener = new tuio.Listener({ |
|
63 object_add: function(d) { if (p.addTuioObject) p.addTuioObject(wrapObject(d)); }, |
|
64 object_update: function(d) { if (p.updateTuioObject) p.updateTuioObject(wrapObject(d)); }, |
|
65 object_remove: function(d) { if (p.removeTuioObject) p.removeTuioObject(wrapObject(d)); }, |
|
66 cursor_add: function(d) { if (p.addTuioCursor) p.addTuioCursor(wrapCursor(d)); }, |
|
67 cursor_update: function(d) { if (p.updateTuioCursor) p.updateTuioCursor(wrapCursor(d)); }, |
|
68 cursor_remove: function(d) { if (p.removeTuioCursor) p.removeTuioCursor(wrapCursor(d)); } |
|
69 }); |
|
70 tuio.addListener(listener); |
|
71 tuio.start(); |
|
72 }; |
|
73 |
|
74 tuio.TuioProcessing.prototype = { |
|
75 getTuioObjects: function() { |
|
76 var res = []; |
|
77 var i, len = tuio.objects.length; |
|
78 for (i=0; i<len; i++) { |
|
79 res.push(wrapObject(tuio.objects[i])); |
|
80 } |
|
81 return res; |
|
82 }, |
|
83 |
|
84 getTuioCursors: function() { |
|
85 var res = []; |
|
86 var i, len = tuio.cursors.length; |
|
87 for (i=0; i<len; i++) { |
|
88 res.push(wrapCursor(tuio.cursors[i])); |
|
89 } |
|
90 return res; |
|
91 } |
|
92 }; |
|
93 |
|
94 })(); |
|
95 |