본문 바로가기
NOTE/SaveSource

[SaveSource] Touch Pinch Zoom

by DevAthena 2016. 10. 14.


/* touch pinch zoom */
        if (Input.touchCount == 2)
        {
            touchZero   = Input.GetTouch(0);
            touchOne    = Input.GetTouch(1);

            touchZeroPrevPos    = touchZero.position - touchZero.deltaPosition;
            touchOnePrevPos     = touchOne.position - touchOne.deltaPosition;

            prevTouchDeltaMag   = (touchZeroPrevPos - touchOnePrevPos).magnitude;
            touchDeltaMag       = (touchZero.position - touchOne.position).magnitude;

            deltaMagnitudeDiff  = prevTouchDeltaMag - touchDeltaMag;

            if (Camera.main.orthographic)
            {
                Camera.main.orthographicSize    += deltaMagnitudeDiff * orthoZoomSpeed;
                Camera.main.orthographicSize    = Mathf.Max(Camera.main.orthographicSize, 0.1f);
            }
            else
            {
                Camera.main.fieldOfView         += deltaMagnitudeDiff * perspectiveZoomSpeed;
                Camera.main.fieldOfView         = Mathf.Clamp(Camera.main.fieldOfView, 10f, 90f);
            }
        }

- 모바일 환경에서 멀티터치로 핀치 줌 / 아웃을 하는 것

- Mathf.Clamp(현재, 최소, 최대);



'NOTE > SaveSource' 카테고리의 다른 글

[Source Save] TouchCameraMove.cs  (0) 2016.10.31
[Source Save] InputTouchManager.cs  (0) 2016.10.27
[SaveSource] Drag Script  (0) 2016.10.14
[SaveSource] Player Cam & Input.Axis  (0) 2016.10.07
[SaveSource] GyroScope Camera  (0) 2016.10.06