-
Notifications
You must be signed in to change notification settings - Fork 0
/
Modelling_Based_on_LeapMotion.pde
253 lines (219 loc) · 7.18 KB
/
Modelling_Based_on_LeapMotion.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// Modelling_Based_on_LeapMotion.pde
// Modelling System Based on LeapMiton
//
// Created by yorksero831 on 16/4/13.
// Copyright © 2016年 SakaiLab-York. All rights reserved.
//
import de.voidplus.leapmotion.*;
LeapMotion leap;
String MODE = "OBJECT MODE";
float x = 0;
float y = 0;
float z = 0;
Commands cmd = new Commands();
/////////////////////test////////////
YObject testobj;
YObject testobj1;
/////////////////////////////////////
Selector selector = new Selector();
ArrayList<YObject> List_of_Objects = new ArrayList<YObject>();
PGraphics FLayer;
PGraphics BLayer;
void setup()
{
size(600, 600, P3D);
frameRate(30);
leap = new LeapMotion(this).withGestures();
testobj1 = cmd.Cube(100, 100, 100, 5, 5, 5); //////////Create 5X5X5 cube named testobj1
List_of_Objects.add(testobj1);
selector.Add(testobj1); //////Put testobj into selector
FLayer = createGraphics(width, height, P3D);
BLayer = createGraphics(width, height, P3D);
//////voce system init///////
String url2 = "/Users/sakailab_macbook_B/Downloads/Modelling_Based_on_LeapMotion/";
voce.SpeechInterface.init("/Users/sakailab_macbook_B/Downloads/Modelling_Based_on_LeapMotion/libraries/voce-0.9.1/", true, true, url2, "ss");
}
PVector hand_position_last = new PVector();
float dy = 0;
float dx = 0;
float dz = 0;
///////////////////////sound Text invitital/////////////
String getStringStore = "OBJECT MODE";
void draw()
{
background(200, 200, 200);
BLayer.beginDraw();
BLayer.camera(0, 0, height/2/ tan(PI*30.0 / 180.0), 0, 0, 0, 0, 1, 0);
BLayer.background(0, 0, 0, 0);
//////////////////soundText//////////////////
String getString;
//BLayer.stroke(0);
BLayer.textSize(25);
BLayer.fill(0);
BLayer.text(MODE, -75, -250);
BLayer.fill(255);
////////////////////////////////////////////
if (leap.countHands()>0)
{
Hand hand = leap.getRightHand();
int countHand = leap.countHands();
//int hid = hand.getId();
if (countHand>1)
{
//////////////////////////sound reglize//////////
getString = voce.SpeechInterface.popRecognizedString();
if(getString != "")
{
println(getString);
}
if (getString.equals("point"))
{
MODE = "POINT MODE";
}
if (getString.equals("o"))
{
MODE = "OBJECT MODE";
}
if (getString.equals("select"))
{
cmd.Select_it(MODE, selector, List_of_Objects, hand_position_last.x - 0.5*height, hand_position_last.y -0.5*width, -(hand_position_last.z -15)*10);
}
////////////////////////////////////////////////////////
}
PVector hand_position = hand.getPosition();
dy = hand_position_last.y - hand_position.y;
dx = hand_position_last.x - hand_position.x;
dz = hand_position_last.z - hand_position.z;
PVector zo = hand_position.cross(hand_position_last);
zo.y = 0;
zo.z *=2;
zo.normalize();
//YVector zop = new YVector(-zo.z, -zo.x, 0); //-zo.z , , zo.x
//float angle = sqrt(dx*dx+dy*dy+dz*dz*1)*PI/240;
/////////////////////////////Gesture code///////////////////////////////////////////////
if (hand.hasFingers())
{
ArrayList<Finger> fingers = hand.getFingers();
PVector finger1_position;
PVector finger2_position;
float f1_f2_distance;
if (fingers.size()>=2)
{
Finger f1 = fingers.get(0);
finger1_position = f1.getPosition();
Finger f2 = fingers.get(1);
finger2_position = f2.getPosition();
f1_f2_distance = dist(finger1_position.x,finger1_position.y,finger1_position.z,finger2_position.x,finger2_position.y,finger2_position.z);
if(f1_f2_distance<=13)
{
cmd.Select_it(MODE, selector, List_of_Objects, hand_position_last.x - 0.5*height, hand_position_last.y -0.5*width, -(hand_position_last.z -15)*10);
}
}
if (fingers.size()==1)
{
cmd.Move(MODE, selector, -dx, -dy, dz*10);
}
if (fingers.size()==2)
{
YVector zop_x = new YVector(1, 0, 0);
YVector zop_y = new YVector(0, 1, 0);
YVector zop_z = new YVector(0, 0, 1);
float angle_x = dx*PI/240;
float angle_y = dy*PI/240;
float angle_z = dz*PI/240;
cmd.Rotate_it(selector, zop_x, -angle_y);
cmd.Rotate_it(selector, zop_y, angle_x);
cmd.Rotate_it(selector, zop_z, angle_z);
}
}
/////////////////////////////testCode//////////////////////////////////////////////////
if (keyPressed)
{
if (key == '1')
{
MODE = "OBJECT MODE";
println(MODE);
}
if (key == '2')
{
MODE = "POINT MODE";
println(MODE);
}
if (key == 'm' || key == 'M')
{
cmd.Move(MODE, selector, -dx, -dy, dz*10);
}
if (key == 'r' || key == 'R')
{
YVector zop_x = new YVector(1, 0, 0);
YVector zop_y = new YVector(0, 1, 0);
YVector zop_z = new YVector(0, 0, 1);
float angle_x = dx*PI/240;
float angle_y = dy*PI/240;
float angle_z = dz*PI/240;
cmd.Rotate_it(selector, zop_x, -angle_y);
cmd.Rotate_it(selector, zop_y, angle_x);
cmd.Rotate_it(selector, zop_z, angle_z);
}
if (key == 's' || key == 'S')
{
cmd.Select_it(MODE, selector, List_of_Objects, hand_position_last.x - 0.5*height, hand_position_last.y -0.5*width, -(hand_position_last.z -15)*10);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
BLayer.strokeWeight(22);
BLayer.strokeCap(ROUND);
BLayer.stroke(0, 111, 0);
BLayer.point(hand_position_last.x - 0.5*height, hand_position_last.y -0.5*width, -(hand_position_last.z -15)*10);
for(Finger finger : hand.getFingers())
{
PVector finger_position = finger.getPosition();
//int finger_id = finger.getId();
BLayer.strokeWeight(11);
BLayer.stroke(111,0,0);
BLayer.point(finger_position.x - 0.5*height,finger_position.y -0.5*width,-(finger_position.z -15)*10);
}
hand_position_last = hand_position;
}
//println(dy);
beginCamera();
camera(0, 0, height/2/ tan(PI*30.0 / 180.0), 0, 0, 0, 0, 1, 0);
endCamera();
draw_objects(List_of_Objects, BLayer, selector);
selector.Draw_Selected_Object(MODE, FLayer, BLayer);
BLayer.endDraw();
image(BLayer, -0.5*width, -0.5*height);
image(FLayer, -0.5*width, -0.5*height); ////////////////////////////////draw_pivot_layer;
//box(100);
}
void mouseWheel(MouseEvent event)
{
}
///////////////////////////////////////////Commands
void draw_objects(ArrayList<YObject> List_of_Objects, PGraphics BLayer, Selector selector)
{
int i = 0;
int j = 0;
BLayer.beginShape(QUADS);
BLayer.strokeWeight(1);
BLayer.stroke(0, 0, 0);
for (i=0; i<List_of_Objects.size (); i++)
{
int flag = 0;
YObject temp = new YObject(List_of_Objects.get(i));
//println(temp.Id);
for ( j =0; j<selector.Selected_Object.size (); j++)
{
if (temp.Id == selector.Selected_Object.get(j).Id)
{
flag =1;//
break;
}
}
if (flag!=1)
{
temp.DrawFaces(BLayer);
}
}
BLayer.endShape();
}