2.3 Processing Tracker OSC Gen

Here is a processing sketch that creates dummy OSC in the same structure as the OSC sent from Vicon Tracker. You can download the processing file here OSC_Gen or copy the code below and run it in processing. The port number is 12000 and the IP address is 127.0.0.1 which is a special-purpose IPv4 address that calls localhost. This will allow you to run it on your computer and also look for OSC at the same IP address. The number of markers is set to 7 but you can change this in the second line of the code through the variable “numpts.”

You will also need to install the oscP5 library which is in the Processing contribution manager. You can open the the contribution manager by selecting Sketch>Import Library>Add Library in the menu at the top of processing. Search of oscP5 and then press install located in the lower right of the manager.

//IP address is 127.0.0.1
//change port # below
int portnum = 12000;
//change the number of markers below
int numpts = 7;

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

FloatList theta = new FloatList();
FloatList phi = new FloatList();
FloatList radius = new FloatList();

float tadd;
float tnoise = random(1000);
float padd;
float pnoise = random(1000);

float xadd;
float xnoise = random(1000);
float yadd;
float ynoise = random(1000);
float zadd;
float znoise = random(1000);

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

void setup(){
  size(600,600,P3D);
  perspective(PI/3.0,(float)width/height,1,100000);
  
  oscP5 = new OscP5(this,6000);
  
  myRemoteLocation = new NetAddress("127.0.0.1",portnum);
  
  for(int i = 0; i < numpts; i++){
    theta.append(random(PI*2));
    phi.append(random(PI*2));
    radius.append(random(5,80));
  }
}

void draw(){
  background(0);
  
  tadd = map(noise(tnoise),0,1,-1,1)*PI;
  tnoise = tnoise + 0.005;
  
  padd = map(noise(pnoise),0,1,-1,1)*PI;
  pnoise = pnoise + 0.005;
  
  xadd = map(noise(xnoise),0,1,-1,1)*3600;
  xnoise = xnoise + 0.005;
  
  yadd = map(noise(ynoise),0,1,-1,1)*6000;
  ynoise = ynoise + 0.005;
  
  zadd = map(noise(znoise),0,1,0,1)*3000;
  znoise = znoise + 0.005;
  
  cam();
  
  OscMessage myMessage = new OscMessage("/vicon/frame");
  myMessage.add(frameCount);
  myMessage.add(100);
  
  for(int i = 0; i < theta.size(); i++){
    float s = phi.get(i) + padd;
    float t = theta.get(i) + tadd;
    float r = radius.get(i);
    float posx = r * cos(s) * sin(t) + xadd;
    float posy = r * sin(s) * sin(t) + yadd;
    float posz = r * cos(t) + zadd;
    stroke(0,255,255);
    strokeWeight(5);
    point(posx,posy,posz);
    myMessage.add("/vicon/marker/Object/Object" + i);
    myMessage.add(posx);
    myMessage.add(posy);
    myMessage.add(posz);
  }
  
  oscP5.send(myMessage, myRemoteLocation); 
  
}

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;
  println(zcam);
}