Particle program not detecting mousepress


#1

Hello, I’m trying to implement functionality that makes the particles move away from the mouse when the mouse is pressed. I’ve added the following function directly after the keyPressed() function in the main sketch:

void mousePressed() 
{
    mouseLoc = ofPoint(ofGetMouseX(), ofGetMouseY(), 0);
    for (std::size_t i = 0; i < particles.size(); i++)
    {
        ofPoint dir = mouseLoc - particles[i].position;
        dir.normalize();
        dir*-1;
        particles[i].acceleration = dir;
    }
    
    cout << "mousePressed" << endl;
}

I’m trying to check it with the cout but that’s not returning anything the console so I don’t think it’s detecting the mousepress. Can someone help me identify what I’m doing wrong?


#2

Think maybe you need to use void mousePressed(int x, int y, int button) {…}


#3

You’re right – thanks for pointing that out to me. Definitely still retaining some tendencies from Processing.