front_idill/extern/fajran-tuiojs/examples/processingjs/tuio.processing.js
changeset 28 9ccef81f02ab
parent 27 6c08d4d7219e
equal deleted inserted replaced
27:6c08d4d7219e 28:9ccef81f02ab
       
     1 /*
       
     2     Modified by alexandre.bastien@iri.centrepompidou.fr to manage TUIO strings.
       
     3 */
     1 
     4 
     2 // add hooks
     5 // add hooks
     3 (function(){
     6 (function(){
     4 this.Processing.addTuioObject    = undefined;
     7 this.Processing.addTuioObject    = undefined;
     5 this.Processing.updateTuioObject = undefined;
     8 this.Processing.updateTuioObject = undefined;
    18 
    21 
    19 /*
    22 /*
    20 * Modifié par alexandre.bastien@iri.centrepompidou.fr
    23 * Modifié par alexandre.bastien@iri.centrepompidou.fr
    21 */
    24 */
    22 function wrapPath(d) {
    25 function wrapPath(d) {
    23 	var i, len = d.path.length;
    26     var i, len = d.path.length;
    24 	var res = [];
    27     var res = [];
    25 	for (i=0; i<len; i++) {
    28     for (i=0; i<len; i++) {
    26 		var pos = d.path[i];
    29         var pos = d.path[i];
    27 		res.push({
    30         res.push({
    28 			getX: function() { return pos[0]; },
    31             getX: function() { return pos[0]; },
    29 			getY: function() { return pos[1]; },
    32             getY: function() { return pos[1]; },
    30 			getZ: function() { return pos[2]; },
    33             getZ: function() { return pos[2]; },
    31 
    34 
    32 			getScreenX: function(width) { return width * pos[0]; },
    35             getScreenX: function(width) { return width * pos[0]; },
    33 			getScreenY: function(height) { return height * pos[1]; },
    36             getScreenY: function(height) { return height * pos[1]; },
    34 		});
    37         });
    35 	}
    38     }
    36 	return res;
    39     return res;
    37 }
    40 }
    38 
    41 
    39 function wrapObject(d) {
    42 function wrapObject(d) {
    40 	return {
    43     return {
    41 		getSessionID: function() { return d.sid; },
    44         getSessionID: function() { return d.sid; },
    42 		getSymbolID: function() { return d.fid; },
    45         getSymbolID: function() { return d.fid; },
    43 		getX: function() { return d.x; },
    46         getX: function() { return d.x; },
    44 		getY: function() { return d.y; },
    47         getY: function() { return d.y; },
    45 		getAngle: function() { return d.angle; },
    48         getAngle: function() { return d.angle; },
    46 
    49 
    47 		getScreenX: function(width) { return width * d.x; },
    50         getScreenX: function(width) { return width * d.x; },
    48 		getScreenY: function(height) { return height * d.y; },
    51         getScreenY: function(height) { return height * d.y; },
    49 
    52 
    50 		getPath: function() { return wrapPath(d); },
    53         getPath: function() { return wrapPath(d); },
    51 	};
    54     };
    52 }
    55 }
    53 
    56 
    54 /*
    57 /*
    55 * Modifié par alexandre.bastien@iri.centrepompidou.fr
    58 * Modifié par alexandre.bastien@iri.centrepompidou.fr
    56 */
    59 */
    57 function wrapCursor(d) {
    60 function wrapCursor(d) {
    58 	return {
    61     return {
    59 		getSessionID: function() { return d.sid; },
    62         getSessionID: function() { return d.sid; },
    60 		getCursorId: function() { return d.fid; },
    63         getCursorId: function() { return d.fid; },
    61 		getX: function() { return d.x; },
    64         getX: function() { return d.x; },
    62 		getY: function() { return d.y; },
    65         getY: function() { return d.y; },
    63 		getZ: function() { return d.z; },
    66         getZ: function() { return d.z; },
    64 
    67 
    65 		getScreenX: function(width) { return width * d.x; },
    68         getScreenX: function(width) { return width * d.x; },
    66 		getScreenY: function(height) { return height * d.y; },
    69         getScreenY: function(height) { return height * d.y; },
    67 
    70 
    68 		getPath: function() { return wrapPath(d); },
    71         getPath: function() { return wrapPath(d); },
    69 		getPosition: function() { return wrapPosition(d); },
    72         getPosition: function() { return wrapPosition(d); },
    70 	};
    73     };
    71 }
    74 }
    72 
    75 
    73 /*
    76 /*
    74 * Ajouté par alexandre.bastien@iri.centrepompidou.fr
    77 * Ajouté par alexandre.bastien@iri.centrepompidou.fr
    75 */
    78 */
    76 function wrapPosition(d) {
    79 function wrapPosition(d) {
    77 	return {
    80     return {
    78 		getX: function() { return d.x; },
    81         getX: function() { return d.x; },
    79 		getY: function() { return d.y; },
    82         getY: function() { return d.y; },
    80 		getZ: function() { return d.z; },
    83         getZ: function() { return d.z; },
    81 	};
    84     };
    82 }
    85 }
    83 
    86 
    84 /*
    87 /*
    85 * Ajouté par alexandre.bastien@iri.centrepompidou.fr
    88 * Ajouté par alexandre.bastien@iri.centrepompidou.fr
    86 */
    89 */
    87 function wrapString(d) {
    90 function wrapString(d) {
    88 	return {
    91     return {
    89 		getCode: function() { return d.code; },
    92         getCode: function() { return d.code; },
    90 	};
    93     };
    91 }
    94 }
    92 
    95 
    93 tuio.TuioProcessing = function(p) {
    96 tuio.TuioProcessing = function(p) {
    94 	var listener = new tuio.Listener({
    97     var listener = new tuio.Listener({
    95 		object_add:    function(d) { if (p.addTuioObject)    p.addTuioObject(wrapObject(d));    },
    98         object_add:    function(d) { if (p.addTuioObject)    p.addTuioObject(wrapObject(d));    },
    96 		object_update: function(d) { if (p.updateTuioObject) p.updateTuioObject(wrapObject(d)); },
    99         object_update: function(d) { if (p.updateTuioObject) p.updateTuioObject(wrapObject(d)); },
    97 		object_remove: function(d) { if (p.removeTuioObject) p.removeTuioObject(wrapObject(d)); },
   100         object_remove: function(d) { if (p.removeTuioObject) p.removeTuioObject(wrapObject(d)); },
    98 		cursor_add:    function(d) { if (p.addTuioCursor)    p.addTuioCursor(wrapCursor(d));    },
   101         cursor_add:    function(d) { if (p.addTuioCursor)    p.addTuioCursor(wrapCursor(d));    },
    99 		cursor_update: function(d) { if (p.updateTuioCursor) p.updateTuioCursor(wrapCursor(d)); },
   102         cursor_update: function(d) { if (p.updateTuioCursor) p.updateTuioCursor(wrapCursor(d)); },
   100 		cursor_remove: function(d) { if (p.removeTuioCursor) p.removeTuioCursor(wrapCursor(d)); },
   103         cursor_remove: function(d) { if (p.removeTuioCursor) p.removeTuioCursor(wrapCursor(d)); },
   101 		string_add:    function(d) { if (p.addTuioString)    p.addTuioString(wrapString(d));    },
   104         string_add:    function(d) { if (p.addTuioString)    p.addTuioString(wrapString(d));    },
   102 		string_update: function(d) { if (p.updateTuioString) p.updateTuioString(wrapString(d)); },
   105         string_update: function(d) { if (p.updateTuioString) p.updateTuioString(wrapString(d)); },
   103 		string_remove: function(d) { if (p.removeTuioString) p.removeTuioString(wrapString(d)); }
   106         string_remove: function(d) { if (p.removeTuioString) p.removeTuioString(wrapString(d)); }
   104 	});
   107     });
   105 	tuio.addListener(listener);
   108     tuio.addListener(listener);
   106 	tuio.start();
   109     tuio.start();
   107 };
   110 };
   108 
   111 
   109 tuio.TuioProcessing.prototype = {
   112 tuio.TuioProcessing.prototype = {
   110 	getTuioObjects: function() {
   113     getTuioObjects: function() {
   111 		var res = [];
   114         var res = [];
   112 		var i, len = tuio.objects.length;
   115         var i, len = tuio.objects.length;
   113 		for (i=0; i<len; i++) {
   116         for (i=0; i<len; i++) {
   114 			res.push(wrapObject(tuio.objects[i]));
   117             res.push(wrapObject(tuio.objects[i]));
   115 		}
   118         }
   116 		return res;
   119         return res;
   117 	},
   120     },
   118 
   121 
   119 	getTuioCursors: function() {
   122     getTuioCursors: function() {
   120 		var res = [];
   123         var res = [];
   121 		var i, len = tuio.cursors.length;
   124         var i, len = tuio.cursors.length;
   122 		for (i=0; i<len; i++) {
   125         for (i=0; i<len; i++) {
   123 			res.push(wrapCursor(tuio.cursors[i]));
   126             res.push(wrapCursor(tuio.cursors[i]));
   124 		}
   127         }
   125 		return res;
   128         return res;
   126 	},
   129     },
   127 	
   130     
   128 	getTuioStrings: function() {
   131     getTuioStrings: function() {
   129 		var res = [];
   132         var res = [];
   130 		var i, len = tuio.strings.length;
   133         var i, len = tuio.strings.length;
   131 		for (i=0; i<len; i++) {
   134         for (i=0; i<len; i++) {
   132 			res.push(wrapString(tuio.strings[i]));
   135             res.push(wrapString(tuio.strings[i]));
   133 		}
   136         }
   134 		return res;
   137         return res;
   135 	}
   138     }
   136 };
   139 };
   137 
   140 
   138 })();
   141 })();
   139 
   142