Mouse position && object position

hi…
i have this situation. n object on the screen (the objects are simple of rect) and when i pass with the mouse on one of these it happens somethings. i have a problem becaouse when the mouse passes on one of these nothing happen… i have implement all in this way:

void testApp::update(){
for(int i=0; i<num; i++){
      if((punto[i])->mouse(mouseX, mouseY)){
              cout<<"ok"<<endl;
            }
        }
}

where the funciont mouse is:

bool Punto::mouse(float a, float b){
ofVec2f getLocTemp(getLoc());
if((a= getLocTemp.x) && ( b= getLocTemp.y)){
        return true;
    }else
        return false;
}

and getLoc()

const ofVec2f & Punto::getLoc() const{
    return loc;
}

thankss

Hey @ciso, two things:

One, the condition from your if statement if((a= getLocTemp.x) && (b= getLocTemp.y)) should be if((a == getLocTemp.x) && (b == getLocTemp.y)). a=5 is an assignment statement whereas a==5 is a statement that compares a and 5 to see if they are equal.

Two, you mention that the objects on the screen are rectangles. If you want to check if the mouse is inside of your rectangle, you don’t just want to compare the mouse x and y to your object’s x and y position. If you are using ofRectangle instances, check out the inside(...) method (link to documentation). (If you are using rotated rectangles, you’ll need a little extra math.)