|
8
|
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 |
|
|
|
10 |
// fluid3 by Glen Murphy.
|
|
|
11 |
// View the applet in use at http://bodytag.org/
|
|
|
12 |
// Code has not been optimised, and will run fairly slowly.
|
|
|
13 |
|
|
|
14 |
// Adjust the 'RES' variable below to change speed - higher is faster.
|
|
|
15 |
// Don't forget to change the size command in setup if changing the
|
|
|
16 |
// height/width.
|
|
|
17 |
|
|
|
18 |
import TUIO.*;
|
|
|
19 |
TuioProcessing tuioClient;
|
|
|
20 |
|
|
|
21 |
TuioPoint precPoint;
|
|
|
22 |
|
|
|
23 |
//Port du Client TUIO.
|
|
|
24 |
int port = 80;
|
|
|
25 |
//Limites de la zone de recherche pour les mains.
|
|
|
26 |
float minDistHands = 1;
|
|
|
27 |
float maxDistHands = 1.5;
|
|
|
28 |
//Paramètres de la fenêtre.
|
|
|
29 |
int WIDTH = 640;
|
|
|
30 |
int HEIGHT = 480;
|
|
|
31 |
|
|
|
32 |
int RES = 2;
|
|
|
33 |
int PENSIZE = 30;
|
|
|
34 |
|
|
|
35 |
int lwidth = WIDTH/RES;
|
|
|
36 |
int lheight = HEIGHT/RES;
|
|
|
37 |
int PNUM = 30000;
|
|
|
38 |
vsquare[][] v = new vsquare[lwidth+1][lheight+1];
|
|
|
39 |
vbuffer[][] vbuf = new vbuffer[lwidth+1][lheight+1];
|
|
|
40 |
|
|
|
41 |
TuioPoint pt1, pt2, precPt1, precPt2;
|
|
|
42 |
|
|
|
43 |
particle[] p = new particle[PNUM];
|
|
|
44 |
int pcount = 0;
|
|
|
45 |
int mouse1Xvel = 0;
|
|
|
46 |
int mouse1Yvel = 0;
|
|
|
47 |
int mouse2Xvel = 0;
|
|
|
48 |
int mouse2Yvel = 0;
|
|
|
49 |
|
|
|
50 |
/*FONCTION D'INITIALISATION
|
|
|
51 |
Entrée :
|
|
|
52 |
Sortie : Création de la fenêtre et du client TUIO*/
|
|
|
53 |
public void setup()
|
|
|
54 |
{
|
|
|
55 |
size (WIDTH, HEIGHT);
|
|
|
56 |
tuioClient = new TuioProcessing(this, port);
|
|
|
57 |
|
|
|
58 |
background(#666666);
|
|
|
59 |
noStroke();
|
|
|
60 |
for(int i = 0; i < PNUM; i++)
|
|
|
61 |
{
|
|
|
62 |
p[i] = new particle(random(RES,WIDTH-RES),random(RES,HEIGHT-RES));
|
|
|
63 |
}
|
|
|
64 |
for(int i = 0; i <= lwidth; i++)
|
|
|
65 |
{
|
|
|
66 |
for(int u = 0; u <= lheight; u++)
|
|
|
67 |
{
|
|
|
68 |
v[i][u] = new vsquare(i*RES,u*RES);
|
|
|
69 |
vbuf[i][u] = new vbuffer(i*RES,u*RES);
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
void draw()
|
|
|
75 |
{
|
|
|
76 |
tuioInput();
|
|
|
77 |
if(precPt1 != pt1 || precPt2 != pt2)
|
|
|
78 |
{
|
|
|
79 |
int a1xvel = 0, a1yvel = 0, a2xvel = 0, a2yvel = 0;
|
|
|
80 |
if(precPt1 != null && pt1 != null)
|
|
|
81 |
{
|
|
|
82 |
a1xvel = (int)pt1.getX()-(int)precPt1.getX();
|
|
|
83 |
a1yvel = (int)pt1.getY()-(int)precPt1.getY();
|
|
|
84 |
mouse1Xvel = (a1xvel != mouse1Xvel) ? a1xvel : 0;
|
|
|
85 |
mouse1Yvel = (a1yvel != mouse1Yvel) ? a1yvel : 0;
|
|
|
86 |
}
|
|
|
87 |
if(precPt2 != null && pt2 != null)
|
|
|
88 |
{
|
|
|
89 |
a2xvel = (int)pt2.getX()-(int)precPt2.getX();
|
|
|
90 |
a2yvel = (int)pt2.getY()-(int)precPt2.getY();
|
|
|
91 |
mouse2Xvel = (a2xvel != mouse2Xvel) ? a2xvel : 0;
|
|
|
92 |
mouse2Yvel = (a2yvel != mouse2Yvel) ? a2yvel : 0;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
for(int i = 0; i < lwidth; i++)
|
|
|
96 |
{
|
|
|
97 |
for(int u = 0; u < lheight; u++)
|
|
|
98 |
{
|
|
|
99 |
vbuf[i][u].updatebuf(i,u);
|
|
|
100 |
v[i][u].col = 32;
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
for(int i = 0; i < PNUM-1; i++)
|
|
|
104 |
{
|
|
|
105 |
p[i].updatepos();
|
|
|
106 |
}
|
|
|
107 |
for(int i = 0; i < lwidth; i++)
|
|
|
108 |
{
|
|
|
109 |
for(int u = 0; u < lheight; u++)
|
|
|
110 |
{
|
|
|
111 |
v[i][u].addbuffer(i, u);
|
|
|
112 |
v[i][u].updatevels(mouse1Xvel, mouse1Yvel, pt1);
|
|
|
113 |
if(pt2 != null)
|
|
|
114 |
v[i][u].updatevels(mouse2Xvel, mouse2Yvel, pt2);
|
|
|
115 |
v[i][u].display(i, u);
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
precPt1 = pt1;
|
|
|
120 |
precPt2 = pt2;
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
void update(TuioPoint _pt1, TuioPoint _pt2)
|
|
|
125 |
{
|
|
|
126 |
pt1 = _pt1;
|
|
|
127 |
pt2 = _pt2;
|
|
|
128 |
}
|