|
10
|
1 |
/*
|
|
8
|
2 |
* This file is part of the TraKERS\Front Processing package.
|
|
|
3 |
*
|
|
|
4 |
* (c) IRI <http://www.iri.centrepompidou.fr/>
|
|
|
5 |
*
|
|
27
|
6 |
* For the full copyright and license information, please view the LICENSE
|
|
8
|
7 |
* file that was distributed with this source code.
|
|
|
8 |
*/
|
|
|
9 |
|
|
|
10 |
class vsquare {
|
|
|
11 |
int x;
|
|
|
12 |
int y;
|
|
|
13 |
float xvel;
|
|
|
14 |
float yvel;
|
|
|
15 |
float col;
|
|
|
16 |
|
|
|
17 |
vsquare(int xIn,int yIn) {
|
|
|
18 |
x = xIn;
|
|
|
19 |
y = yIn;
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
void addbuffer(int i, int u) {
|
|
|
23 |
if(i>0 && i<lwidth && u>0 && u<lheight) {
|
|
|
24 |
xvel += (vbuf[i-1][u-1].pressure*0.5
|
|
|
25 |
+vbuf[i-1][u].pressure
|
|
|
26 |
+vbuf[i-1][u+1].pressure*0.5
|
|
|
27 |
-vbuf[i+1][u-1].pressure*0.5
|
|
|
28 |
-vbuf[i+1][u].pressure
|
|
|
29 |
-vbuf[i+1][u+1].pressure*0.5
|
|
|
30 |
)*0.49;
|
|
|
31 |
yvel += (vbuf[i-1][u-1].pressure*0.5
|
|
|
32 |
+vbuf[i][u-1].pressure
|
|
|
33 |
+vbuf[i+1][u-1].pressure*0.5
|
|
|
34 |
-vbuf[i-1][u+1].pressure*0.5
|
|
|
35 |
-vbuf[i][u+1].pressure
|
|
|
36 |
-vbuf[i+1][u+1].pressure*0.5
|
|
|
37 |
)*0.49;
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
void updatevels(int mvelX, int mvelY, TuioPoint pt) {
|
|
|
42 |
float adj = x;
|
|
|
43 |
float opp = y;
|
|
|
44 |
float dist;
|
|
|
45 |
float mod;
|
|
|
46 |
|
|
|
47 |
if(pt != null) {
|
|
|
48 |
float XRev = map(pt.getX(), realWidth, realHeight, WIDTH, HEIGHT);
|
|
|
49 |
float YRev = map(pt.getY(), realWidth, realHeight, WIDTH, HEIGHT);
|
|
|
50 |
adj = x - XRev;
|
|
|
51 |
opp = y - YRev;
|
|
|
52 |
dist = sqrt(opp*opp + adj*adj);
|
|
|
53 |
if(dist < PENSIZE) {
|
|
|
54 |
if(dist < 4) dist = PENSIZE;
|
|
|
55 |
mod = PENSIZE/dist;
|
|
|
56 |
xvel += mvelX*mod;
|
|
|
57 |
yvel += mvelY*mod;
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
if(randomGust > 0) {
|
|
|
61 |
adj = x - randomGustX;
|
|
|
62 |
opp = y - randomGustY;
|
|
|
63 |
dist = sqrt(opp*opp + adj*adj);
|
|
|
64 |
if(dist < randomGustSize) {
|
|
|
65 |
if(dist < RES*2) dist = randomGustSize;
|
|
|
66 |
mod = randomGustSize/dist;
|
|
|
67 |
xvel += (randomGustMax-randomGust)*randomGustXvel*mod;
|
|
|
68 |
yvel += (randomGustMax-randomGust)*randomGustYvel*mod;
|
|
|
69 |
}
|
|
|
70 |
}
|
|
|
71 |
xvel *= 0.99;
|
|
|
72 |
yvel *= 0.98;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
void addcolour(int amt) {
|
|
|
76 |
col += amt;
|
|
|
77 |
if(col > 196) col = 196;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
void display(int i, int u) {
|
|
|
81 |
float tcol = 0;
|
|
|
82 |
if(i>0 && i<lwidth-1 && u>0 && u<lheight-1) {
|
|
|
83 |
tcol = (+ v[i][u+1].col
|
|
|
84 |
+ v[i+1][u].col
|
|
|
85 |
+ v[i+1][u+1].col*0.5
|
|
|
86 |
)*0.3;
|
|
|
87 |
tcol = (int)(tcol+col*0.5);
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
fill(255-tcol, 255-tcol, 255-tcol);
|
|
|
91 |
rect(x,y,RES,RES);
|
|
|
92 |
col = 0;
|
|
|
93 |
}
|
|
9
|
94 |
}
|