I am working on something where I am rotating a rectangle (drawing it inside a transformation matrix), but I still want to accurately detect mouse clicks on it.
I am thinking that the easiest way is to transform the mouse input to match the transformed output. I am just having troubles getting the correct transformation… I am getting results that seem to be somewhat close, but it’s proving to be a tad tricky to nail down.
here’s my current translateMouseCoords method…
void StencilInstance::translateMouseCoords(int& x, int& y){
float xOff = this->x + this->width/2.0;
float yOff = this->y + this->height/2.0;
float cosT = cos(tiAngleToRadians(-1.0*this->rotation));
float sinT = sin(tiAngleToRadians(-1.0*this->rotation));
x -= xOff;
y -= yOff;
x = x * cosT - y * sinT;
y = y * cosT + x * sinT;
x += xOff;
y += yOff;
}
here’s the draw that does the transform and what not…
void StencilInstance::draw(float x, float y, float w, float h, bool borders){
ofPushMatrix();
ofTranslate(x+w/2.0, y+h/2.0, 0);
ofRotateZ(this->rotation);
ofTranslate((x+w/2.0)*-1.0, (y+h/2.0)*-1.0, 0);
ofRect(x, y, w, h);
ofPopMatrix();
}
wondering if anyone has worked with anything like this or has any other ideas?