front_idill/extern/fajran-tuiojs/examples/processingjs/hand_pointing.html
author bastiena
Fri, 06 Apr 2012 18:36:40 +0200
changeset 26 858e90c7cbaa
child 28 9ccef81f02ab
permissions -rw-r--r--
Front IDILL : JS TUIO module modified to receive 3D Points
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     1
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     2
<html><head>
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     3
<meta charset="UTF-8" />
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     4
<script type="text/javascript" src="../../src/tuio.js"></script>
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     5
<script type="text/javascript" src="../../connector/npTuioClient/tuiojs.npTuioClient.js"></script>
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     6
<script type="text/javascript" src="processing.js"></script>
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     7
<script type="text/javascript" src="tuio.processing.js"></script>
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     8
<script type="text/javascript" src="init.js"></script>
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     9
</head>
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    10
<body>
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    11
<center>
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    12
	<script type="application/processing">
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    13
		<!--// All Examples Written by Casey Reas and Ben Fry
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    14
		// unless otherwise stated.
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    15
		var tuioClient;
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    16
		//Indique s'il s'agit de la main gauche.
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    17
		var oneHandLeft;
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    18
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    19
		//Taille de la fenêtre
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    20
		var WIDTH = 640, HEIGHT = 480;
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    21
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    22
		//Port du Client TUIO
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    23
		var port = 80;
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    24
		var minDistHands = 1;
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    25
		var maxDistHands = 1.5;
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    26
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    27
		/*FONCTION D'INITIALISATION
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    28
		Entrée :
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    29
		Sortie : Cr�ation de la fenêtre et du client TUIO*/
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    30
		void setup()
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    31
		{
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    32
			size (WIDTH, HEIGHT);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    33
			showMask();
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    34
			tuioClient = new tuio.TuioProcessing(this);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    35
			textAlign(CENTER);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    36
			imageMode(CENTER);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    37
			smooth();
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    38
		}
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    39
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    40
		/*FONCTION DE DESSIN
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    41
		Entrée :
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    42
		Sortie : Appel à la fonction de traitement d'input du serveur toutes les n millisecondes*/
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    43
		void draw()
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    44
		{
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    45
			fill(0);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    46
			tuioInput();
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    47
			noStroke();
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    48
		}
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    49
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    50
		/*FONCTION DE RECEPTION DES MESSAGES OSC
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    51
		Entrée :
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    52
		Sortie : Appel aux différentes fonctions de dessin si un message est reçu*/
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    53
		void tuioInput()
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    54
		{
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    55
			noFill();
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    56
			var tuioCursorList = tuioClient.getTuioCursors();
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    57
			
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    58
			if(tuioCursorList.length() <= 0)
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    59
			{
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    60
				showMask();
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    61
				refreshText("Les mains sont trop loin ou trop près.", "Je ne détecte aucune main.");
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    62
			}
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    63
					
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    64
			if(tuioCursorList.length() == 1)
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    65
			{
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    66
				handleOneHand(tuioCursorList[0]);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    67
				fill(255);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    68
				refreshText("Les mains sont dans la zone de captation.", "Je détecte une main.");
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    69
			}
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    70
			else if(tuioCursorList.length() == 2)
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    71
			{
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    72
				handleBothHands(tuioCursorList);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    73
				fill(255);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    74
				refreshText("Les mains sont dans la zone de captation.", "Je détecte les deux mains.");
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    75
			}
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    76
		}
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    77
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    78
		/*FONCTION DE GESTION DES COURBES POUR UNE MAIN DETECTEE
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    79
		Entrée : Un curseur TUIO
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    80
		Sortie : Appel aux différentes fonctions de dessin si un message est reçu*/
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    81
		void handleOneHand(var handCursor)
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    82
		{
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    83
			var pt = handCursor.getPosition();
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    84
			drawEllipse(pt.getX(), pt.getY(), pt.getZ(), !oneHandLeft);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    85
		}
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    86
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    87
		/*FONCTION DE GESTION DES COURBES POUR DEUX MAINS DETECTEES
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    88
		Entrée : La liste des curseurs TUIO
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    89
		Sortie : Appel aux différentes fonctions de dessin si un message est reçu*/
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    90
		void handleBothHands(var tuioCursorList)
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    91
		{
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    92
			var handLeftCursor = tuioCursorList[0];
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    93
			var handRightCursor = tuioCursorList[1];
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    94
			var pt;
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    95
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    96
			pt = handLeftCursor.getPosition();
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    97
			drawEllipse(pt.getX(), pt.getY(), pt.getZ(), true);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    98
			pt = handRightCursor.getPosition();
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    99
			drawEllipse(pt.getX(), pt.getY(), pt.getZ(), false);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   100
		}
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   101
		
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   102
		/*FONCTION DE GENERATION DU MASQUE
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   103
		Entrée :
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   104
		Sortie : Place des rectangles autour de la zone de dessin*/
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   105
		void showMask()
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   106
		{
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   107
			background(0);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   108
			fill(255);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   109
			rect(0, 80, width, height-130);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   110
		}
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   111
			
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   112
		/*FONCTION DE RAFFRACHISSEMENT DU TEXTE SUPERIEUR
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   113
		Entrée : Texte à afficher
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   114
		Sortie : Place un rectangle au dessus de la zone de dessin et raffraichit le texte*/
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   115
		void refreshText(String txt1, String txt2)
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   116
		{
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   117
			fill(0);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   118
			rect(0, 0, width, 80);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   119
			fill(255);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   120
			text(txt1, width/2 - 20, 20);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   121
			text(txt2, width/2 - 20, 40);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   122
		}
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   123
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   124
		/*FONCTION DE DESSIN D'UN POINT DE COURBE
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   125
		Entrée : Coordonnées X, Y et Z d'un point
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   126
		Sortie : Le point est dessiné avec une épaisseur et une luminosité dépendant de Z*/
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   127
		void drawEllipse(float x, float y, float z, boolean leftHand)
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   128
		{
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   129
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   130
			fill(0, 0, 255);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   131
			stroke(0,0,0);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   132
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   133
			float weight = map(z, minDistHands, maxDistHands, 50, 1);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   134
			float redColor = map(z, minDistHands, maxDistHands, 255, 80);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   135
			
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   136
			if(leftHand)
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   137
				fill(redColor,0,0);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   138
			else
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   139
				fill(0,redColor,0);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   140
			
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   141
			if(weight >= 30)
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   142
				fill(0, 0, redColor);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   143
			
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   144
			ellipse(x+20, y+100, weight, weight);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   145
		}
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   146
	</script>
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   147
	<canvas></canvas>
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   148
</center>
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
   149
</body></html>