Beispiel #1
0
 /// <summary>
 /// Recalibrates the center position.
 /// </summary>
 public void CalibrateCameraPosition()
 {
     Debug.Log("<color=orange>TBCameraRig: Recentering camera...</color>", gameObject);
     #if RIFT || GEAR_VR
     OVRManager.display.RecenterPose();
     #elif STEAM_VR
     StartCoroutine(TBHMDSettings.CalibrateSteamVR());
     #elif MORPHEUS || DAYDREAM || CARDBOARD
     TBHMDSettings.CalibrateNativeCamera();
     #endif
 }
Beispiel #2
0
        void Awake()
        {
            instance  = this;
            transform = GetComponent <Transform> ();

            TBHMDSettings.InitializeHMDSettings();

            // Choose which camera we should be using based on what platform we're on.
            ChooseCamera();

            if (cameraObject != gameObject)
            {
                cameraObject.transform.parent        = transform;
                cameraObject.transform.localPosition = Vector3.zero;
                cameraObject.transform.localRotation = Quaternion.identity;
            }

            switch (cameraMode)
            {
            case TBCameraMode.Single:                 // For fancy systems that only show one camera in Unity, like the native integrations.
                centerCamera = centerEye.GetComponent <Camera> ();
                SyncCameraSettings(centerCamera);
                break;

            case TBCameraMode.Dual:                   // For legacy systems that use two cameras in the editor.
                leftCamera  = leftEye.GetComponent <Camera> ();
                rightCamera = rightEye.GetComponent <Camera> ();
                SyncCameraSettings(leftCamera);
                SyncCameraSettings(rightCamera);
                break;
            }

            #if UNITY_EDITOR
            // Setup the screenshot camera. If no screenshot camera already exists, try to create one.
            if (FindObjectOfType <TBScreenshotCamera>() != null)
            {
                TBScreenshotCamera = FindObjectOfType <TBScreenshotCamera>();
            }
            else if (TBScreenshotCamera != null)
            {
                TBScreenshotCamera = Instantiate(TBScreenshotCamera).gameObject.GetComponent <TBScreenshotCamera>();
            }

            // Apply settings to the screenshot camera if it was created.
            if (TBScreenshotCamera != null)
            {
                _screenshotCamera = TBScreenshotCamera.gameObject.GetComponent <Camera>();
                SyncCameraSettings(_screenshotCamera);
                TBScreenshotCamera.transform.position = transform.position;
                TBScreenshotCamera.transform.rotation = transform.rotation;
                TBScreenshotCamera.gameObject.SetActive(false);
            }
            #endif

            // Create TBCenter, the anchor transfom to use if you need to get the camera's position.
            TBCenter = new GameObject().transform;
            TBCenter.gameObject.name = "TBCenter";
            TBCenter.MakeZeroedChildOf(centerEye.transform);

            // If there is no audio listener on the instantiated camera, add one to TBCenter.
            if (GetComponentInChildren <AudioListener>() == null)
            {
                TBCenter.gameObject.AddComponent <AudioListener>();
            }

            if (recenterOnLoad)
            {
                CalibrateCameraPosition();
            }
        }