forked from narirou/KadenProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKadenProject.pde
174 lines (120 loc) · 3.13 KB
/
KadenProject.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
169
170
171
172
173
174
/* ============================================
LUGVE Processing Example
2013 | KADEN PROJECT :: SWITCH
Credits:
- Particles
by Daniel Shiffman
- SimpleOpenNI Hands3d Test
by Max Rheiner, Interaction Design, zhdk
============================================= */
import java.util.*;
import processing.serial.*;
import SimpleOpenNI.*;
// Hand Controller
SimpleOpenNI context;
HandController hand;
// Lugve System
LugveSystem lugve;
// Arduino
Serial port;
Arduino arduino;
// Window
int WINDOW_WIDTH = 1024;
int WINDOW_HEIGHT = 768;
void setup() {
size( WINDOW_WIDTH, WINDOW_HEIGHT, OPENGL );
context = new SimpleOpenNI( this );
if( context.enableDepth() == false ) {
println( "Can't open the depthMap, maybe the camera is not connected!" );
exit();
return;
}
context.setMirror( true );
context.enableHands();
context.enableGesture();
context.addGesture( "RaiseHand" );
context.setSmoothingHands( 2.0 );
hand = new HandController(); // using context
port = new Serial( this, "COM3", 9600 );
arduino = new Arduino( 15, 10 ); // using port
lugve = new LugveSystem();
hint( DISABLE_DEPTH_MASK );
}
void draw() {
background( 15 );
hand.update();
hand.display();
lugve.update();
lugve.display();
}
/* ========================
Mouse Event
======================== */
void mousePressed() {
switch( mouseButton ) {
case LEFT:
lugve.setPos( mouseX, mouseY );
arduino.setPos( mouseX, mouseY );
break;
}
}
/* ========================
Key Event
======================== */
void keyPressed() {
// Set Size
if( key == CODED ) {
switch( keyCode ) {
case UP:
lugve.sizeUp();
break;
case DOWN:
lugve.sizeDown();
break;
}
}
else if( '0' < key && key < '9' ) {
lugve.setSize( int( key - '0' ) );
}
// ON / OFF
else if( key == ENTER || key == RETURN ) {
lugve.toggleLight();
}
// Change Mode
else if( key == ' ' ) {
lugve.toggleSystem();
}
}
/* ========================
Hands Event
======================== */
void onCreateHands( int handId, PVector pos, float time ) {
println( "onCreateHands - handId: " + handId + ", pos: " + pos + ", time:" + time );
hand.createHands( pos );
}
void onUpdateHands( int handId, PVector pos, float time ) {
hand.updateHands( pos );
// Move Light
if( hand.isStop( time ) && hand.isTrack() ) {
float x = pos.x + width/2;
float y = height/2 - pos.y;
lugve.setPos( x, y );
}
// Move Arduino LED
if( hand.isTrack() ) {
float x = pos.x + width/2;
float y = height/2 - pos.y;
arduino.setPos( x, y );
}
}
void onDestroyHands( int handId,float time ) {
println( "onDestroyHandsCb - handId: " + handId + ", time:" + time );
hand.destroyHands();
}
void onRecognizeGesture( String strGesture, PVector idPosition, PVector endPosition ) {
println( "onRecognizeGesture - strGesture: " + strGesture + ", idPosition: " + idPosition + ", endPosition:" + endPosition );
hand.recognizeGesture( strGesture, idPosition, endPosition );
}
void onProgressGesture( String strGesture, PVector position,float progress ) {
println("onProgressGesture - strGesture: " + strGesture + ", position: " + position + ", progress:" + progress );
}