front_idill/extern/fajran-tuiojs/examples/processingjs/tuio.processing.js
author bastiena
Fri, 06 Apr 2012 18:36:40 +0200
changeset 26 858e90c7cbaa
parent 25 a7b0e40bcab0
child 27 6c08d4d7219e
permissions -rw-r--r--
Front IDILL : JS TUIO module modified to receive 3D Points
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;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    10
})();
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    11
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    12
(function(){
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    13
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    14
var tuio = this.tuio;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    15
26
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    16
/*
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    17
* Modifié par alexandre.bastien@iri.centrepompidou.fr
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    18
*/
25
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    19
function wrapPath(d) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    20
	var i, len = d.path.length;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    21
	var res = [];
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    22
	for (i=0; i<len; i++) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    23
		var pos = d.path[i];
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    24
		res.push({
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    25
			getX: function() { return pos[0]; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    26
			getY: function() { return pos[1]; },
26
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    27
			getZ: function() { return pos[2]; },
25
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    28
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    29
			getScreenX: function(width) { return width * pos[0]; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    30
			getScreenY: function(height) { return height * pos[1]; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    31
		});
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    32
	}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    33
	return res;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    34
}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    35
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    36
function wrapObject(d) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    37
	return {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    38
		getSessionID: function() { return d.sid; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    39
		getSymbolID: function() { return d.fid; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    40
		getX: function() { return d.x; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    41
		getY: function() { return d.y; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    42
		getAngle: function() { return d.angle; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    43
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    44
		getScreenX: function(width) { return width * d.x; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    45
		getScreenY: function(height) { return height * d.y; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    46
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    47
		getPath: function() { return wrapPath(d); },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    48
	};
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    49
}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    50
26
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    51
/*
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    52
* Modifié par alexandre.bastien@iri.centrepompidou.fr
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    53
*/
25
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    54
function wrapCursor(d) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    55
	return {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    56
		getSessionID: function() { return d.sid; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    57
		getCursorId: function() { return d.fid; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    58
		getX: function() { return d.x; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    59
		getY: function() { return d.y; },
26
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    60
		getZ: function() { return d.z; },
25
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    61
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    62
		getScreenX: function(width) { return width * d.x; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    63
		getScreenY: function(height) { return height * d.y; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    64
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    65
		getPath: function() { return wrapPath(d); },
26
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    66
		getPosition: function() { return wrapPosition(d); },
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    67
	};
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    68
}
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    69
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    70
/*
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    71
* Ajouté par alexandre.bastien@iri.centrepompidou.fr
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    72
*/
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    73
function wrapPosition(d) {
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    74
	return {
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    75
		getX: function() { return d.x; },
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    76
		getY: function() { return d.y; },
858e90c7cbaa Front IDILL :
bastiena
parents: 25
diff changeset
    77
		getZ: function() { return d.z; },
25
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    78
	};
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    79
}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    80
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    81
tuio.TuioProcessing = function(p) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    82
	var listener = new tuio.Listener({
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    83
		object_add:    function(d) { if (p.addTuioObject)    p.addTuioObject(wrapObject(d));    },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    84
		object_update: function(d) { if (p.updateTuioObject) p.updateTuioObject(wrapObject(d)); },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    85
		object_remove: function(d) { if (p.removeTuioObject) p.removeTuioObject(wrapObject(d)); },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    86
		cursor_add:    function(d) { if (p.addTuioCursor)    p.addTuioCursor(wrapCursor(d));    },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    87
		cursor_update: function(d) { if (p.updateTuioCursor) p.updateTuioCursor(wrapCursor(d)); },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    88
		cursor_remove: function(d) { if (p.removeTuioCursor) p.removeTuioCursor(wrapCursor(d)); }
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    89
	});
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    90
	tuio.addListener(listener);
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    91
	tuio.start();
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    92
};
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    93
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    94
tuio.TuioProcessing.prototype = {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    95
	getTuioObjects: function() {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    96
		var res = [];
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    97
		var i, len = tuio.objects.length;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    98
		for (i=0; i<len; i++) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    99
			res.push(wrapObject(tuio.objects[i]));
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   100
		}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   101
		return res;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   102
	},
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   103
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   104
	getTuioCursors: function() {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   105
		var res = [];
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   106
		var i, len = tuio.cursors.length;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   107
		for (i=0; i<len; i++) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   108
			res.push(wrapCursor(tuio.cursors[i]));
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   109
		}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   110
		return res;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   111
	}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   112
};
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   113
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   114
})();
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
   115