GMU:(In)Visible Networks/Esra Demirel: Difference between revisions

From Medien Wiki
No edit summary
No edit summary
Line 29: Line 29:
communication between Captury System and Processing. <br>
communication between Captury System and Processing. <br>


import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation; // IP of Computer running captury, Port configured in software
long lastMillis=0; // used to periodically send subscribe messages
ArrayList <PVector> joints=new ArrayList <PVector>(); // used to buffer joint positions between oscEvent callbacks and "draw" calls
void setup() {
  fullScreen();
  //size(800, 600);
  oscP5 = new OscP5(this, 1065);
  myRemoteLocation = new NetAddress("141.54.159.160", 1065); // our computer...
}
void draw() {
  // periodically ask the captury server to send us data.
  if (millis()-lastMillis>5000) {
    // The format is as follows:
    //"/subscribe/<Actor_name>/<skeleton_data_type>/<joint_name>/<data_format>"
    //most of the placeholders can be replaced by a "*" for "everything"
    // unfortunately, if you subscribe to too many things, a bug in the captury will lead to malformed OSC-bundles that in turn crash OSCP5
    OscMessage myMessage = new OscMessage("/subscribe/*/blender/Head/vector"); // get positions ("vector") of all joints of actor "felix_braun_rot" in mm
    oscP5.send(myMessage, myRemoteLocation);
  }
  strokeWeight(4); 
  // go through list of joints and draw them all
  frameRate(5);
  fill(101, 50);
  stroke(255, 30);
  background(0);
  for (int i=0; i<joints.size(); i++) {
    //draw everything here
    point(joints.get(i).x/5+width/2, joints.get(i).y/5+height/2);
    line(random(600), random(600), joints.get(i).x/5+width/2, joints.get(i).y/5+height/2);
  }
  joints.clear();
}
/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
  println(theOscMessage); // debug out
  // only use packages that contain position data as three floats
  if (theOscMessage.checkTypetag("fff")) {
    joints.add(new PVector(theOscMessage.get(0).floatValue(), theOscMessage.get(1).floatValue(), theOscMessage.get(2).floatValue()));
    println( theOscMessage.get(0).floatValue());
    println( theOscMessage.get(1).floatValue());
    println( theOscMessage.get(2).floatValue());
  }
}




This Processing Sketch show how OSC protocol is used and how our draw function is inserted inside that protocol.
This Processing Sketch show how OSC protocol is used and how our draw function is inserted inside that protocol.
First of all oscP5 and netP5 libraries are imported inside the sketch.In order to use OSC protocol we have to import those library. There are 3 messages received from Captury, they are x,y,z coordinates of the tracked person locations.
First of all oscP5 and netP5 libraries are imported inside the sketch.In order to use OSC protocol we have to import those library. There are 3 messages received from Captury, they are x,y,z coordinates of the tracked person locations.