void RotateToFaceForward()
    {
        FoveEyeCamera ec  = mainCamera.GetComponent <FoveEyeCamera>();
        var           eul = new Vector3(0f, 180f, 0f);

        transform.rotation = Quaternion.Euler(0f, eul.y - ec.transform.rotation.eulerAngles.y, 0f);
    }
        public void SetCamera(EFVR_Eye whichEye, FoveEyeCamera cam)
        {
            switch (whichEye)
            {
            case EFVR_Eye.Left:
                left = cam;
                break;

            case EFVR_Eye.Right:
                right = cam;
                break;
            }
        }
        public bool CanUseCamera(EFVR_Eye whichEye, FoveEyeCamera cam)
        {
            switch (whichEye)
            {
            case EFVR_Eye.Left:
                return(left == null || left == cam);

            case EFVR_Eye.Right:
                return(right == null || right == cam);
            }

            return(false);
        }
Ejemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        var leftEyeCam = GameObject.Find("FOVE Eye (Left)");

        leftEyeCamera = leftEyeCam.GetComponent <FoveEyeCamera>();

        theSourceFile = new FileInfo(gazeFilePath);
        reader        = theSourceFile.OpenText();
        text          = reader.ReadLine(); // skip first line
        lastData      = new string[] { "-1.0" };

        eventController.SetEventTypesForDebug(getCueTypes());
        //eventController.SetEventTypesForDebug(new List<string>(new string[] { "ARROW_FOLLOW", "ARROW_FOLLOW", "ARROW_FOLLOW", "ARROW_FOLLOW", "ARROW_FOLLOW", "ARROW_FOLLOW" }));
    }
    private static FoveCameraPair GetNextLayerPair(EFVR_Eye whichEye, FoveEyeCamera cam)
    {
        if (whichEye != EFVR_Eye.Left && whichEye != EFVR_Eye.Right)
        {
            return(null);
        }

        foreach (var pair in _layerCameraPairs)
        {
            if (pair.CanUseCamera(whichEye, cam))
            {
                return(pair);
            }
        }

        var p = new FoveCameraPair(cam._compositor, cam.foveInterfaceBase);

        _layerCameraPairs.Add(p);

        return(p);
    }
        public FoveCameraPair(FVRCompositor compositor, FoveInterfaceBase xface)
        {
            left  = null;
            right = null;

            var createInfo = new SFVR_CompositorLayerCreateInfo
            {
                alphaMode         = EFVR_AlphaMode.Auto,
                disableDistortion = xface.DistortionDisabled,
                disableTimewarp   = xface.TimewarpDisabled,
                disableFading     = xface.FadingDisabled,
                type = xface.LayerType
            };

            var err = compositor.CreateLayer(createInfo, out layer);

            if (err != EFVR_ErrorCode.None)
            {
                Debug.LogError("[FOVE] Error getting layer: " + err);
            }

            Debug.Log("[FOVE] Layer requested no distortion? " + createInfo.disableDistortion);
        }
        private void UpdateCameraSettings(GameObject cameraObject, FoveEyeCamera eyeCam, float iod)
        {
            cameraObject.transform.localPosition = new Vector3(iod, eyeHeight, eyeForward) * worldScale;
            cameraObject.transform.localRotation = Quaternion.identity;

            eyeCam.resolutionScale = oversamplingRatio;

            if (overrideAntialiasing)
            {
                eyeCam.antiAliasing = antialiasSampleCount;
            }
            else
            {
                if (QualitySettings.antiAliasing > 0)
                {
                    eyeCam.antiAliasing = QualitySettings.antiAliasing;
                }
                else
                {
                    eyeCam.antiAliasing = 1;
                }
            }
        }
        /// <summary>
        /// Set up one FOVE view camera in the live scene at runtime.
        /// </summary>
        /// <param name="ipd">How far apart the cameras should be to create the stereoscopic effect.</param>
        /// <param name="whichEye">The eye are you creating this time.</param>
        /// <param name="go">The Unity GameObject instance to which the FOVE camera is attached.</param>
        /// <param name="ec">The FoveEyeCamera instance which is attached to the GameObject.</param>
        /// <returns>The Unity Camera instance which is attached to the GameObject.</returns>
        /// <remarks>We try to support a number of options to be flexible for different users' needs.
        /// As such, the process goes through some checks and differing setup tasks in corresponding
        /// cases. The three paths are: 1) no camera prefabs are referenced, 2) a single camera prefab is
        /// referenced, and 3) both cameras are overridden by objects already placed in the scene.
        /// The third option should only be done for people who *really* need to have two separate cameras
        /// with separate effects for each eye, and accept the consequences that showing different images
        /// to each eye can very easily cause disorientation and sickness in most people.
        ///
        /// In no case is it strictly necessary to add your own FoveEyeCamera behaviour to a game object,
        /// and we recomment nod doing so, as it can be easy to accidentally get your effects in the wrong
        /// order. (FoveEyeCamera should be the last behaviour in the list in order to get all the image
        /// effects reliably.)</remarks>
        private Camera SetupFoveViewCamera(float ipd, EFVR_Eye whichEye, out GameObject go, out FoveEyeCamera ec)
        {
            GameObject temp   = null;
            Camera     cam    = null;
            Camera     mirror = GetComponent <Camera>();

            if (useCameraOverride && useCameraPrefab)
            {
                Debug.LogError("You can not use a prefab and override cameras at the same time!");
            }

            if (useCameraOverride)
            {
                if (leftEyeOverride != null && rightEyeOverride != null)
                {
                    if (whichEye == EFVR_Eye.Left)
                    {
                        cam = leftEyeOverride;
                    }
                    else if (whichEye == EFVR_Eye.Right)
                    {
                        cam = rightEyeOverride;
                    }
                    else
                    {
                        Debug.LogError("Camera Override in unforseen state");
                    }
                    temp      = cam.gameObject;
                    _nearClip = leftEyeOverride.nearClipPlane;
                    _farClip  = leftEyeOverride.farClipPlane;

                    //sanity check
                    if (leftEyeOverride.nearClipPlane != rightEyeOverride.nearClipPlane ||
                        leftEyeOverride.farClipPlane != rightEyeOverride.farClipPlane)
                    {
                        Debug.LogWarning("Left and Right eye clip planes differ, using left plane for VR!");
                    }

                    //the mirror camera is the portal/preview view for unity etc - useful for use when there is no compositor.
                    if (mirror != null)
                    {
                        mirror.nearClipPlane = _nearClip;
                        mirror.farClipPlane  = _farClip;
                    }
                }
                else
                {
                    Debug.LogError("Both Camera Overrides must be assiged if using override mode.");
                }
            }

            // Use a camera prefab if set to do so and one is available
            if (useCameraPrefab)
            {
                if (eyeCameraPrototype != null)
                {
                    if (eyeCameraPrototype.GetComponent <FoveInterface>() != null)
                    {
                        Debug.LogError("FoveInterface's eye camera prototype has another FoveInterface component attached. " + whichEye);
                        go = null;
                        ec = null;
                        return(null);
                    }
                    cam       = Instantiate(eyeCameraPrototype);
                    _nearClip = cam.nearClipPlane;
                    _farClip  = cam.farClipPlane;

                    temp = cam.gameObject;

                    if (mirror != null)
                    {
                        mirror.nearClipPlane = _nearClip;
                        mirror.farClipPlane  = _farClip;
                    }
                }
            }

            if (cam == null)
            {
                temp = new GameObject();
                cam  = temp.AddComponent <Camera>();
                if (mirror != null)
                {
                    _nearClip = mirror.nearClipPlane;
                    _farClip  = mirror.farClipPlane;

                    // Copy over camera properties
                    cam.cullingMask         = mirror.cullingMask;
                    cam.depth               = mirror.depth;
                    cam.renderingPath       = mirror.renderingPath;
                    cam.useOcclusionCulling = mirror.useOcclusionCulling;
#if UNITY_5_6_OR_NEWER
                    cam.allowHDR = mirror.allowHDR;
#else
                    cam.hdr = mirror.hdr;
#endif
                    cam.backgroundColor = mirror.backgroundColor;
                    cam.clearFlags      = mirror.clearFlags;
                }

                cam.nearClipPlane = _nearClip;
                cam.farClipPlane  = _farClip;
            }

            cam.fieldOfView = 95.0f;

            ec = temp.GetComponent <FoveEyeCamera>();
            if (ec == null)
            {
                ec = temp.AddComponent <FoveEyeCamera>();
            }

            ec.whichEye = whichEye;
            ec.suppressProjectionUpdates = suppressProjectionUpdates;
            ec.foveInterfaceBase         = this;


            temp.name             = string.Format("FOVE Eye ({0})", whichEye);
            temp.transform.parent = transform;

            UpdateCameraSettings(temp, ec, ipd);

            go = temp;
            return(cam);
        }