Tuesday, May 30, 2006

Well, Im getting there now.

UT2004 sends x, y's and z's to another computer via UDP on port 9000.
Processing recieves the packet communication and converts them into lovely useful floats, whilst ignoring any packets that arent relevant (there are quite a few!).

Heres the processing code that accepts communication and converts to floats.
I used the Carnivore library in the end.


// Uses Carnivore
// Note: requires Carnivore Library for Processing v1.3 (http://rhizome.org/carnivore) (needs winpcap)


import rsg.carnivore.*;
int count3 = 0;
float tempx;
float tempy;
float tempz;
String packettext;
String look = "nextthree";

void setup(){
size(625, 625);
background(255);
Carnivore c = new Carnivore(this);
}

void draw(){

}


void packetEvent(CarniPacket packet){ // Called each time a new packet arrives

packettext = packet.ascii;
int stringlength = packettext.length();

if (stringlength < 19){

String list[] = split(packettext);
//println(list[0]);

if(list[0].equals(look) == true) { //wait for the first signal...
println("here");
count3 = 1;
}else{
if (count3 == 1){
tempx = float(list[0]);
count3 = 2;
println("x = " + tempx);
}else{
if (count3 == 2){
tempy = float(list[0]);
count3 = 3;
println("y = " + tempy);
}else{
if (count3 == 3){
tempz = float(list[0]);
count3 = 0;
println("z = " + tempz);
}
}
}
} //end if else madness

}//end if string length

}//end packetevent

1 Comments:

Anonymous Anonymous said...

i've been wondering for some time: what are you up to? and how far can ut and processing be merged? are there any docs? just some questions :)

4:03 pm  

Post a comment

<< Home