// // to start osceleton streaming from command line // ./osceleton -w -a 192.168.0.45 -i simpleloop.oni import processing.opengl.*; import oscP5.*; import netP5.*; OscP5 oscP5, oscP5Send; NetAddress myRemoteLocation; PaperDoll[] dolls; int NUM_DOLLS = 4; float MILLIS_PER_FRAME = 33.3333333; int [] jointTypes = new int[23]; float zoomF =0.5f; float rotX = radians(180); // by default rotate the whole scene 180deg around the x-axis, // the data from openni comes upside down float rotY = radians(0); int framenum =0; boolean drawDoll=true; boolean drawDollTexture=false; boolean drawDollOutline=true; boolean drawSticks=true; boolean drawMarkers=true; boolean drawTextCoords=false; boolean sendOSC=true; boolean printOSC=false; boolean printCoords=false; int lasttime=0, thistime; final int CLEAR_DELAY=200; boolean heartOn=false; boolean paused=false; int ballSize = 10; Hashtable skels = new Hashtable(); ArrayList skFrames[] = (ArrayList[]) new ArrayList[NUM_DOLLS]; int rec_id=0; boolean recording=false; int xoffset[] = { -400, -100, 100, 400 }; boolean showlive=true; float speed = 0.4; void setup() { //size(800, 600, OPENGL); //Keep 4/3 aspect ratio, since it matches the kinect's. size(1280, 800, OPENGL); //noCursor(); oscP5 = new OscP5(this, "127.0.0.1", 7110); //oscP5 = new OscP5(this, "192.168.0.231", 7110); oscP5Send = new OscP5(this, 12000); // max/MSP on leo's computer //myRemoteLocation = new NetAddress("127.0.0.1", 7400 ); //myRemoteLocation = new NetAddress("192.168.0.127", 7400 ); myRemoteLocation = new NetAddress("169.254.102.159", 7400 ); textFont(createFont("Verdana", 24)); //hint(ENABLE_OPENGL_4X_SMOOTH); noStroke(); dolls = new PaperDoll[NUM_DOLLS]; println(dolls.length); // cut paper animation for (int i=0;i0)) { if((i==rec_id) && recording) { framenum=skFrames[i].size()-1; } else { if(!paused) framenum=(int(millis()/MILLIS_PER_FRAME))%(skFrames[i].size()); } Skeleton s = (Skeleton) skFrames[i].get(framenum); // if (drawMarkers) { // //s.drawSticks(xoffset[i]); // pushMatrix(); // //translate(xoffset[i], 0, 0); // //scale(width, height, -300.0); // fill(255, 255, 0); // strokeWeight(10); // stroke(128, 128, 0); // s.drawDots(xoffset[i]); // //s.drawDots(0); // popMatrix(); // } if (drawDoll || drawSticks) { // draw doll pushMatrix(); scale(width, height, -300.0); dolls[rec_id].calcScreenCoords(s); //dolls[rec_id].printScreenCoords(); popMatrix(); if (drawSticks) { pushMatrix(); translate(xoffset[i], 0, 0); dolls[rec_id].drawOSCeleton(); popMatrix(); } dolls[rec_id].constrainCoords(); if(sendOSC) dolls[rec_id].sendCoords(rec_id); if (drawDoll) { pushMatrix(); translate(xoffset[i], 0, 0); dolls[rec_id].drawDoll(); if(printCoords) dolls[rec_id].printConstrainedCoords(); popMatrix(); } } } } else { fill(128); text("recording", 20, 120); } } fill(128); text("character "+(rec_id+1), 20, 30); if (skFrames[rec_id]!=null) text("frames "+skFrames[rec_id].size(), 20, 60); //text("speed "+String.format("%.2g%n", speed), 20, 90); // heartlight if(sendOSC) sendHeartBeat(); } void sendHeartBeat() { OscMessage myMessage = new OscMessage("/heartlight"); //myMessage.add(i); if(heartOn) { myMessage.add(1.0); /* add an int to the osc message */ } else { myMessage.add(0.0); } heartOn=!heartOn; /* send the message */ oscP5Send.send(myMessage, myRemoteLocation); } void keyPressed() { switch(key) { case 'r': recording = !recording; // thistime=millis(); // if(thistime-lasttime0) // skFrames[rec_id].clear(); // println("erased all frames"); // } // lasttime=thistime; if (recording) { if (skFrames[rec_id]==null) skFrames[rec_id] = new ArrayList(); print("start recording to buffer "); println(rec_id); } else { print("done recording. loop has "); print(skFrames[rec_id].size()-1); println(" frames."); } break; case 'c': if(skFrames[rec_id].size()>0) skFrames[rec_id].clear(); println("erased all frames"); break; case 'n': recording=false; rec_id=(rec_id+1)%skFrames.length; break; case 'l': showlive=!showlive; break; case 'd': drawDoll=!drawDoll; break; case 'm': drawMarkers=!drawMarkers; break; case 't': drawTextCoords=!drawTextCoords; break; case ' ': paused=!paused; break; case 'p': printCoords=!printCoords; break; // case '+': // speed+=0.01; // break; // case '-': // speed-=0.01; // break; } switch(keyCode) { case LEFT: xoffset[rec_id]-=10; break; case RIGHT: // zoom out xoffset[rec_id]+=10; break; } }