Data_read
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
[[Kinect]]~
【Data_read.pde】の解説~
※パーツ毎に記述していきます。~
-プログラムの構成~
①サーバ経由でKinectからデータを受信する~
②受信した数字の羅列を分解、再定義~
③【s】ボタンで受信したデータをpositions.txtに保存~
=========================================================...
* ①サーバ経由でKinectからデータを受信する[#r842de3c]
import processing.net.*; //Processingからネットワークを扱...
Client myClient; //クライアント側ですよっ。~
String line; //文字列を入れるためにlineっていう変数を定義...
~
void setup() {~
myClient = new Client(this, "localhost", 12345); //コン...
}~
~
void draw() {
if(myClient.available() > 0) {
//クライアントが利用できる時。
line = myClient.readString(); //lineに受信したデータ...
}
}
-参考リンク
--[[readString():http://processing.org/reference/librarie...
--[[string:http://processing.org/reference/String.html]]~
* ②受信した数字の羅列を分解、再定義[#r842de3c]
※ここではクラス化してあります。~
class Bonenow {
Bonenow() {
String[] pieces = split(line, " ");
//データが、"10 30 440 40 40 440..."のようにスペースで区...
if(pieces.length >= 45) {
//鬱陶しいことに、分解したデータが必ずしも45個とは限らな...
//変なスペースなんかが二つ入ってたりすることもあるのです。~
//だから、データが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 + ", " + ...
//定義した座標がどうなってるか自分がわかるようにす...
※この作業を地道に、~
頭→~
首→~
左肩→右肩→~
左肘→右肘→~
左手→右手→~
腰→~
左尻→右尻→~
左膝→右膝→~
左足→右足~
とゆう風に定義していきます。~
//そしたら定義した数字を、line()で繋ぎ合わせます。
stroke(0);
strokeWeight(3);
line(headx, heady, headz, neckx, necky, neckz); //...
line(leshx, leshy, leshz, rishx, rishy, rishz); //...
line(leshx, leshy, leshz, torsx, torsy, torsz); //...
line(rishx, rishy, rishz, torsx, torsy, torsz); //...
line(leshx, leshy, leshz, leelx, leely, leelz); //...
line(leelx, leely, leelz, lehax, lehay, leelz); //...
line(rishx, rishy, rishz, rielx, riely, rielz); //...
line(rielx, riely, rielz, rihax, rihay, rihaz); //...
line(torsx, torsy, torsz, lehix, lehiy, lehiz); //...
line(torsx, torsy, torsz, rihix, rihiy, rihiz); //...
line(lehix, lehiy, lehiz, rihix, rihiy, rihiz); //...
line(lehix, lehiy, lehiz, leknx, lekny, leknz); //...
line(leknx, lekny, leknz, lefox, lefoy, lefoz); //...
line(rihix, rihiy, rihiz, riknx, rikny, riknz); //...
line(riknx, rikny, riknz, rifox, rifoy, rifoz); //...
delay(200); //200ミリ秒(=0.2秒)、プログラムの実行...
}
}
}
-参考リンク~
--[[配列:http://processing.org/reference/Array.html]]~
--[[split():http://processing.org/reference/split_.html]]~
--[[int:http://processing.org/reference/int.html]]~
--[[if:http://processing.org/reference/if.html]]~
--[[length:http://processing.org/reference/String_length_...
--[[>=(以上):http://processing.org/reference/greaterthano...
--[[int():http://processing.org/reference/int_.html]]~
--[[float:http://processing.org/reference/float.html]]~
--[[stroke():http://processing.org/reference/stroke_.html...
--[[strokeWeight():http://processing.org/reference/stroke...
--[[line():http://processing.org/reference/line_.html]]~
--[[delay():http://processing.org/reference/delay_.html]]~
* ③【s】ボタンで受信したデータをpositions.txtに保存[#r842...
PrintWriter output; //PrintWriterを宣言
void setup() {
output = createWriter("../Data_play/data/positions.txt"...
}
void draw() {
if(myClient.available() > 0) {
//outputに受信したデータを書き込む
output.println(headx + " " + heady + " " + headz + " ...
}
}
void keyPressed() {
if(key == 's') {
output.flush(); //ここでぱっと書きこんで
output.close(); //書きこみ終了。
exit(); //もうやることもないんでついでにプログラム自...
}
}
-参照リンク
--[[PrintWriter:http://processing.org/reference/PrintWrit...
--[[void keyPressed:http://processing.org/reference/keyPr...
--[[exit():http://processing.org/reference/exit_.html]]
[[Data_play]]はコチラ~
終了行:
[[Kinect]]~
【Data_read.pde】の解説~
※パーツ毎に記述していきます。~
-プログラムの構成~
①サーバ経由でKinectからデータを受信する~
②受信した数字の羅列を分解、再定義~
③【s】ボタンで受信したデータをpositions.txtに保存~
=========================================================...
* ①サーバ経由でKinectからデータを受信する[#r842de3c]
import processing.net.*; //Processingからネットワークを扱...
Client myClient; //クライアント側ですよっ。~
String line; //文字列を入れるためにlineっていう変数を定義...
~
void setup() {~
myClient = new Client(this, "localhost", 12345); //コン...
}~
~
void draw() {
if(myClient.available() > 0) {
//クライアントが利用できる時。
line = myClient.readString(); //lineに受信したデータ...
}
}
-参考リンク
--[[readString():http://processing.org/reference/librarie...
--[[string:http://processing.org/reference/String.html]]~
* ②受信した数字の羅列を分解、再定義[#r842de3c]
※ここではクラス化してあります。~
class Bonenow {
Bonenow() {
String[] pieces = split(line, " ");
//データが、"10 30 440 40 40 440..."のようにスペースで区...
if(pieces.length >= 45) {
//鬱陶しいことに、分解したデータが必ずしも45個とは限らな...
//変なスペースなんかが二つ入ってたりすることもあるのです。~
//だから、データが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 + ", " + ...
//定義した座標がどうなってるか自分がわかるようにす...
※この作業を地道に、~
頭→~
首→~
左肩→右肩→~
左肘→右肘→~
左手→右手→~
腰→~
左尻→右尻→~
左膝→右膝→~
左足→右足~
とゆう風に定義していきます。~
//そしたら定義した数字を、line()で繋ぎ合わせます。
stroke(0);
strokeWeight(3);
line(headx, heady, headz, neckx, necky, neckz); //...
line(leshx, leshy, leshz, rishx, rishy, rishz); //...
line(leshx, leshy, leshz, torsx, torsy, torsz); //...
line(rishx, rishy, rishz, torsx, torsy, torsz); //...
line(leshx, leshy, leshz, leelx, leely, leelz); //...
line(leelx, leely, leelz, lehax, lehay, leelz); //...
line(rishx, rishy, rishz, rielx, riely, rielz); //...
line(rielx, riely, rielz, rihax, rihay, rihaz); //...
line(torsx, torsy, torsz, lehix, lehiy, lehiz); //...
line(torsx, torsy, torsz, rihix, rihiy, rihiz); //...
line(lehix, lehiy, lehiz, rihix, rihiy, rihiz); //...
line(lehix, lehiy, lehiz, leknx, lekny, leknz); //...
line(leknx, lekny, leknz, lefox, lefoy, lefoz); //...
line(rihix, rihiy, rihiz, riknx, rikny, riknz); //...
line(riknx, rikny, riknz, rifox, rifoy, rifoz); //...
delay(200); //200ミリ秒(=0.2秒)、プログラムの実行...
}
}
}
-参考リンク~
--[[配列:http://processing.org/reference/Array.html]]~
--[[split():http://processing.org/reference/split_.html]]~
--[[int:http://processing.org/reference/int.html]]~
--[[if:http://processing.org/reference/if.html]]~
--[[length:http://processing.org/reference/String_length_...
--[[>=(以上):http://processing.org/reference/greaterthano...
--[[int():http://processing.org/reference/int_.html]]~
--[[float:http://processing.org/reference/float.html]]~
--[[stroke():http://processing.org/reference/stroke_.html...
--[[strokeWeight():http://processing.org/reference/stroke...
--[[line():http://processing.org/reference/line_.html]]~
--[[delay():http://processing.org/reference/delay_.html]]~
* ③【s】ボタンで受信したデータをpositions.txtに保存[#r842...
PrintWriter output; //PrintWriterを宣言
void setup() {
output = createWriter("../Data_play/data/positions.txt"...
}
void draw() {
if(myClient.available() > 0) {
//outputに受信したデータを書き込む
output.println(headx + " " + heady + " " + headz + " ...
}
}
void keyPressed() {
if(key == 's') {
output.flush(); //ここでぱっと書きこんで
output.close(); //書きこみ終了。
exit(); //もうやることもないんでついでにプログラム自...
}
}
-参照リンク
--[[PrintWriter:http://processing.org/reference/PrintWrit...
--[[void keyPressed:http://processing.org/reference/keyPr...
--[[exit():http://processing.org/reference/exit_.html]]
[[Data_play]]はコチラ~
ページ名: