5.3 OSC Processing

import oscP5.*;
import netP5.*;


OscP5 osc0;
OscP5 osc1;

OscP5 oscP5;
NetAddress myRemoteLocation;

ArrayList  pos1 = new ArrayList();
ArrayList  pos2 = new ArrayList();

///camera varibles
int oldx = mouseX;
int oldy = mouseY;
float rotx = 0;
float roty = 0;
float zcam = 0;

float travel = 5;


void setup() {
  size(1600, 1000, P3D);
  
  oscP5 = new OscP5(this,6880);
  myRemoteLocation = new NetAddress("192.168.1.165",12000);
  
  pos1.add(new PVector(0,0,0));

}

void draw() {
  background(0);
  
  pushMatrix();
  cam();
  
  PVector fp;
  PVector lp;
  
  /*PVector lastp =  pos1.get(pos1.size()-1);
  float newx = random(-travel,travel) + lastp.x;
  float newy = random(-travel,travel) + lastp.y;
  float newz = random(-travel,travel) + lastp.z;
  
  pos1.add(new PVector(newx,newy,newz));*/
  
  stroke(255);
  
  if(pos1.size() > 0){
    for(int i = 0; i < pos1.size()-1; i++){ 
      fp = pos1.get(i); 
      lp = pos1.get(i+1); 
      line( fp.x,fp.y,fp.z,lp.x,lp.y,lp.z); 
    } 
    lp = pos1.get(pos1.size()-1); 
    OscMessage myMessage = new OscMessage("/points1");   
    myMessage.add(lp.x); 
    myMessage.add(lp.y); 
    myMessage.add(lp.z); 
    oscP5.send(myMessage, myRemoteLocation); 
   } 

  if(pos2.size() > 0){ 
    for(int i = 0; i < pos2.size()-1; i++){
      fp =  pos2.get(i);
      lp =  pos2.get(i+1);
      line( fp.x,fp.y,fp.z,lp.x,lp.y,lp.z);
    }
    
    lp =  pos2.get(pos2.size()-1);
    OscMessage myMessage = new OscMessage("/points2");
    myMessage.add(lp.x);
    myMessage.add(lp.y);
    myMessage.add(lp.z);
     
    oscP5.send(myMessage, myRemoteLocation);
  }
  
  popMatrix();

   
}

void cam() {
  int newx = mouseX;
  int newy = mouseY;
  translate(width/2, height/2,zcam);
  rotateY(rotx);
  rotateX(roty);
  //rotateZ(PI);
  if ((mousePressed == true)) {
    rotx = rotx + (oldx-newx)/50.0;
    roty = roty + (oldy-newy)/50.0;
  }
  oldx = newx;
  oldy = newy;
}

void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  zcam = zcam - e*5;
}


/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
  println(theOscMessage);
  if(theOscMessage.checkAddrPattern("/p1")==true) {
      float x = theOscMessage.get(0).floatValue();
      float y = theOscMessage.get(1).floatValue();
      float z = theOscMessage.get(2).floatValue();

      pos1.add(new PVector(x,y,z));
   }
   
   if(theOscMessage.checkAddrPattern("/p2")==true) {
      float x = theOscMessage.get(0).floatValue();
      float y = theOscMessage.get(1).floatValue();
      float z = theOscMessage.get(2).floatValue();
      pos2.add(new PVector(x,y,z));
   }
   
   return;
}