-
Notifications
You must be signed in to change notification settings - Fork 15
/
HandPoint.pde
140 lines (130 loc) · 4.08 KB
/
HandPoint.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
class HandPoint {
int numFingers = 5;
int numOrigins = numFingers;
int numTools = numFingers;
int idActive = 0;
int idHand = 0;
color fgColor = color(0, 0, 255);
String pointType = "hand";
boolean active = false;
boolean clicked = false;
PointablePoint[] fingerPoints = new PointablePoint[numFingers];
PointablePoint[] toolPoints = new PointablePoint[numTools];
PointablePoint[] originPoints = new PointablePoint[numOrigins];
ArrayList handPath;
PVector pStart = new PVector(0,0,0);
PVector p = new PVector(0,0,0);
PVector pp = new PVector(0,0,0); //previous position
HandPoint(int _ih, PVector _p) {
idHand = _ih;
pStart = _p;
p = pStart;
handPath = new ArrayList();
for(int i=0;i<numOrigins;i++){
originPoints[i] = new PointablePoint(i,idHand, p, color(255, 50), "origin");
}
for (int i=0;i<numFingers;i++) {
fingerPoints[i] = new PointablePoint(i,idHand, p, color(255, 0, 0), "finger");
}
for (int i=0;i<numTools;i++) {
toolPoints[i] = new PointablePoint(i,idHand, p, color(0, 255, 0), "tool");
}
}
void update() {
//if(record) handPath.add(p);
if(record||showTraces) handPath.add(p);
if(sendOsc) sendHandOsc();
if(sendMidi) sendHandMidi();
if(pp == p){
active = false;
}else{
active = true;
}
}
void draw() {
//if(debug){
drawDot(p, fgColor, ""+idHand);
drawTraces(handPath, color(fgColor,100));
//}
}
void run() {
update();
draw();
}
void sendHandOsc() {
OscMessage myMessage;
try{
if(oscFormat.equals("Animata")){
myMessage = new OscMessage("/joint");
myMessage.add("hand" + idHand);
myMessage.add(((p.x/sW)*640)+0);
myMessage.add(((p.y/sH)*480)+0);
oscP5.send(myMessage, myRemoteLocation);
}else if(oscFormat.equals("Isadora")){
myMessage = new OscMessage("/isadora/"+getMidiId(1));
myMessage.add(p.x/sW);
oscP5.send(myMessage, myRemoteLocation);
myMessage = new OscMessage("/isadora/"+getMidiId(2));
myMessage.add(p.y/sH);
oscP5.send(myMessage, myRemoteLocation);
myMessage = new OscMessage("/isadora/"+getMidiId(3));
myMessage.add(p.z/sD);
oscP5.send(myMessage, myRemoteLocation);
}else if(oscFormat.equals("OSCeleton")){
myMessage = new OscMessage("/joint");
myMessage.add("hand" + idHand);
myMessage.add(idHand);
myMessage.add(p.x/sW);
myMessage.add(p.y/sH);
myMessage.add(p.z/sD);
oscP5.send(myMessage, myRemoteLocation);
}else if(oscFormat.equals("OldManos")){
myMessage = new OscMessage("/" + "hand" + idHand);
myMessage.add(pointType);
myMessage.add(idHand);
if(centerMode){
myMessage.add((2.0*(p.x/sW))-1.0);
myMessage.add((2.0*(p.y/sH))-1.0);
myMessage.add((2.0*(p.z/sD))-1.0);
}else{
myMessage.add(p.x/sW);
myMessage.add(p.y/sH);
myMessage.add(p.z/sD);
}
oscP5.send(myMessage, myRemoteLocation);
}else{ //default
myMessage = new OscMessage("/" + "hand" + idHand);
myMessage.add(pointType);
myMessage.add(idHand);
myMessage.add(idActive);
if(centerMode){
myMessage.add((2.0*(p.x/sW))-1.0);
myMessage.add((2.0*(p.y/sH))-1.0);
myMessage.add((2.0*(p.z/sD))-1.0);
}else{
myMessage.add(p.x/sW);
myMessage.add(p.y/sH);
myMessage.add(p.z/sD);
}
oscP5.send(myMessage, myRemoteLocation);
}
}catch(Exception e){ }
}
void sendHandMidi(){
try{
sendCtl(getMidiId(1),getMidiVal(p.x,sW));
sendCtl(getMidiId(2),getMidiVal(p.y,sH));
sendCtl(getMidiId(3),getMidiVal(p.z,sD));
}catch(Exception e){ }
}
int getMidiId(int id){
int returns = int((idHand*18)+id);
return returns;
}
int getMidiVal(float _x, float _sw){
int returns = int((_x/_sw)*127.0);
if(returns<0) returns = 0;
if(returns>127) returns = 127;
return returns;
}
}