public void Update() { if (!Enabled) { return; } //Check touches if they are still active if (_myTouch1 != null) { if (_myTouch1.IsRelased()) { LooseTouch1(); } } if (_myTouch2 != null) { if (_myTouch2.IsRelased()) { LooseTouch2(); } } //If second touch is active but first is not, then lets move second to first if (_myTouch2 != null && _myTouch1 == null) { _myTouch1 = _myTouch2; _myTouch2 = null; } //Get new touches if (_myTouch1 == null) { if ((_myTouch1 = InputOptions.MyState.GetBrandNewTouch(false)) != null) { _firstTouchMoved = false; _firstTouchPosition = _myTouch1.Position; _isMyTouch1Mouse = false; } else { //Try get mouse if ((_myTouch1 = InputOptions.MyState.GetPressedMouse(true)) != null) { _firstTouchMoved = false; _firstTouchPosition = _myTouch1.Position; _isMyTouch1Mouse = true; } } } if (_myTouch2 == null && _myTouch1 != null && !_isMyTouch1Mouse) { if ((_myTouch2 = InputOptions.MyState.GetBrandNewTouchBut(_myTouch1)) != null) { //Ready for zooming _zoomTouchesAveragePosition = (_myTouch1.Position + _myTouch2.Position) / 2; _myTouch1.SetAsOwned(); _firstTouchMoved = true; } } if (_myTouch1 != null) { if (_myTouch2 == null) { if (!_firstTouchMoved) { if (Vector2.Distance(_myTouch1.Position, _firstTouchPosition) > _firstTouchMoveDist) { //Start dragging _firstTouchMoved = true; HardAdjustFocusPosition(_myTouch1.Position - _firstTouchPosition); _myTouch1.SetAsOwned(); } } else { // There is only one touch - dragging! HardAdjustFocusPosition(_myTouch1.Move); } } else { // There are two touches - finger zooming! #region Fingerzooming! Vector2 previousDiff = _myTouch1.PreviousTouch.Position - _myTouch2.PreviousTouch.Position; float previousDist = previousDiff.Length(); Vector2 currDiff = _myTouch1.Position - _myTouch2.Position; float currDist = currDiff.Length(); FingerZoom *= currDist / previousDist; if (FingerZoom < CameraOptions.MinZoom) { FingerZoom = CameraOptions.MinZoom; } if (FingerZoom > CameraOptions.MaxZoom) { FingerZoom = CameraOptions.MaxZoom; } Vector2 newAveragePosition = (_myTouch1.Position + _myTouch2.Position) / 2; HardAdjustFocusPosition(newAveragePosition - _zoomTouchesAveragePosition); _zoomTouchesAveragePosition = newAveragePosition; #endregion } } }