1

I am implementing 2-finger-zoom.

2nd finger down - remember finger distance: (done once)

event.getPointerCoords(0, finger1_start);
event.getPointerCoords(1, finger2_start);
start_distance = VecLength(finger1_start, finger2_start);

2 fingers down + ACTION_MOVE

event.getPointerCoords(0, finger1_now);
event.getPointerCoords(1, finger2_now);
double distance_now = VecLength(finger1_now, finger2_now);
zoom = distance_now / start_distance;

VecLength method - returns length of distance between 2 points

double VecLength (MotionEvent.PointerCoords a, MotionEvent.PointerCoords b)
{
    return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));
}

Problem, it jitters when I use view.setScaleX. I zommed in as smoothly as possible using my fingers recording the zoom value in logcat.

Not using view.setScaleX/Y Not using setScalex/y

Using view.setScaleX/Y using setScalex/y

Which proves that I do see the jitter. I narrowed it down to the pointers actually having different coordinates each frame going back/forth.

I assume the scale somehow affects the view, but I don't understand how to undo that. How do I get "raw" finger coordinates or respect the zoom in my calculation?

Not that I cannot use getRawX as this only returns one finger. I obviously need both.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
KYL3R
  • 3,877
  • 1
  • 12
  • 26

1 Answers1

0

It seems I can mostly fix this by multiplying the start distance with the current scale:

So change

event.getPointerCoords(0, finger1_now);
event.getPointerCoords(1, finger2_now);
double distance_now = VecLength(finger1_now, finger2_now);
zoom = distance_now / start_distance;

to

event.getPointerCoords(0, finger1_now);
event.getPointerCoords(1, finger2_now);
double distance_now = VecLength(finger1_now, finger2_now);
zoom = distance_now / start_distance * view.getScaleX(); << x and y scale are the same in my case
KYL3R
  • 3,877
  • 1
  • 12
  • 26