I have been experimenting rotating components using a slider control and dragging them afterwards.
The components are rotated around their centres as expected and everything is well, the problem is, after the object is dragged to a different position rotating them using a slider will throw them off wildly. I understand it is happening because after the object has been dragged the rotation centre of its matrix is still bound to the previous location.
I tried resetting the transform matrix using this bit of code:
void reinitRotation(float radians) { float top = getY(); float left = getX(); float w = getWidth()*.5; float h = getHeight()*.5; setTransform(AffineTransform::rotation(radians, left + w, top + h)); repaint(); }
However it does not work as expected because the values the getPosition() returns also appear to be transformed, so the new matrix is no better. The object continues to rotate around its centre, the problem is, it changes its position in a strange manner. Using getBoundsInParent() instead of getPosition() for some strange reason does not seem to work either.
The question is, how do I reset the transform matrix to be centred at object's new location?