|
1 /* |
|
2 * This file is part of the TraKERS\Front Processing package. |
|
3 * |
|
4 * (c) IRI <http://www.iri.centrepompidou.fr/> |
|
5 * |
|
6 * For the full copyright and license information, please view the LICENSE_FRONT |
|
7 * file that was distributed with this source code. |
|
8 */ |
|
9 |
1 import TUIO.*; |
10 import TUIO.*; |
2 TuioProcessing tuioClient; |
11 TuioProcessing tuioClient; |
3 //Indique s'il s'agit de la main gauche. |
12 //Indique s'il s'agit de la main gauche. |
4 boolean oneHandLeft; |
13 boolean oneHandLeft; |
|
14 |
|
15 //Taille de la fenêtre |
|
16 int WIDTH = 640, HEIGHT = 480; |
5 |
17 |
6 //Port du Client TUIO |
18 //Port du Client TUIO |
7 int port = 80; |
19 int port = 80; |
8 float minDistHands = 1; |
20 float minDistHands = 1; |
9 float maxDistHands = 1.5; |
21 float maxDistHands = 1.5; |
10 |
22 |
11 /*FONCTION D'INITIALISATION |
23 /*FONCTION D'INITIALISATION |
12 Entrée : |
24 Entrée : |
13 Sortie : Création de la fenêtre et du client TUIO*/ |
25 Sortie : Création de la fenêtre et du client TUIO*/ |
14 public void setup() |
26 void setup() |
15 { |
27 { |
16 size (640, 480); |
28 size (WIDTH, HEIGHT); |
17 showMask(); |
29 showMask(); |
18 tuioClient = new TuioProcessing(this, port); |
30 tuioClient = new TuioProcessing(this, port); |
19 textAlign(CENTER); |
31 textAlign(CENTER); |
20 imageMode(CENTER); |
32 imageMode(CENTER); |
21 smooth(); |
33 smooth(); |
22 } |
34 } |
23 |
35 |
24 /*FONCTION DE DESSIN |
36 /*FONCTION DE DESSIN |
25 Entrée : |
37 Entrée : |
26 Sortie : Appel à la fonction de traitement d'input du serveur toutes les n millisecondes*/ |
38 Sortie : Appel à la fonction de traitement d'input du serveur toutes les n millisecondes*/ |
27 public void draw() |
39 void draw() |
28 { |
40 { |
29 fill(0); |
41 fill(0); |
30 tuioInput(); |
42 tuioInput(); |
31 noStroke(); |
43 noStroke(); |
32 } |
44 } |
33 |
45 |
34 /*FONCTION DE RECEPTION DES MESSAGES OSC |
|
35 Entrée : |
|
36 Sortie : Appel aux différentes fonctions de dessin si un message est reçu*/ |
|
37 public void tuioInput() |
|
38 { |
|
39 noFill(); |
|
40 Vector tuioCursorList = tuioClient.getTuioCursors(); |
|
41 |
|
42 if(tuioCursorList.size() <= 0) |
|
43 { |
|
44 showMask(); |
|
45 refreshText("Les mains sont trop loin ou trop près.", "Je ne détecte aucune main."); |
|
46 } |
|
47 |
|
48 if(tuioCursorList.size() == 1) |
|
49 { |
|
50 handleOneHand((TuioCursor)tuioCursorList.elementAt(0)); |
|
51 fill(255); |
|
52 refreshText("Les mains sont dans la zone de captation.", "Je détecte une main."); |
|
53 } |
|
54 else if(tuioCursorList.size() == 2) |
|
55 { |
|
56 handleBothHands(tuioCursorList); |
|
57 fill(255); |
|
58 refreshText("Les mains sont dans la zone de captation.", "Je détecte les deux mains."); |
|
59 } |
|
60 } |
|
61 |
|
62 /*FONCTION DE GENERATION DU MASQUE |
46 /*FONCTION DE GENERATION DU MASQUE |
63 Entrée : |
47 Entrée : |
64 Sortie : Place des rectangles autour de la zone de dessin*/ |
48 Sortie : Place des rectangles autour de la zone de dessin*/ |
65 public void showMask() |
49 void showMask() |
66 { |
50 { |
67 background(0); |
51 background(0); |
68 fill(255); |
52 fill(255); |
69 rect(0, 80, width, height-130); |
53 rect(0, 80, width, height-130); |
70 } |
54 } |
71 |
55 |
72 /*FONCTION DE RAFFRACHISSEMENT DU TEXTE SUPERIEUR |
56 /*FONCTION DE RAFFRACHISSEMENT DU TEXTE SUPERIEUR |
73 Entrée : Texte à afficher |
57 Entrée : Texte à afficher |
74 Sortie : Place un rectangle au dessus de la zone de dessin et raffraichit le texte*/ |
58 Sortie : Place un rectangle au dessus de la zone de dessin et raffraichit le texte*/ |
75 public void refreshText(String txt1, String txt2) |
59 void refreshText(String txt1, String txt2) |
76 { |
60 { |
77 fill(0); |
61 fill(0); |
78 rect(0, 0, width, 80); |
62 rect(0, 0, width, 80); |
79 fill(255); |
63 fill(255); |
80 text(txt1, width/2 - 20, 20); |
64 text(txt1, width/2 - 20, 20); |
81 text(txt2, width/2 - 20, 40); |
65 text(txt2, width/2 - 20, 40); |
82 } |
|
83 |
|
84 /*FONCTION DE GESTION DES COURBES POUR UNE MAIN DETECTEE |
|
85 Entrée : Un curseur TUIO |
|
86 Sortie : Appel aux différentes fonctions de dessin si un message est reçu*/ |
|
87 public void handleOneHand(TuioCursor handCursor) |
|
88 { |
|
89 TuioPoint pt = handCursor.getPosition();//(TuioPoint)pointList.get(j); |
|
90 fill(0); |
|
91 drawEllipse(pt.getX(), pt.getY(), pt.getZ(), !oneHandLeft); |
|
92 } |
|
93 |
|
94 /*FONCTION DE GESTION DES COURBES POUR DEUX MAINS DETECTEES |
|
95 Entrée : La liste des curseurs TUIO |
|
96 Sortie : Appel aux différentes fonctions de dessin si un message est reçu*/ |
|
97 void handleBothHands(Vector tuioCursorList) |
|
98 { |
|
99 TuioCursor handLeftCursor = (TuioCursor)tuioCursorList.elementAt(0); |
|
100 TuioCursor handRightCursor = (TuioCursor)tuioCursorList.elementAt(1); |
|
101 TuioPoint pt; |
|
102 |
|
103 pt = (TuioPoint)handLeftCursor.getPosition();//handLeftPointList.get(j); |
|
104 drawEllipse(pt.getX(), pt.getY(), pt.getZ(), true); |
|
105 pt = (TuioPoint)handRightCursor.getPosition();//handRightPointList.get(k); |
|
106 drawEllipse(pt.getX(), pt.getY(), pt.getZ(), false); |
|
107 } |
66 } |
108 |
67 |
109 /*FONCTION DE DESSIN D'UN POINT DE COURBE |
68 /*FONCTION DE DESSIN D'UN POINT DE COURBE |
110 Entrée : Coordonnées X, Y et Z d'un point |
69 Entrée : Coordonnées X, Y et Z d'un point |
111 Sortie : Le point est dessiné avec une épaisseur et une luminosité dépendant de Z*/ |
70 Sortie : Le point est dessiné avec une épaisseur et une luminosité dépendant de Z*/ |