GMU:Human and Nonhuman Performances II SS16/Group FLL: Difference between revisions

From Medien Wiki
No edit summary
Line 77: Line 77:
[[File:ChineseKnotDemo.jpg|thumb|left|500px|Chinese knot demo]]
[[File:ChineseKnotDemo.jpg|thumb|left|500px|Chinese knot demo]]
<br style="clear:both;">
<br style="clear:both;">
Here is the code running in Processing:
Main Tab:
<source lang="Java" line start= "1">
import netP5.*;
import oscP5.*;
import processing.video.*;
OscP5 osc;
NetAddress remote;
Movie myMovie;
int localport = 12000;
int remoteport = 1065;
boolean debug = true;
Sphere sphere1;
String skeleton1 = "LiQianqian";
String bone1 = "Root";
String bone2 = "LeftHand";
String bone3 = "RightHand";
int depth;
void setup() {
  frameRate(60);
  background(0);
  myMovie = new Movie(this, "Chinese Knot_Final.mov");
  fullScreen(P3D);
 
  sphere1 = new Sphere(1);
  depth = width;
 
  osc = new OscP5(this, localport);
  remote = new NetAddress("kosmos.medien.uni-weimar.de", remoteport);
  setPort(localport);
  plugBone(sphere1, skeleton1, bone1);
  plugBone(sphere1, skeleton1, bone2);
  plugBone(sphere1, skeleton1, bone3);
 
  refreshSubscriptions();
}
void refreshSubscriptions() {
  subscribeBone(skeleton1, bone1);
  subscribeBone(skeleton1, bone2);
  subscribeBone(skeleton1, bone3);
}
void movieEvent(Movie m) {
  m.read();
}
void draw() {
  sphere1.draw();
  if (frameCount % 10 == 0) {
    refreshSubscriptions();
  }
}
void oscEvent(OscMessage msg) {
  if(debug) {
    print("### received an osc message.");
    print(" addrpattern: "+msg.addrPattern());
    println(" typetag: "+msg.typetag());
  }
}
void plugBone(Object target, String skeleton, String bone) {
  String path =  "/" + skeleton + "/blender/" + bone + "/vector";
  osc.plug(target, "update" + bone, path);
}
void setPort(int port) {
  OscMessage msg = new OscMessage("/configure/port");
  msg.add(port);
  osc.send(msg, remote);
}
void subscribeBone(String skeletonId, String bone) {
  OscMessage msg = new OscMessage("/subscribe/" + skeletonId + "/blender/" + bone + "/vector");
  msg.add(50.0);
  msg.add(0.0);
  msg.add(100.0);
  osc.send(msg, remote);
}
</source>
Sphere Tab:
<source lang="Java" line start= "10">
class Sphere {
  float x, y, z;
  float x1, y1, z1;
  float x2, y2, z2;
  float x3, y3, x4, y4;
 
  float a, b, cc;
  float a1, b1, cc1;
  float a2, b2, cc2;
  float a3, b3, a4, b4;
 
  float d, e, f;
  float d1, e1, f1;
  float d2, e2, f2;
  float d3, e3, d4, e4;
 
  float speedChange, speedChange1, VideoSpeed;
  int play;
  color c;
 
  int getLength() {
      return int(myMovie.duration() * myMovie.frameRate);
  }
 
  int getFrame() {   
      return ceil(myMovie.time() * 60) - 1;
  }
 
  int newFrame = 0;
   
  Sphere( color c) {
    this.c = c;
  }
  void draw() {
    image(myMovie, 0, 0, width, height);
   
    if(speedChange > 0.3 && getFrame() < 599){
      play = 1;
      myMovie.play();
    }
    else {
      play = -1;
      myMovie.play();
    }
   
    if(getFrame() < 0) myMovie.play();
   
    float newSpeed = map(speedChange1, 0, 150, 0*play, 2*play);
    myMovie.speed(newSpeed);
   
    fill(255);
    x4 = abs(x2 - x3);
    y4 = abs(y2 - y3);
    speedChange = abs(x4 - y4);
    println(speedChange);
    text("Root Speed: " + nfc(speedChange, 2) + "X", 10, 30);
    x3 = x2;
    y3 = y2;
   
    speedChange1 = dist(a, b, cc, d, e, f);
    text("Hand Distance: " + nfc(speedChange1, 2), 10, 50); 
   
    VideoSpeed = speedChange1*play;
    text("VideoSpeed: " + nfc(VideoSpeed, 2) + "X", 10, 70);
   
    text(getFrame() + " / " + (getLength() - 1), 10, 90);
  }
  public void updateRoot(float x, float y, float z) {
    this.x = map(x, 0, 100, -width/2, width/2);
    this.y = map(y, -100, 100, -height/2, height/2);
    this.z = map(z, 0, 100, 0, depth);
   
    x2 = abs(x - x1);
    y2 = abs(y - y1);
    z2 = abs(z - z1);
   
    x1 = this.x;
    y1 = this.y;
    z1 = this.z;
  }
 
  public void updateLeftHand(float a, float b, float cc) {
    this.a = map(a, 0, 100, -width/2, width/2);
    this.b = map(b, -100, 100, -height/2, height/2);
    this.cc = map(cc, 0, 100, 0, depth);
   
    a2 = abs(a - a1);
    b2 = abs(b - b1);
    cc2 = abs(cc - cc1);
   
    a1 = this.a;
    b1 = this.b;
    cc1 = this.cc;
  }
 
  public void updateRightHand(float d, float e, float f) {
    this.d = map(d, 0, 100, -width/2, width/2);
    this.e = map(e, -100, 100, -height/2, height/2);
    this.f = map(f, 0, 100, 0, depth);
   
    d2 = abs(d - d1);
    e2 = abs(e - e1);
    f2 = abs(f - f1);
   
    d1 = this.d;
    e1 = this.e;
    f1 = this.f;
  }
}
</source>


'''Interaction with Objects'''
'''Interaction with Objects'''