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