Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How could I use a function from different class?

$
0
0

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");
 }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles