-
Notifications
You must be signed in to change notification settings - Fork 15
/
PointablePoint.pde
176 lines (167 loc) · 4.74 KB
/
PointablePoint.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
class PointablePoint{
ArrayList pointablePath;
PVector p = new PVector(0,0,0);
PVector pp = new PVector(0,0,0); //previous position
int idPointable = 0;
int idHand = 0;
color fgColor = color(255);
String pointType = "pointable";
boolean active = false;
boolean clicked = false;
PointablePoint(int _ip, int _ih, PVector _p, color _c, String _s){
idPointable = _ip;
idHand = _ih;
pointablePath = new ArrayList();
p = _p;
fgColor = _c;
pointType = _s;
}
void update(){
//if(record) pointablePath.add(p);
if(record||showTraces) pointablePath.add(p);
if(sendOsc) sendPointableOsc();
if(sendMidi) sendPointableMidi();
if(pp == p){
active = false;
}else{
active = true;
}
}
void draw(){
//if(debug){
drawDot(p, fgColor, idHand + "-" + idPointable);
drawTraces(pointablePath, color(fgColor,100));
//}
}
void run(){
update();
draw();
}
void sendPointableOsc() {
OscMessage myMessage;
try{
if(oscFormat.equals("Animata")){
myMessage = new OscMessage("/joint");
myMessage.add(pointType + idHand + "-" + idPointable);
myMessage.add(((p.x/sW)*640)+0);
myMessage.add(((p.y/sH)*480)+0);
oscP5.send(myMessage, myRemoteLocation);
}else if(oscFormat.equals("Isadora")){
int a=0;
int b=0;
int c=0;
if(idPointable==0){
a = 4;
b = 5;
c = 6;
}else if(idPointable==1){
a = 7;
b = 8;
c = 9;
}else if(idPointable==2){
a = 10;
b = 11;
c = 12;
}else if(idPointable==3){
a = 13;
b = 14;
c = 15;
}else if(idPointable==4){
a = 16;
b = 17;
c = 18;
}
myMessage = new OscMessage("/isadora/"+getMidiId(a));
myMessage.add(p.x/sW);
oscP5.send(myMessage, myRemoteLocation);
myMessage = new OscMessage("/isadora/"+getMidiId(b));
myMessage.add(p.y/sH);
oscP5.send(myMessage, myRemoteLocation);
myMessage = new OscMessage("/isadora/"+getMidiId(c));
myMessage.add(p.z/sD);
oscP5.send(myMessage, myRemoteLocation);
}else if(oscFormat.equals("OSCeleton")){
myMessage = new OscMessage("/joint");
myMessage.add(pointType + idHand + "-" + idPointable);
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("/" + "finger" + idHand + "-" + idPointable);
myMessage = new OscMessage("/" + pointType + idHand + "-" + idPointable);
myMessage.add(pointType);
myMessage.add(idHand);
myMessage.add(idPointable);
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("/" + "finger" + idHand + "-" + idPointable);
myMessage = new OscMessage("/" + pointType + idHand + "-" + idPointable);
myMessage.add(pointType);
myMessage.add(idHand);
myMessage.add(idPointable);
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 sendPointableMidi(){
try{
int a=0;
int b=0;
int c=0;
if(idPointable==0){
a = 4;
b = 5;
c = 6;
}else if(idPointable==1){
a = 7;
b = 8;
c = 9;
}else if(idPointable==2){
a = 10;
b = 11;
c = 12;
}else if(idPointable==3){
a = 13;
b = 14;
c = 15;
}else if(idPointable==4){
a = 16;
b = 17;
c = 18;
}
sendCtl(getMidiId(a),getMidiVal(p.x,sW));
sendCtl(getMidiId(b),getMidiVal(p.y,sH));
sendCtl(getMidiId(c),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;
}
}