Question about mouse2DTransformations library

I was hoping to use this library, but I must be doing something wrong. Can someone let me know what I am not doing right?

The idea is that clicking on the slider bar changes its color, but it only works when clicking on the rectangle’s pre-pushMatrix() position. (it starts out horizontal and is simply rotated 90 degrees.)

// mouseOnPathPositionAsPercent
import mouse.transformed2D.*;
MouseTransformed mouse = new MouseTransformed(this);

Slider slider;
PVector m;
void setup() {
  size(800, 480);
  slider = new Slider();
}

void draw() {
  background(0, 0, 255);
  m = new PVector(mouseX, mouseY);
  slider.display();
}
void mousePressed() {
  if (slider.isOver() == true) {
    slider.fillColor = 50;
  }
}
void mouseReleased() {
  slider.fillColor = 255;
}
class Slider {
  PVector loc, dims, xyMin, xyMax;
  float angle;
  int fillColor;
  Slider() {
    loc = new PVector(width/2, height/2);
    dims = new PVector(300, 75);
    xyMin = new PVector(loc.x - dims.x/2, loc.y - dims.y/2);
    xyMax = new PVector(loc.x + dims.x/2, loc.y + dims.y/2);
    angle = 90;
    fillColor = 255;
  }
  boolean isOver() {
    if (mouse.mouseX() > xyMin.x && mouse.mouseY() > xyMin.y && 
      mouse.mouseX() < xyMax.x && mouse.mouseY() < xyMax.y) {
      return true;
    } else {
      return false;
    }
  }
  void display() {
    mouse.pushMatrix();
    mouse.translate(loc.x, loc.y);
    mouse.rotate(radians(angle));
    fill(fillColor);
    rectMode(CENTER);
    rect(0, 0, dims.x, dims.y);
    mouse.popMatrix();
  }
}

Well, i‘m not really sure what should exactly be different, But you could try adding println(„“) before and after and Printing the Position of the Rect and the mouse and See if they are where they should really be, or if something goes wrong. And if, then where? You can find that by just println(„position1“,mX,mY,rectX,rectY) or 2 and so on for each println you have.

Thanks. It looks like maybe reason this isn’t working is because the xyMin xyMax values I’m using in isOver() aren’t updated along with the translation. I’m not sure how to make that happen.

Ah yes… Thats definetly it :sweat_smile: I can‘t Seen to find where the angle of the Slider actually is changed, But in there you should also rotate and translate the xyMin and xyMax values :sweat_smile:

I came across this library in a post on the old forum when I was having trouble making a slider that could be rotated, so that what that is for. I was having so much trouble with it that I disabled the rotation until I could get it working with just a basic translation.

I was able to get this to work, thanks for the advice.

1 Like