-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKinectFishing.pde
169 lines (134 loc) · 3.53 KB
/
KinectFishing.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*/INSTRUCTION:
-If 1 hand:
1 hand controls sea & background & ship
-If 2 hand:
1st hand controls sea
2nd hand controls background & ship
/*/
import ddf.minim.*;
Minim Doraemon;
AudioPlayer playerDoraemon;
import java.util.Map;
import java.util.Iterator;
import SimpleOpenNI.*;
SimpleOpenNI context;
int handVecListSize = 20;
Map<Integer, ArrayList<PVector>> handPathList = new HashMap<Integer, ArrayList<PVector>>();
PFont font;
PImage submarine;
PImage BlueFish;
PImage OrangeFish;
PImage PinkFish;
PImage TreasureChest;
PImage Fireworks;
float[] xBF = new float[2];
float[] yBF = new float[2];
float[] xOF = new float[3];
float[] yOF = new float[3];
float[] xPF = new float[3];
float[] yPF = new float[3];
float MeterBar;
float TrackHands;
float StillSea;
float seaX1=800-467;
float seaX2=800-467*2;
float seaX3=800-467*3;
float seaY;
float R=random(255);
float G=random(255);
float B=random(255);
//Array for random colors of circle controlled by hands
color[] userClr = new color[]
{
color(R, G, B),
color(R, B, G),
color(G, R, B),
color(G, B, R),
color(B, G, R),
color(B, R, G)
};
void setup()
{
size(800, 500);
submarine=loadImage("submarine.png");
BlueFish=loadImage("BlueFish.png");
OrangeFish=loadImage("OrangeFish.png");
PinkFish=loadImage("PinkFish.png");
TreasureChest=loadImage("TreasureChest.png");
Fireworks=loadImage("fireworks.jpg");
font=loadFont("Noteworthy-Bold-48.vlw");
textAlign(CENTER);
MeterBar=15;
for (int BF = 0; BF < 2; BF++) {
xBF[BF] = random(-30, 600);
yBF[BF] = random(seaY+90);
}
for (int OF = 0; OF < 3; OF++) {
xOF[OF] = random(-30, 600);
yOF[OF] = random(seaY+90);
}
for (int PF = 0; PF < 3; PF++) {
xPF[PF] = random(-30, 600);
yPF[PF] = random(seaY+90);
}
Doraemon = new Minim(this);
playerDoraemon = Doraemon.loadFile("Doraemon.mp3");
playerDoraemon.loop();
context = new SimpleOpenNI(this);
if (context.isInit() == false)
{
println("Can't init SimpleOpenNI, maybe the camera is not connected!");
exit();
return;
}
// enable depthMap generation
context.enableDepth();
// disable mirror
context.setMirror(true);
context.enableHand();
context.startGesture(SimpleOpenNI.GESTURE_WAVE);
}
void draw()
{
// update the cam
context.update();
background(255);
TrackHands();
}
// -----------------------------------------------------------------
// hand events
void onNewHand(SimpleOpenNI curContext, int handId, PVector pos)
{
println("onNewHand - handId: " + handId + ", pos: " + pos);
ArrayList<PVector> vecList = new ArrayList<PVector>();
vecList.add(pos);
while (vecList.size () > 3) {
vecList.remove(2);
}
handPathList.put(handId, vecList);
}
void onTrackedHand(SimpleOpenNI curContext, int handId, PVector pos)
{
// println("onTrackedHand - handId: " + handId + ", pos: " + pos );
ArrayList<PVector> vecList = handPathList.get(handId);
if (vecList != null)
{
vecList.add(0, pos);
if (vecList.size() >= handVecListSize)
// remove the last point
vecList.remove(vecList.size()-1);
}
}
void onLostHand(SimpleOpenNI curContext, int handId)
{
println("onLostHand - handId: " + handId);
handPathList.remove(handId);
}
// -----------------------------------------------------------------
// gesture events
void onCompletedGesture(SimpleOpenNI curContext, int gestureType, PVector pos)
{
println("onCompletedGesture - gestureType: " + gestureType + ", pos: " + pos);
int handId = context.startTrackingHand(pos);
println("hand stracked: " + handId);
}