The above sketch shows the approximate size of LEEDS Studio in millimeters. Here is a base sketch with LEEDS studio in 3D and OSC Message integrated into the sketch: LEEDS_Base_Sketch
Below is a break down of the various elements of the sketch.
This is the main setup() and draw() functions of the sketch. The setup() functioncalls a function to create the CUI and starts the oscP5 listenign object. The draw() function draws a line through the stored positions of the marker being tracked and draws a point at its current postion.
import oscP5.*;
import netP5.*;
import controlP5.*;
//List to store positions of marker
ArrayList <PVector> trace = new ArrayList <PVector>();
//LEEDs dimensions in mm
float roomw = 12000;
float roomd = 7800;
float roomh = 3000;
/*port number to listen to. Make sure the port number in
Vicon Tracker is set to this*/
int Port_Number = 12000;
void setup() {
//size(1200, 800, P3D);
fullScreen(P3D);
perspective(PI/3.0,(float)width/height,1,100000);
/* start oscP5, listening for incoming messages at port number */
oscP5 = new OscP5(this,Port_Number);
//call function to create the GUI
controls();
}
void draw(){
background(0);
PVector newpos1;
PVector newpos2;
if(trace.size() > 2){
newpos1 = trace.get(trace.size()-1);
newpos2 = trace.get(trace.size()-2);
//distance between the last two points gives you the speed magnitude
float dd = dist(newpos1.x,newpos1.y,newpos1.z,newpos2.x,newpos2.y,newpos2.z);
//show the latest speed in the sketch
textSize(15);
fill(255);
text("SPEED: "+ dd, 30, height-40);
}
pushMatrix();
//call camera function
cam();
//room toggel is on then draw the room
if(room_on){
room(roomw,roomd,roomh);
}
stroke(0,255,255);
strokeWeight(2);
//draw lines between all of the stored postions of the tracked marker
for(int i = 0; i < trace.size()-1; i++){
newpos1 = trace.get(i);
newpos2 = trace.get(i+1);
stroke(255,0,0);
line(newpos1.x,newpos1.y,newpos1.z,newpos2.x,newpos2.y,newpos2.z);
}
//draw a point at the latest position of the marker
stroke(0,255,255);
strokeWeight(10);
point(Marker1_position.x,Marker1_position.y,Marker1_position.z);
popMatrix();
}
This is the standard camera function we have been using.
///camera varibles
int oldx = mouseX;
int oldy = mouseY;
float rotx = 0;
float roty = PI/2.0;
float zcam = -7800;
float rotxdelta = 0;
void cam() {
int newx = mouseX;
int newy = mouseY;
translate(width/2, height/2+roomh/2.0,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;
if(rotate_on == true){
rotx = rotx+ 0.005;
}
}
void mouseWheel(MouseEvent event) {
float e = event.getCount();
zcam = zcam - e*35;
}
This function sets up the contrils for the GUI.
ControlP5 cp5;
boolean room_on = true;
boolean rotate_on = true;
void controls(){
cp5 = new ControlP5(this);
cp5.addToggle("rotate_on")
.setPosition(40,40)
.setSize(20,20)
.setValue(false)
.setColorForeground(color(120,120,120))
.setColorLabel(color(255))
.setColorBackground(color(70,70,70))
.setColorValue(color(0,0,0))
.setColorActive(color(150,150,150))
;
cp5.addToggle("room_on")
.setPosition(40,80)
.setSize(20,20)
.setValue(true)
.setColorForeground(color(120,120,120))
.setColorLabel(color(255))
.setColorBackground(color(70,70,70))
.setColorValue(color(0,0,0))
.setColorActive(color(150,150,150))
;
}
This is the fucntion that listens for incoming OSC data from Vicon Tracker.
//initialize OscP5 object for listening to the OSC stream
OscP5 oscP5;
/* Address pattern of a specific marker */
String Marker1_address = "/vicon/marker/Wood Block/Wood Block1";
/* Address pattern of a specific marker */
String Marker2_address = "/vicon/marker/Object/Object2";
PVector Marker1_position = new PVector(0,0,0);
/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
/*find the message for a particular marker in the osc message*/
if(theOscMessage.checkAddrPattern(Marker1_address)==true) {
/* parse theOscMessage and extract the values from the osc message arguments. */
float XPOS = theOscMessage.get(0).floatValue();
float YPOS = theOscMessage.get(1).floatValue();
float ZPOS = theOscMessage.get(2).floatValue();
Marker1_position = new PVector(XPOS,YPOS,ZPOS);
trace.add(Marker1_position);
}
if(theOscMessage.checkAddrPattern(Marker2_address)==true) {
/* parse theOscMessage and extract the values from the osc message arguments. */
float XPOS = theOscMessage.get(0).floatValue();
float YPOS = theOscMessage.get(1).floatValue();
float ZPOS = theOscMessage.get(2).floatValue();
println(XPOS);
}
}
This function draws the room as a wireframe.
//function to draw the room
void room(float w, float d, float h){
stroke(255);
strokeWeight(1);
noFill();
beginShape();
vertex(-d/2, -w/2,0);
vertex(d/2, -w/2,0);
vertex(d/2, w/2,0);
vertex(-d/2, w/2,0);
vertex(-d/2, -w/2,0);
endShape();
beginShape();
vertex(-d/2, -w/2,h);
vertex(d/2, -w/2,h);
vertex(d/2, w/2,h);
vertex(-d/2, w/2,h);
vertex(-d/2, -w/2,h);
endShape();
beginShape();
vertex(d/2, -w/2,h);
vertex(d/2, -w/2,0);
vertex(d/2, w/2,0);
vertex(d/2, w/2,h);
vertex(d/2, -w/2,h);
endShape();
beginShape();
vertex(-d/2, -w/2,h);
vertex(-d/2, -w/2,0);
vertex(-d/2, w/2,0);
vertex(-d/2, w/2,h);
vertex(-d/2, -w/2,h);
endShape();
}
