Kinect
※パーツ毎に記述していきます。
==================================================================================
import processing.net.*; //Processingからネットワークを扱いたい時に使うライブラリを宣言
Client myClient; //クライアント側ですよっ。
String line; //文字列を入れるためにlineっていう変数を定義する。
void setup() {
myClient = new Client(this, "localhost", 12345); //コンピュータの中の12345っていう場所でデータをやりとりしますよ。~
}
void draw() {
if(myClient.available() > 0) {
//クライアントが利用できる時。
line = myClient.readString(); //lineに受信したデータを格納します。
}
}
※ここではクラス化してあります。
class Bonenow {
Bonenow() {
String[] pieces = split(line, " ");
if(pieces.length >= 45) {
int headx = int(float(pieces[0])/10); //頭のx座標
int heady = int(float(pieces[1])/10); //頭のy座標
int headz = int(float(pieces[2])/10); //頭のz座標
//45個用意したpiecesって名前の箱(配列)の、
//最初の3つの文字を頭の(x,y,z)として定義します。
println("head(x, y, z) = " + "( " + headx + ", " + heady + ", " + headz + ")");
//定義した座標がどうなってるか自分がわかるようにする。
※この作業を地道に、
頭→
首→
左肩→右肩→
左肘→右肘→
左手→右手→
腰→
左尻→右尻→
左膝→右膝→
左足→右足
とゆう風に定義していきます。
//そしたら定義した数字を、line()で繋ぎ合わせます。
stroke(0);
strokeWeight(3);
line(headx, heady, headz, neckx, necky, neckz); //head-neck
line(leshx, leshy, leshz, rishx, rishy, rishz); //lesh-rish
line(leshx, leshy, leshz, torsx, torsy, torsz); //lesh-tors
line(rishx, rishy, rishz, torsx, torsy, torsz); //rish-tors
line(leshx, leshy, leshz, leelx, leely, leelz); //lesh-leel
line(leelx, leely, leelz, lehax, lehay, leelz); //leel-leha
line(rishx, rishy, rishz, rielx, riely, rielz); //rish-riel
line(rielx, riely, rielz, rihax, rihay, rihaz); //riel-riha
line(torsx, torsy, torsz, lehix, lehiy, lehiz); //tors-lehi
line(torsx, torsy, torsz, rihix, rihiy, rihiz); //tors-rihi
line(lehix, lehiy, lehiz, rihix, rihiy, rihiz); //lehi-rihi
line(lehix, lehiy, lehiz, leknx, lekny, leknz); //lehi-lekn
line(leknx, lekny, leknz, lefox, lefoy, lefoz); //lekn-lefo
line(rihix, rihiy, rihiz, riknx, rikny, riknz); //rihi-rikn
line(riknx, rikny, riknz, rifox, rifoy, rifoz); //rikn-rifo
delay(200);
}
}
}
PrintWriter output; //PrintWriterを宣言
void setup() {
output = createWriter("../Data_play/data/positions.txt"); //positions.txtって名前で保存する。
}
void draw() {
if(myClient.available() > 0) {
//outputに受信したデータを書き込む
output.println(headx + " " + heady + " " + headz + " " + neckx + " " + necky + " " + neckz + " " + leshx + " " + leshy + " " + leshz + " " + rishx + " " + rishy + " " + rishz + " " + leelx + " " + leely + " " + leelz + " " + rielx + " " + riely + " " + rielz + " " + lehax + " " + lehay + " " + lehaz + " " + rihax + " " + rihay + " " + rihaz+ " " + torsx + " " + torsy + " " + torsz + " " + lehix + " " + lehiy + " " + lehiz + " " + rihix + " " + rihiy + " " + rihiz + " " + leknx + " " + lekny + " " + leknz + " " + riknx + " " + rikny + " " + riknz + " " + lefox + " " + lefoy + " " + lefoz + " " + rifox + " " + rifoy + " " + rifoz);
}
}
void keyPressed() {
if(key == 's') {
output.flush(); //ここでぱっと書きこんで
output.close(); //書きこみ終了。
exit(); //もうやることもないんでついでにプログラム自体終了。
}
}