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