Пример #1
0
        private void NormalizePosAndRot(Vector3 focusPosition, float zoom, ref Vector3 pos, ref Quaternion rot)
        {
            float tiltTarget;

            if (MobileTouchCamera.EnableZoomTilt)
            {
                float zoomProgress = Mathf.Clamp01((zoom - MobileTouchCamera.CamZoomMin) / (MobileTouchCamera.CamZoomMax - MobileTouchCamera.CamZoomMin));
                tiltTarget = Mathf.Lerp(MobileTouchCamera.ZoomTiltAngleMin, MobileTouchCamera.ZoomTiltAngleMax, zoomProgress);
            }
            else
            {
                tiltTarget = MobileTouchCamera.GetCurrentTileAngleDeg();
            }
            float   tiltTargetRadian  = Mathf.Deg2Rad * tiltTarget;
            Vector3 right             = MobileTouchCamera.Transform.right;
            Vector3 camForwardOnPlane = Vector3.Cross(MobileTouchCamera.RefPlane.normal, right);

            pos = focusPosition + camForwardOnPlane * zoom * Mathf.Cos(tiltTargetRadian) + MobileTouchCamera.RefPlane.normal * zoom * Mathf.Sin(tiltTargetRadian);
            Vector3   forward = (focusPosition - pos).normalized;
            Vector3   up      = Vector3.Cross(forward, right);
            Matrix4x4 matrix  = new Matrix4x4(right, up, forward, new Vector4(0, 0, 0, 1));

            rot = matrix.rotation;
            MobileTouchCamera.Transform.rotation = rot;
            Vector3 intersectionScreenFocusEnd  = MobileTouchCamera.GetIntersectionPoint(MobileTouchCamera.Cam.ScreenPointToRay(new Vector3(Screen.width * focusScreenPos.x, Screen.height * focusScreenPos.y, 0)));
            Vector3 intersectionScreenCenterEnd = MobileTouchCamera.GetIntersectionPoint(MobileTouchCamera.Cam.ScreenPointToRay(new Vector3(Screen.width * 0.5f, Screen.height * 0.5f, 0)));

            pos += (intersectionScreenCenterEnd - intersectionScreenFocusEnd);

            MobileTouchCamera.CamZoom = zoom;
        }
        private void KeepinCenter(Vector3 targetPosition, Quaternion targetRotation, float targetZoom)
        {
//			Debug.Log ("target zoom "+ targetZoom);
            timeTransitionStart = Time.time;
            posTransitionStart  = Transform.position;
            rotTransitionStart  = Transform.rotation;
            zoomTransitionStart = MobileTouchCamera.CamZoom;
            rotTransitionEnd    = targetRotation;
            zoomTransitionEnd   = targetZoom;



            MobileTouchCamera.Transform.rotation = targetRotation;
            MobileTouchCamera.CamZoom            = targetZoom;
            Vector3 intersectionScreenCenterEnd = MobileTouchCamera.GetIntersectionPoint(MobileTouchCamera.Cam.ScreenPointToRay(new Vector3(Screen.width * 0.5f, Screen.height * 0.5f, 0)));
            Vector3 focusVector = targetPosition - intersectionScreenCenterEnd;

            posTransitionEnd = MobileTouchCamera.GetClampToBoundaries(posTransitionStart + focusVector, true);
            MobileTouchCamera.Transform.rotation = rotTransitionStart;
            MobileTouchCamera.CamZoom            = zoomTransitionStart;

            if (Mathf.Approximately(transitionDuration, 0))
            {
                SetTransform(posTransitionEnd, targetRotation, targetZoom);
                return;
            }

            isTransitionStarted = true;
        }
Пример #3
0
        public void FocusCameraOnTarget(Vector3 targetPosition, Quaternion targetRotation, float targetZoom)
        {
            timeTransitionStart = Time.time;
            posTransitionStart  = Transform.position;
            rotTransitionStart  = Transform.rotation;
            zoomTransitionStart = MobileTouchCamera.CamZoom;
            rotTransitionEnd    = targetRotation;
            zoomTransitionEnd   = targetZoom;

            MobileTouchCamera.CamZoom            = targetZoom;
            MobileTouchCamera.Transform.rotation = targetRotation;
            Vector3 intersectionScreenCenterEnd = MobileTouchCamera.GetIntersectionPoint(MobileTouchCamera.Cam.ScreenPointToRay(new Vector3(Screen.width * focusScreenPos.x, Screen.height * focusScreenPos.y, 0)));
            Vector3 focusVector = targetPosition - intersectionScreenCenterEnd;

            posTransitionEnd = posTransitionStart + focusVector;

            NormalizePosAndRot(targetPosition, targetZoom, ref posTransitionEnd, ref rotTransitionEnd);


            posTransitionEnd = MobileTouchCamera.GetClampToBoundaries(posTransitionEnd, true);

            MobileTouchCamera.Transform.rotation = rotTransitionStart;
            MobileTouchCamera.CamZoom            = zoomTransitionStart;

            if (Mathf.Approximately(transitionDuration, 0))
            {
                SetTransform(posTransitionEnd, rotTransitionEnd, zoomTransitionEnd);
                return;
            }

            isTransitionStarted = true;
        }