I'm developing a ViewGroup layout which is able to detect touch events and scale/rotate/pan it's child view based on touch events. My problem is that I would like the child to rotate/zoom around the point between the user's fingers two fingers, performing the gesture, not around its center.
I've got the gesture recognizers in place and I am already able to scale/pan/rotate around the center of the child. I think the main issue is transforming the pivot point (which in my case would be the midpoint between the user's first and second pointers) to the child's current rotation. The first time I set the pivot, it works nicely, but as soon as I rotate the view, lift fingers and then try to rotate around another pivot, the view jumps around. Here's how it looks (only with rotation):
So when the first rotation happens it works as expected and it rotates around the point between the two fingers. However, once rotated, the next rotation jumps to a new location. Here's the relevant code:
@Override
public boolean onRotationBegin(RotationGestureDetector detector) {
float[] coordinates = screenPointsToScaledPoints(new float[]{detector.getFocusX(), detector.getFocusY()});
pivotX = coordinates[0];
pivotY = coordinates[1];
child().setPivotX(pivotX);
child().setPivotY(pivotY);
return true;
}
@Override
public boolean onRotate(RotationGestureDetector detector) {
rotation += detector.getRotationDelta();
return true;
}
private float[] screenPointsToScaledPoints(float[] a){
mRotateMatrixInverse.mapPoints(a);
return a;
}
private void applyScaleAndTranslation() {
View child = child();
child.setRotation(rotation);
mRotateMatrix.setRotate(rotation, pivotX, pivotY);
mRotateMatrix.invert(mRotateMatrixInverse);
}
Any ideas what I could be missing?
invert()
ed matrix – pskinkinvert
because I'm actually tracking single touch events and need to have their coordinates because I'm making a drawing app, where you can move the canvas around. If you post that link as an answer I can mark it as accepted and post what I did as a separate answer :) – Georgitransform()
ed by the current matrix (or i missed your point ;-( ), also feel free to auto answer... – pskink