We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I am quite new to Prcoessing and I am stuck on using functions from a class to another function. I basically want to use 'void update' in 'void oscEvent(OscMessage theOscMessage' to send update function to OSC. Hope my problem makes sense :(
here is the code:
void draw() {
background(0);
for (Particle p : particles) {
p.update();
}
}
class Particle {
PVector position, velocity;
void update() {
PVector mouse = new PVector(map(mouseX, 0, width, -width / 2, width / 2), map(mouseY, 0, height, -height / 2, height / 2), 0);
PVector acc = PVector.sub(mouse, position);
acc.limit(FULL_ACC);
velocity.add(acc);
velocity.limit(FULL_VEL);
position.add(velocity);
}
void oscEvent(OscMessage theOscMessage) {
if (theOscMessage.checkAddrPattern("/output_1")==true) {
update(); //problem is here, what is the proper way in order for the OSC to pick up this info?
println("mouseMoved");
} else if (theOscMessage.checkAddrPattern("/output_2")==true) {
update();
println("mouseMoved");
} else if (theOscMessage.checkAddrPattern("/output_3") == true) {
update();
println("mouseMoved");
} else {
println("Unknown OSC message received");
}
}
}
Answers
Use ctrl-t for better indents
Just say particle.update();
hi, thanks for getting back! I tried your method but it gave me an error stating "Cannot make a static reference to the non-static update() "
particle (with a small letter not a capital) was an example for an object
You need to put in your object particles[i] when it’s an array etc
this is key. the code you posted is missing several }s which changes the whole meaning of the code. where does draw() end? is update() part of Particle class?
Hi, I apologise for the messy code. I fixed the curly brackets. Also, yes the update() is part of Particle class. Hope it makes more sense to you! Thanks
position & velocity!
final PVector position = new PVector(), velocity = new PVector();
.new
.If you really wanna insist on keeping oscEvent() as a Particle method, a possible workaround is to call each instance of Particle from within PApplet::oscEvent(), passing the received OscMessage object to each 1 of them: :ar!
http://Sojamo.de/libraries/oscp5/examples/oscP5message/oscP5message.pde
Hi, @GoToLoop thank you so much for your wonderful ideas. I tried all of them if it could make any sense to me. The project itself is longer than the one I posted above and the OSC message helps to send data to Wekinator (machine learning application). The particles can be controlled through Arduino sensor, which then the gestures are trained at Wekinator. So, I'm thinking Void oscEvent will send Particles through OSC message? Would it possible for you to look at the whole code?
sorry for being a nuisance, but I really want this to work :( Thanks
Sorry, I don't have the hardware neither know much about the oscP5 library. :-<
My answers were simply about what were obvious from what you had posted so far. :-\"
@hsawa post your entire code please
What gotoloop is saying is that the function oscEvent won't work inside the class because it works only on the level of the sketch and not in a class.
(This would also apply to the function mousePressed())
A workaround would be to have the function oscEvent outside the class and pass its action into the class as he has demonstrated.
a
this won't work:
instead use e.g. (see gotoloop's post above)
OR
and in the function
action
in the class you receive the parameteract
and can act accordingly :@Chrisir thank you so much!! It worked perfectly!, I was able to train the gestures as well through machine learning. I can't thank you enough. Thank you everyone :)
Great !