front_idill/extern/fajran-tuiojs/examples/processingjs/tuio.processing.js
author bastiena
Fri, 06 Apr 2012 18:32:13 +0200
changeset 25 a7b0e40bcab0
child 26 858e90c7cbaa
permissions -rw-r--r--
Front IDILL : Basic JS TUIO lib loaded
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
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    16
function wrapPath(d) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    17
	var i, len = d.path.length;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    18
	var res = [];
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    19
	for (i=0; i<len; i++) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    20
		var pos = d.path[i];
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    21
		res.push({
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    22
			getX: function() { return pos[0]; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    23
			getY: function() { return pos[1]; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    24
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    25
			getScreenX: function(width) { return width * pos[0]; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    26
			getScreenY: function(height) { return height * pos[1]; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    27
		});
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    28
	}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    29
	return res;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    30
}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    31
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    32
function wrapObject(d) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    33
	return {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    34
		getSessionID: function() { return d.sid; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    35
		getSymbolID: function() { return d.fid; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    36
		getX: function() { return d.x; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    37
		getY: function() { return d.y; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    38
		getAngle: function() { return d.angle; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    39
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    40
		getScreenX: function(width) { return width * d.x; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    41
		getScreenY: function(height) { return height * d.y; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    42
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    43
		getPath: function() { return wrapPath(d); },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    44
	};
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    45
}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    46
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    47
function wrapCursor(d) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    48
	return {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    49
		getSessionID: function() { return d.sid; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    50
		getCursorId: function() { return d.fid; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    51
		getX: function() { return d.x; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    52
		getY: function() { return d.y; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    53
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    54
		getScreenX: function(width) { return width * d.x; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    55
		getScreenY: function(height) { return height * d.y; },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    56
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    57
		getPath: function() { return wrapPath(d); },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    58
	};
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    59
}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    60
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    61
tuio.TuioProcessing = function(p) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    62
	var listener = new tuio.Listener({
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    63
		object_add:    function(d) { if (p.addTuioObject)    p.addTuioObject(wrapObject(d));    },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    64
		object_update: function(d) { if (p.updateTuioObject) p.updateTuioObject(wrapObject(d)); },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    65
		object_remove: function(d) { if (p.removeTuioObject) p.removeTuioObject(wrapObject(d)); },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    66
		cursor_add:    function(d) { if (p.addTuioCursor)    p.addTuioCursor(wrapCursor(d));    },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    67
		cursor_update: function(d) { if (p.updateTuioCursor) p.updateTuioCursor(wrapCursor(d)); },
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    68
		cursor_remove: function(d) { if (p.removeTuioCursor) p.removeTuioCursor(wrapCursor(d)); }
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    69
	});
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    70
	tuio.addListener(listener);
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    71
	tuio.start();
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    72
};
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    73
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    74
tuio.TuioProcessing.prototype = {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    75
	getTuioObjects: function() {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    76
		var res = [];
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    77
		var i, len = tuio.objects.length;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    78
		for (i=0; i<len; i++) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    79
			res.push(wrapObject(tuio.objects[i]));
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    80
		}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    81
		return res;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    82
	},
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    83
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    84
	getTuioCursors: function() {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    85
		var res = [];
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    86
		var i, len = tuio.cursors.length;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    87
		for (i=0; i<len; i++) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    88
			res.push(wrapCursor(tuio.cursors[i]));
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    89
		}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    90
		return res;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    91
	}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    92
};
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    93
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    94
})();
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    95