IEnumerator followMisalignmentAngle()
        {
            yield return(new WaitForSeconds(2f)); //Wait for system to settle.

            //Something at startup preventing initial view - so we hack it in here.
            observables.PickAlternateImage();
            while (true)
            {
                Vector3 euler = cameraRig.GetEyeAngle(eye);

                float degree = 0;
                if (euler.y >= 180)
                {
                    degree = euler.y - 360;
                }
                else
                {
                    degree = euler.y;
                }

                NetworkManager.instance.SetFloat("degree", degree);
                yield return(new WaitForSeconds(0.5f));
            }
        }
Ejemplo n.º 2
0
        private void StoreAndQuit()
        {
            Vector3 euler = cameraRig.GetEyeAngle(eye);

            Debug.Log("Eye angle (euler) is " + euler + " degrees.");

            if (eye == StereoTargetEyeMask.Left)
            {
                cameraRig.config.leftEyeMisalignmentAngle = euler;
            }
            else
            {
                cameraRig.config.rightEyeMisalignmentAngle = euler;
            }

            //cameraRig.config.Sync();
            SceneManager.LoadScene("Menu");
        }
        void Update()
        {
            // One press to start. Second to stop. Third to (re-)start
            if (Input.GetButtonDown("EyeSkills Confirm") || NetworkManager.instance.GetButton("start") || NetworkManager.instance.GetButton("stop"))
            {
                if (!straightening)
                {
                    ResetEyeMisalignment();
                    straightening = true;
                }
                else if (straightening)
                {
                    straightening = false;
                    // Time to log our new time to the calibration object.
                    // We store the best (least) misalignment the participant achieved as an absolute angle
                    Debug.Log("smallest angle in calibration " + config.leastMisalignmentBeforeFusionLost);
                    Debug.Log("current angle" + currentAngle);

                    if (config.leastMisalignmentBeforeFusionLost > currentAngle)
                    {
                        Debug.Log("Storing least misalignment before fusion lost");
                        config.leastMisalignmentBeforeFusionLost = Mathf.Abs(currentAngle);
                        AudioManager.instance.Say("SavingBestAngle");
                    }
                }
            }

            if (straightening)
            {
                //Debug.Log("Straightening");
                cameraRig.RotateToStraightenEye(eyeMask, turningRate * Time.deltaTime);

                // The least distance we were away from being straight.
                currentAngle = cameraRig.GetEyeAngle(eyeMask).y; //misalignedEye.transform.rotation.eulerAngles.y;
                if (currentAngle > 180)
                {
                    currentAngle = 360 - currentAngle;                     //HACK. Need to think this through more thoroughly.
                }
                //currentAngle = Vector3.Angle(misalignedEye.transform.rotation.eulerAngles, nonMisalignedEye.transform.rotation.eulerAngles).y;
                NetworkManager.instance.SetFloat("degree", currentAngle);
            }
        }
        void Update()
        {
            //TODO : Do not forget these experiences started as a quick experimental hack. They must be completely refactored.

            //Debug.Log("Time still " + still);
            if (!practitionerMode)
            {
                if (chooseCancel.IsCancelled())
                {
                    ResetEyeMisalignment();
                    userWantsStraightening = true;
                }
            }

            //TODO: Confirm (or waiting a specified time, or resetting a given number of times) should exit, but restart/shaking the head should reset the camera - we ought to record each reset within the specified time.
            if (esInput.GetShortButtonPress("EyeSkills Confirm") || NetworkManager.instance.GetButton("store") || NetworkManager.instance.GetButton("start") || chooseCancel.IsCancelled()) //TODO : or SHAKE
            {
                // Time to log our new time to the calibration object.
                // We store the best (least) misalignment the participant achieved as an absolute angle
                if (cameraRig.config.leastMisalignmentBeforeFusionLost > currentAngle)
                {
                    Debug.Log("Storing least misalignment before fusion lost");
                    cameraRig.config.leastMisalignmentBeforeFusionLost = Mathf.Abs(currentAngle);
                    AudioManager.instance.Say("SavingBestAngle");
                }
                Debug.Log("Resetting eye");
                ResetEyeMisalignment();
                userWantsStraightening = true;
            }

            //if (esInput.GetShortButtonPress("EyeSkills Up"))
            //{
            //    AudioManager.instance.Say("BlinkersOn");
            //    blinker1.SetActive(true);
            //    blinker2.SetActive(true);
            //}
            //else if (esInput.GetShortButtonPress("EyeSkills Down"))
            //{
            //    AudioManager.instance.Say("BlinkersOff");
            //    blinker1.SetActive(false);
            //    blinker2.SetActive(false);
            //}

            if (userWantsStraightening)
            {
                //Debug.Log("Straightening");
                cameraRig.RotateToStraightenEye(eyeMask, turningRate * Time.deltaTime);

                // The least distance we were away from being straight.
                currentAngle = cameraRig.GetEyeAngle(eyeMask).y; //misalignedEye.transform.rotation.eulerAngles.y;
                if (currentAngle > 180)
                {
                    currentAngle = 360 - currentAngle; //HACK. Need to think this through more thoroughly.
                }
                //currentAngle = Vector3.Angle(misalignedEye.transform.rotation.eulerAngles, nonMisalignedEye.transform.rotation.eulerAngles).y;
                NetworkManager.instance.SetFloat("degree", currentAngle);
            }


            // Lets just hack the binocular suppression de-escalation to implicitly detect when it's needed
            //Debug.Log("current angle : " + currentAngle);
            if (Mathf.Approximately(currentAngle, 0) && !areRemovingSuppression)
            {
                AudioManager.instance.Say("Straightened");
                Debug.Log("Starting to remove suppression");
                areRemovingSuppression  = true;
                currentSuppressionRatio = originalSuppressionRatio;
            }
            else if (!Mathf.Approximately(currentAngle, 0) && (areRemovingSuppression))
            {
                //the cameras are no longer straight, but we had been manipulating the suppression ratio, so reset it
                Debug.Log("Resetting suppression");
                AudioManager.instance.Say("Resetting");
                cameraRig.SetBinocularSuppressionRatio(originalSuppressionRatio);
                areRemovingSuppression = false;
            }

            if (areRemovingSuppression)
            {
                // Now we need to gradually straighten up the binocular suppression ratio
                if (!Mathf.Approximately(currentSuppressionRatio, 0f))
                {
                    currentSuppressionRatio = currentSuppressionRatio -
                                              (currentSuppressionRatio * suppressionReductionRate * Time.deltaTime);
                    //Debug.Log("Current suppression ratio " + currentSuppressionRatio);
                    cameraRig.SetBinocularSuppressionRatio(currentSuppressionRatio);

                    if (Mathf.Approximately(currentSuppressionRatio, 0f))
                    {
                        AudioManager.instance.Say("SuppressionCompensationRemoved");
                    }
                }
            }
            if (esInput.GetShortButtonPress("EyeSkills Up"))  //Cycle through the available cameras
            {
                int camID = currentCam % phoneCamera.getNumberOfCameras();
                Debug.Log("Trying to choose camera number " + camID);
                phoneCamera.startCamera(camID);
                currentCam += 1;
            }
        }