Hi!
Im a CG animator and Im learning a little of scripting to improve my skills. I was wondering if someone know how to get the x and y values of a XY Pad, using oscP5. (https://vimeo.com/14734980)
I don’t have idea of which methods should I need to use to get this result, I started with these lines, but I think that something is missing, in order to separate the x and y and send
import oscP5.*;
import netP5.*;
OscP5 oscP5;
float posx = 0;
float posy= 0;
void setup() {
frameRate(25);
/* start oscP5, listening for incoming messages at port 8000 */
oscP5 = new OscP5(this, 8000);
oscP5.plug(this, "positionx", "/1/xy2");
oscP5.plug(this, "positiony", "/1/xy2");
This program prints the message info and arguments to the console. You can use that same program (changing the ports maybe) to see what you receive from your XY pad. Maybe you are receiving two integers, or two floats, or a string…
The Processing IDE has an Examples menu, inside File. All the libraries you install normally come with examples, which appear under Contributed Libraries inside the Examples menu. Processing comes with hundreds of examples for you to learn from.
void Pad() {
OscMessage msg = new OscMessage("/1/xy2");
oscP5.send(msg, self);
// even if there's a global xval variable
// the following line creates a local temporary variable
// that gets deleted at the end of this function
float xval= msg.get(0).floatValue();
// Also, it's reading an osc argument out of a message
// which was just SENT (instead of reading such an argument
// from a received message below)
}
void oscEvent(OscMessage msg) {
println(msg);
println(msg.arguments());
// the following line is printing a global variable called xval
// which probably contains nothing
println(xval);
// what you probably want is to place the data received by this
// function into the global variable xval, like this:
xval= msg.get(0).floatValue();
// if you added float at the beginning of the previous line,
// the variable would be a local variable, and the content lost
// at the end of this function
}