Beispiel #1
0
        void Update()
        {
            print("update");
            // Exit Sample
            if (Input.GetKey(KeyCode.Escape))
            {
                Application.Quit();
#if UNITY_EDITOR
                UnityEditor.EditorApplication.isPlaying = false;
#endif
            }

            // Hide and lock cursor when right mouse button pressed
            if (Input.GetMouseButtonDown(1))
            {
                Cursor.lockState = CursorLockMode.Locked;
            }

            // Unlock and show cursor when right mouse button released
            if (Input.GetMouseButtonUp(1))
            {
                Cursor.visible   = true;
                Cursor.lockState = CursorLockMode.None;
            }

            // Rotation
            if (Input.GetMouseButton(1))
            {
                var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1));

                var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude);

                m_TargetCameraState.yaw   += mouseMovement.x * mouseSensitivityFactor;
                m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor;
            }
            var     translation = GetInputTranslationDirection() * Time.deltaTime;
            Vector3 camcur      = m_TargetCameraState.GetCurrentCamera();
            if (flag_w == false)
            {
                if (flag_update != false && array1[0] != 0)
                {
                    prev_x = array1[0];
                    prev_y = array1[1];
                    prev_w = array1[2];
                    flag_w = true;
                }
                else
                {
                    flag_update = true;
                }
            }
            // Translation
            if (flag_w == true)
            {
                diff_x = (array1[0] - prev_x);
                diff_y = (array1[1] - prev_y);
                diff_z = (array1[2] - prev_w);
                //save the current position
                prev_x   = array1[0];
                prev_y   = array1[1];
                prev_w   = array1[2];
                usemax_x = Math.Abs(diff_x) > Math.Abs(diff_y) ? (Math.Abs(diff_x) > Math.Abs(diff_z) ? true : false) : false;
                usemax_y = Math.Abs(diff_y) > Math.Abs(diff_x) ? (Math.Abs(diff_y) > Math.Abs(diff_z) ? true : false) : false;
                usemax_z = Math.Abs(diff_z) > Math.Abs(diff_x) ? (Math.Abs(diff_z) > Math.Abs(diff_y) ? true : false) : false;
                if (usemax_x)
                {
                    print("x Max");
                    ratio_x = 100; ratio_y = 500; ratio_z = 500;
                }
                else if (usemax_y)
                {
                    print("y Max");
                    ratio_x = 500; ratio_y = 100; ratio_z = 500;
                }
                else if (usemax_z)
                {
                    print("z Max");
                    ratio_x = 500; ratio_y = 500; ratio_z = 100;
                }
                if (Math.Abs(diff_x) > 10 || Math.Abs(diff_y) > 10 || Math.Abs(diff_z) > 10)
                {
                    m_TargetCameraState.SetCurrentCamera(diff_x / ratio_x, diff_y / ratio_y, diff_z / ratio_z /**/);
                }
            }

            // Speed up movement when shift key held
            if (Input.GetKey(KeyCode.LeftShift))
            {
                translation *= 10.0f;
            }

            // Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel)
            boost += Input.mouseScrollDelta.y * 0.2f;
            //translation *= Mathf.Pow(2.0f, boost);
            translation = translation / 5000;
            m_TargetCameraState.Translate(translation);

            // Framerate-independent interpolation
            // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time
            var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime);
            var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime);
            m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct);

            m_InterpolatingCameraState.UpdateTransform(transform);
        }