protected void actionMove(MotionEvent event) { if (this.pointerIdCount == 2) { int state = this.getState(); if (state == WorldWind.POSSIBLE) { if (this.shouldRecognize(event)) { this.transitionToState(event, WorldWind.BEGAN); } } else if (state == WorldWind.BEGAN || state == WorldWind.CHANGED) { float distance = this.currentPinchDistance(event); float newScale = Math.abs(distance / this.referenceDistance); this.scale = this.lowPassFilter(this.scale, newScale); this.transitionToState(event, WorldWind.CHANGED); } } }
protected void handlePinch(GestureRecognizer recognizer) { int state = recognizer.getState(); float scale = ((PinchRecognizer) recognizer).getScale(); if (state == WorldWind.BEGAN) { this.gestureDidBegin(); } else if (state == WorldWind.CHANGED) { if (scale != 0) { // Apply the change in scale to the navigator, relative to when the gesture began. this.lookAt.range = this.beginLookAt.range / scale; this.applyLimits(this.lookAt); this.wwd.getNavigator().setAsLookAt(this.wwd.getGlobe(), this.lookAt); this.wwd.requestRedraw(); } } else if (state == WorldWind.ENDED || state == WorldWind.CANCELLED) { this.gestureDidEnd(); } }
protected void prepareToRecognize(MotionEvent event) { this.referenceDistance = this.currentPinchDistance(event); this.scale = 1; }
@Override protected void handlePinch(GestureRecognizer recognizer) { int state = recognizer.getState(); float scale = ((PinchRecognizer) recognizer).getScale(); if (state == WorldWind.BEGAN) { this.gestureDidBegin(); } else if (state == WorldWind.CHANGED) { if (scale != 0) { // Apply the change in scale to the navigator, relative to when the gesture began. scale = ((scale - 1) * 0.1f) + 1; // dampen the scale factor this.camera.altitude = this.camera.altitude * scale; this.applyLimits(this.camera); this.wwd.getNavigator().setAsCamera(this.wwd.getGlobe(), this.camera); this.wwd.requestRedraw(); } } else if (state == WorldWind.ENDED || state == WorldWind.CANCELLED) { this.gestureDidEnd(); } }
protected boolean shouldRecognize(MotionEvent event) { if (event.getPointerCount() != 2) { return false; // require exactly two pointers to recognize the gesture } double distance = this.currentPinchDistance(event); return Math.abs(distance - this.referenceDistance) > this.interpretDistance; }
protected void actionDown(MotionEvent event) { int pointerId = event.getPointerId(event.getActionIndex()); if (this.pointerIdCount < 2) { this.pointerIds[this.pointerIdCount++] = pointerId; // add it to the pointer ID array if (this.pointerIdCount == 2) { this.referenceDistance = this.currentPinchDistance(event); this.scaleOffset *= this.scale; this.scale = 1; } } }