Exemplo n.º 1
0
    // Start
    void Start()
    {
        AlphaFadeValue = 1.0f;
        CurrentLevel   = 0;
        PrevStartDown  = false;
        PrevHatDown    = false;
        PrevHatUp      = false;
        ShowVRVars     = false;
        OldSpaceHit    = false;
        strFPS         = "FPS: 0";
        LoadingLevel   = false;

        sShowLevels = false;

        // Ensure that camera controller variables have been properly
        // initialized before we start reading them
        if (CameraController != null)
        {
            CameraController.InitCameraControllerVariables();
        }

        // Save default values initially
        StoreSnapshot("DEFAULT");

        // Make sure to hide cursor
        Screen.showCursor = false;
        Screen.lockCursor = true;

        // Add delegates to update; useful for ordering menu tasks, if required
        UpdateFunctions += UpdateFPS;

        // CameraController updates
        if (CameraController != null)
        {
            UpdateFunctions += UpdateIPD;
            UpdateFunctions += UpdatePrediction;
            UpdateFunctions += UpdateFOV;
            UpdateFunctions += UpdateDistortionCoefs;
            UpdateFunctions += UpdateHeightOffset;
        }

        // PlayerController updates
        if (PlayerController != null)
        {
            UpdateFunctions += UpdateSpeedAndRotationScaleMultiplier;
        }

        // MainMenu updates
        UpdateFunctions += UpdateSelectCurrentLevel;
        UpdateFunctions += UpdateHandleSnapshots;

        // Device updates
        UpdateFunctions += UpdateResetOrientation;

        // Check for HMD and sensor
        CheckIfRiftPresent();

        // Init static members
        sShowLevels = false;
    }
Exemplo n.º 2
0
    // Start
    void Start()
    {
        Screen.showCursor = true;
        AlphaFadeValue = 1.0f;
        CurrentLevel   = 0;
        PrevStartDown  = false;
        PrevHatDown    = false;
        PrevHatUp      = false;
        ShowVRVars	   = false;
        OldSpaceHit    = false;
        strFPS         = "FPS: 0";
        LoadingLevel   = false;

        ScenesVisible    = false;

        // Ensure that camera controller variables have been properly
        // initialized before we start reading them
        if(CameraController != null)
        {
            CameraController.InitCameraControllerVariables();
            GuiHelper.SetCameraController(ref CameraController);
        }

        // Set the GUI target
        GUIRenderObject = GameObject.Instantiate(Resources.Load("OVRGUIObjectMain")) as GameObject;

        if(GUIRenderObject != null)
        {
            if(GUIRenderTexture == null)
            {
                int w = Screen.width;
                int h = Screen.height;

                if(CameraController.PortraitMode == true)
                {
                    int t = h;
                    h = w;
                    w = t;
                }

                GUIRenderTexture = new RenderTexture(w, h, 24);
                GuiHelper.SetPixelResolution(w, h);
                GuiHelper.SetDisplayResolution(OVRDevice.HResolution, OVRDevice.VResolution);
            }
        }

        // Attach GUI texture to GUI object and GUI object to Camera
        if(GUIRenderTexture != null && GUIRenderObject != null)
        {
            GUIRenderObject.renderer.material.mainTexture = GUIRenderTexture;

            if(CameraController != null)
            {
                // Grab transform of GUI object
                Transform t = GUIRenderObject.transform;
                // Attach the GUI object to the camera
                CameraController.AttachGameObjectToCamera(ref GUIRenderObject);
                // Reset the transform values (we will be maintaining state of the GUI object
                // in local state)
                OVRUtils.SetLocalTransform(ref GUIRenderObject, ref t);
                // Deactivate object until we have completed the fade-in
                // Also, we may want to deactive the render object if there is nothing being rendered
                // into the UI
                // we will move the position of everything over to the left, so get
                // IPD / 2 and position camera towards negative X
                Vector3 lp = GUIRenderObject.transform.localPosition;
                float ipd = 0.0f;
                CameraController.GetIPD(ref ipd);
                lp.x -= ipd * 0.5f;
                GUIRenderObject.transform.localPosition = lp;

                GUIRenderObject.SetActive(false);
            }
        }

        // Save default values initially
        StoreSnapshot("DEFAULT");

        // Make sure to hide cursor
        //if(Application.isEditor == false)
        //{
            //Screen.showCursor = false;
            //Screen.lockCursor = true;
        //}

        // Add delegates to update; useful for ordering menu tasks, if required
        UpdateFunctions += UpdateFPS;

        // CameraController updates
        if(CameraController != null)
        {
            UpdateFunctions += UpdateIPD;
            UpdateFunctions += UpdatePrediction;
            UpdateFunctions += UpdateFOV;
            UpdateFunctions += UpdateDistortionCoefs;
            UpdateFunctions += UpdateEyeHeightOffset;
        }

        // PlayerController updates
        if(PlayerController != null)
        {
            UpdateFunctions += UpdateSpeedAndRotationScaleMultiplier;
            UpdateFunctions += UpdatePlayerControllerMovement;
        }

        // MainMenu updates
        UpdateFunctions += UpdateSelectCurrentLevel;
        UpdateFunctions += UpdateHandleSnapshots;

        // Device updates
        UpdateFunctions += UpdateDeviceDetection;
        UpdateFunctions += UpdateResetOrientation;
        OVRMessenger.AddListener<Device, bool>("Sensor_Attached", UpdateDeviceDetectionMsgCallback);

        // Mag Yaw-Drift correction
        UpdateFunctions += MagCal.UpdateMagYawDriftCorrection;
        MagCal.SetOVRCameraController(ref CameraController);

        // Crosshair functionality
        Crosshair.Init();
        Crosshair.SetCrosshairTexture(ref CrosshairImage);
        Crosshair.SetOVRCameraController (ref CameraController);
        Crosshair.SetOVRPlayerController(ref PlayerController);
        UpdateFunctions += Crosshair.UpdateCrosshair;

        // Check for HMD and sensor
        CheckIfRiftPresent();

        // Init static members
        ScenesVisible = false;
    }
Exemplo n.º 3
0
    // Start
    void Start()
    {
        AlphaFadeValue = 1.0f;
        CurrentLevel   = 0;
        PrevStartDown  = false;
        PrevHatDown    = false;
        PrevHatUp      = false;
        ShowVRVars     = false;
        OldSpaceHit    = false;
        strFPS         = "FPS: 0";
        LoadingLevel   = false;

        ScenesVisible = false;

        // Ensure that camera controller variables have been properly
        // initialized before we start reading them
        if (CameraController != null)
        {
            CameraController.InitCameraControllerVariables();
            GuiHelper.SetCameraController(ref CameraController);
        }

        // Set the GUI target
        GUIRenderObject = GameObject.Instantiate(Resources.Load("OVRGUIObjectMain")) as GameObject;

        if (GUIRenderObject != null)
        {
            if (GUIRenderTexture == null)
            {
                int w = Screen.width;
                int h = Screen.height;

                if (CameraController.PortraitMode == true)
                {
                    int t = h;
                    h = w;
                    w = t;
                }

                GUIRenderTexture = new RenderTexture(w, h, 24);
                GuiHelper.SetPixelResolution(w, h);
                GuiHelper.SetDisplayResolution(OVRDevice.HResolution, OVRDevice.VResolution);
            }
        }

        // Attach GUI texture to GUI object and GUI object to Camera
        if (GUIRenderTexture != null && GUIRenderObject != null)
        {
            GUIRenderObject.renderer.material.mainTexture = GUIRenderTexture;

            if (CameraController != null)
            {
                // Grab transform of GUI object
                Transform t = GUIRenderObject.transform;
                // Attach the GUI object to the camera
                CameraController.AttachGameObjectToCamera(ref GUIRenderObject);
                // Reset the transform values (we will be maintaining state of the GUI object
                // in local state)
                OVRUtils.SetLocalTransform(ref GUIRenderObject, ref t);
                // Deactivate object until we have completed the fade-in
                // Also, we may want to deactive the render object if there is nothing being rendered
                // into the UI
                // we will move the position of everything over to the left, so get
                // IPD / 2 and position camera towards negative X
                Vector3 lp  = GUIRenderObject.transform.localPosition;
                float   ipd = 0.0f;
                CameraController.GetIPD(ref ipd);
                lp.x -= ipd * 0.5f;
                GUIRenderObject.transform.localPosition = lp;

                GUIRenderObject.SetActive(false);
            }
        }

        // Save default values initially
        StoreSnapshot("DEFAULT");

        // Make sure to hide cursor
        if (Application.isEditor == false)
        {
            Screen.showCursor = false;
            Screen.lockCursor = true;
        }

        // Add delegates to update; useful for ordering menu tasks, if required
        UpdateFunctions += UpdateFPS;

        // CameraController updates
        if (CameraController != null)
        {
            UpdateFunctions += UpdateIPD;
            UpdateFunctions += UpdatePrediction;
            UpdateFunctions += UpdateFOV;
            UpdateFunctions += UpdateDistortionCoefs;
            UpdateFunctions += UpdateEyeHeightOffset;
        }

        // PlayerController updates
        if (PlayerController != null)
        {
            UpdateFunctions += UpdateSpeedAndRotationScaleMultiplier;
            UpdateFunctions += UpdatePlayerControllerMovement;
        }

        // MainMenu updates
        UpdateFunctions += UpdateSelectCurrentLevel;
        UpdateFunctions += UpdateHandleSnapshots;

        // Device updates
        UpdateFunctions += UpdateDeviceDetection;
        UpdateFunctions += UpdateResetOrientation;
        OVRMessenger.AddListener <Device, bool>("Sensor_Attached", UpdateDeviceDetectionMsgCallback);

        // Mag Yaw-Drift correction
        UpdateFunctions += MagCal.UpdateMagYawDriftCorrection;
        MagCal.SetOVRCameraController(ref CameraController);

        // Crosshair functionality
        Crosshair.Init();
        Crosshair.SetCrosshairTexture(ref CrosshairImage);
        Crosshair.SetOVRCameraController(ref CameraController);
        Crosshair.SetOVRPlayerController(ref PlayerController);
        UpdateFunctions += Crosshair.UpdateCrosshair;

        // Check for HMD and sensor
        CheckIfRiftPresent();

        // Init static members
        ScenesVisible = false;
    }
Exemplo n.º 4
0
    // Start
    void Start()
    {
        AlphaFadeValue = 1.0f;
        CurrentLevel   = 0;
        PrevStartDown  = false;
        PrevHatDown    = false;
        PrevHatUp      = false;
        ShowVRVars	   = false;
        OldSpaceHit    = false;
        strFPS         = "FPS: 0";
        LoadingLevel   = false;

        sShowLevels    = false;

        // Ensure that camera controller variables have been properly
        // initialized before we start reading them
        if(CameraController != null)
            CameraController.InitCameraControllerVariables();

        // Save default values initially
        StoreSnapshot("DEFAULT");

        // Make sure to hide cursor
        Screen.showCursor = false;
        Screen.lockCursor = true;

        // Add delegates to update; useful for ordering menu tasks, if required
        UpdateFunctions += UpdateFPS;
        UpdateFunctions += UpdateIPD;
        UpdateFunctions += UpdatePrediction;
        UpdateFunctions += UpdateFOV;
        UpdateFunctions += UpdateDistortionCoefs;
        UpdateFunctions += UpdateHeightOffset;
        UpdateFunctions += UpdateSpeedAndRotationMultiplier;
        UpdateFunctions += UpdateSelectCurrentLevel;
        UpdateFunctions += UpdateHandleSnapshots;
        UpdateFunctions += UpdateResetOrientation;

        // Check for HMD and sensor
        CheckIfRiftPresent();

        // Init static members
        sShowLevels = false;
    }
Exemplo n.º 5
0
    // Start
    void Start()
    {
        AlphaFadeValue = 1.0f;
        CurrentLevel   = 0;
        PrevStartDown  = false;
        PrevHatDown    = false;
        PrevHatUp      = false;
        ShowVRVars     = false;
        OldSpaceHit    = false;
        strFPS         = "FPS: 0";
        LoadingLevel   = false;

        sShowLevels = false;

        // Ensure that camera controller variables have been properly
        // initialized before we start reading them
        if (CameraController != null)
        {
            CameraController.InitCameraControllerVariables();
        }

        // Attach GUI texture to GUI object and GUI object to Camera
        if (GUIRenderTexture != null && GUIRenderObject != null)
        {
            GUIRenderObject.renderer.material.mainTexture = GUIRenderTexture;

            if (CameraController != null)
            {
                // Grab transform of GUI object
                Transform t = GUIRenderObject.transform;
                // Attach the GUI object to the camera
                CameraController.AttachGameObjectToCamera(ref GUIRenderObject);
                // Reset the transform values (we will be maintaining state of the GUI object
                // in local state)
                OVRUtils.SetLocalTransform(ref GUIRenderObject, ref t);
                // Deactivate object until we have completed the fade-in
                // Also, we may want to deactive the render object if there is nothing being rendered
                // into the UI
                GUIRenderObject.SetActive(false);
            }
        }

        // Save default values initially
        StoreSnapshot("DEFAULT");

        // Make sure to hide cursor
        //Screen.showCursor = false;
        //Screen.lockCursor = true;

        // Add delegates to update; useful for ordering menu tasks, if required
        UpdateFunctions += UpdateFPS;

        // CameraController updates
        if (CameraController != null)
        {
            UpdateFunctions += UpdateIPD;
            UpdateFunctions += UpdatePrediction;
            UpdateFunctions += UpdateFOV;
            UpdateFunctions += UpdateDistortionCoefs;
            UpdateFunctions += UpdateHeightOffset;
        }

        // PlayerController updates
        if (PlayerController != null)
        {
            UpdateFunctions += UpdateSpeedAndRotationScaleMultiplier;
        }

        // MainMenu updates
        UpdateFunctions += UpdateSelectCurrentLevel;
        UpdateFunctions += UpdateHandleSnapshots;

        // Device updates
        UpdateFunctions += UpdateDeviceDetection;
        UpdateFunctions += UpdateResetOrientation;
        OVRMessenger.AddListener <Device, bool>("Sensor_Attached", UpdateDeviceDetectionMsgCallback);

        // Mag Yaw-Drift correction
        UpdateFunctions += MagCal.UpdateMagYawDriftCorrection;

        MagCal.SetOVRCameraController(ref CameraController);

        // Check for HMD and sensor
        CheckIfRiftPresent();

        // Init static members
        sShowLevels = false;
    }
Exemplo n.º 6
0
    /// <summary>
    /// Start this instance.
    /// </summary>
    void Start()
    {
        AlphaFadeValue = 1.0f;
        CurrentLevel   = 0;
        PrevStartDown  = false;
        PrevHatDown    = false;
        PrevHatUp      = false;
        ShowVRVars	   = false;
        OldSpaceHit    = false;
        strFPS         = "FPS: 0";
        LoadingLevel   = false;
        ScenesVisible  = false;

        // Ensure that camera controller variables have been properly
        // initialized before we start reading them
        if(CameraController != null)
            CameraController.InitCameraControllerVariables();

        // Set the GUI target
        GUIRenderObject = GameObject.Instantiate(Resources.Load("OVRGUIObjectMain")) as GameObject;

        if(GUIRenderObject != null)
        {
            // Chnge the layer
            GUIRenderObject.layer = LayerMask.NameToLayer(LayerName);

            if(GUIRenderTexture == null)
            {
                int w = Screen.width;
                int h = Screen.height;

                // We don't need a depth buffer on this texture
                GUIRenderTexture = new RenderTexture(w, h, 0);
                GuiHelper.SetPixelResolution(w, h);
                // NOTE: All GUI elements are being written with pixel values based
                // from DK1 (1280x800). These should change to normalized locations so
                // that we can scale more cleanly with varying resolutions
                //GuiHelper.SetDisplayResolution(OVRDevice.HResolution,
                //								 OVRDevice.VResolution);
                GuiHelper.SetDisplayResolution(1280.0f, 800.0f);
            }
        }

        // Attach GUI texture to GUI object and GUI object to Camera
        if(GUIRenderTexture != null && GUIRenderObject != null)
        {
            GUIRenderObject.renderer.material.mainTexture = GUIRenderTexture;

            if(CameraController != null)
            {
                // Grab transform of GUI object
                Vector3 ls = GUIRenderObject.transform.localScale;
                Vector3 lp = GUIRenderObject.transform.localPosition;
                Quaternion lr = GUIRenderObject.transform.localRotation;

                // Attach the GUI object to the camera
                CameraController.AttachGameObjectToCamera(ref GUIRenderObject);
                // Reset the transform values (we will be maintaining state of the GUI object
                // in local state)

                GUIRenderObject.transform.localScale = ls;
                GUIRenderObject.transform.localRotation = lr;

                // Deactivate object until we have completed the fade-in
                // Also, we may want to deactive the render object if there is nothing being rendered
                // into the UI
                // we will move the position of everything over to the left, so get
                // IPD / 2 and position camera towards negative X
                float   ipd = 0.0f;
                CameraController.GetIPD(ref ipd);
                lp.x -= ipd * 0.5f;
                GUIRenderObject.transform.localPosition = lp;

                GUIRenderObject.SetActive(false);
            }
        }

        // Save default values initially
        StoreSnapshot("DEFAULT");

        // Make sure to hide cursor
        if(Application.isEditor == false)
        {
            Screen.showCursor = false;
            Screen.lockCursor = true;
        }

        // Add delegates to update; useful for ordering menu tasks, if required
        UpdateFunctions += UpdateFPS;

        // CameraController updates
        if(CameraController != null)
        {
            UpdateFunctions += UpdateIPD;
            UpdateFunctions += UpdatePrediction;

            // Set LPM on by default
            UpdateFunctions += UpdateLowPersistenceMode;
            OVRDevice.SetLowPersistenceMode(LowPersistenceMode);
            UpdateFunctions += UpdateVisionMode;
            UpdateFunctions += UpdateFOV;
            UpdateFunctions += UpdateEyeHeightOffset;

            // Add a GridCube component to this object
            GridCube = gameObject.AddComponent<OVRGridCube>();
            GridCube.SetOVRCameraController(ref CameraController);

            // Add a VisionGuide component to this object
            /*VisionGuide = gameObject.AddComponent<OVRVisionGuide>();
            VisionGuide.SetOVRCameraController(ref CameraController);
            VisionGuide.SetFadeTexture(ref FadeInTexture);
            VisionGuide.SetVisionGuideLayer(ref LayerName);*/
        }

        // PlayerController updates
        if(PlayerController != null)
        {
            UpdateFunctions += UpdateSpeedAndRotationScaleMultiplier;
            UpdateFunctions += UpdatePlayerControllerMovement;
        }

        // MainMenu updates
        UpdateFunctions += UpdateSelectCurrentLevel;
        UpdateFunctions += UpdateHandleSnapshots;

        // Device updates
        UpdateFunctions += UpdateDeviceDetection;

        // Add a callback to detect device detection
        OVRMessenger.AddListener<Device, bool>("Sensor_Attached", UpdateDeviceDetectionMsgCallback);

        // Mag Yaw-Drift correction
        // We will test to see if we are already calibrated by the
        // Calibration tool
        MagCal.SetInitialCalibarationState();
        UpdateFunctions += MagCal.UpdateMagYawDriftCorrection;
        MagCal.SetOVRCameraController(ref CameraController);

        // Crosshair functionality
        Crosshair.Init();
        Crosshair.SetCrosshairTexture(ref CrosshairImage);
        Crosshair.SetOVRCameraController (ref CameraController);
        Crosshair.SetOVRPlayerController(ref PlayerController);
        UpdateFunctions += Crosshair.UpdateCrosshair;

        // Check for HMD and sensor
        CheckIfRiftPresent();

        // Reset tracker position.
        // We assume that the CameraController is at the desired neck location
        Vector3 eyeOffset = Vector3.zero;

        if(CameraController != null)
            CameraController.GetEyeCenterPosition(ref eyeOffset);

        OVRCamera.ResetCameraPositionOrientation(ref eyeOffset, true, false, false);
    }
Exemplo n.º 7
0
    /// <summary>
    /// Start this instance.
    /// </summary>
    void Start()
    {
        AlphaFadeValue = 1.0f;
        CurrentLevel   = 0;
        PrevStartDown  = false;
        PrevHatDown    = false;
        PrevHatUp      = false;
        ShowVRVars     = false;
        OldSpaceHit    = false;
        strFPS         = "FPS: 0";
        LoadingLevel   = false;
        ScenesVisible  = false;

        // Ensure that camera controller variables have been properly
        // initialized before we start reading them
        if (CameraController != null)
        {
            CameraController.InitCameraControllerVariables();
        }

        // Set the GUI target
        GUIRenderObject = GameObject.Instantiate(Resources.Load("OVRGUIObjectMain")) as GameObject;

        if (GUIRenderObject != null)
        {
            // Chnge the layer
            GUIRenderObject.layer = LayerMask.NameToLayer(LayerName);

            if (GUIRenderTexture == null)
            {
                int w = Screen.width;
                int h = Screen.height;

                // We don't need a depth buffer on this texture
                GUIRenderTexture = new RenderTexture(w, h, 0);
                GuiHelper.SetPixelResolution(w, h);
                // NOTE: All GUI elements are being written with pixel values based
                // from DK1 (1280x800). These should change to normalized locations so
                // that we can scale more cleanly with varying resolutions
                //GuiHelper.SetDisplayResolution(OVRDevice.HResolution,
                //								 OVRDevice.VResolution);
                GuiHelper.SetDisplayResolution(1280.0f, 800.0f);
            }
        }

        // Attach GUI texture to GUI object and GUI object to Camera
        if (GUIRenderTexture != null && GUIRenderObject != null)
        {
            GUIRenderObject.renderer.material.mainTexture = GUIRenderTexture;

            if (CameraController != null)
            {
                // Grab transform of GUI object
                Transform t = GUIRenderObject.transform;
                // Attach the GUI object to the camera
                CameraController.AttachGameObjectToCamera(ref GUIRenderObject);
                // Reset the transform values (we will be maintaining state of the GUI object
                // in local state)
                OVRUtils.SetLocalTransform(ref GUIRenderObject, ref t);
                // Deactivate object until we have completed the fade-in
                // Also, we may want to deactive the render object if there is nothing being rendered
                // into the UI
                // we will move the position of everything over to the left, so get
                // IPD / 2 and position camera towards negative X
                Vector3 lp  = GUIRenderObject.transform.localPosition;
                float   ipd = 0.0f;
                CameraController.GetIPD(ref ipd);
                lp.x -= ipd * 0.5f;
                GUIRenderObject.transform.localPosition = lp;

                GUIRenderObject.SetActive(false);
            }
        }

        // Save default values initially
        StoreSnapshot("DEFAULT");

        // Make sure to hide cursor
        if (Application.isEditor == false)
        {
            Screen.showCursor = false;
            Screen.lockCursor = true;
        }

        // Add delegates to update; useful for ordering menu tasks, if required
        UpdateFunctions += UpdateFPS;

        // CameraController updates
        if (CameraController != null)
        {
            UpdateFunctions += UpdateIPD;
            UpdateFunctions += UpdatePrediction;
            // Set LPM on by default
            UpdateFunctions += UpdateLowPersistanceMode;
            OVRDevice.SetLowPersistanceMode(LowPersistanceMode);
            UpdateFunctions += UpdateVisionMode;
            UpdateFunctions += UpdateFOV;
            UpdateFunctions += UpdateEyeHeightOffset;

            // Add a GridCube component to this object
            GridCube = gameObject.AddComponent <OVRGridCube>();
            GridCube.SetOVRCameraController(ref CameraController);

            // Add a VisionGuide component to this object
            VisionGuide = gameObject.AddComponent <OVRVisionGuide>();
            VisionGuide.SetOVRCameraController(ref CameraController);
            VisionGuide.SetFadeTexture(ref FadeInTexture);
            VisionGuide.SetVisionGuideLayer(ref LayerName);
        }

        // PlayerController updates
        if (PlayerController != null)
        {
            UpdateFunctions += UpdateSpeedAndRotationScaleMultiplier;
            UpdateFunctions += UpdatePlayerControllerMovement;
        }

        // MainMenu updates
        UpdateFunctions += UpdateSelectCurrentLevel;
        UpdateFunctions += UpdateHandleSnapshots;

        // Device updates
        UpdateFunctions += UpdateDeviceDetection;

        // Add a callback to detect device detection
        OVRMessenger.AddListener <Device, bool>("Sensor_Attached", UpdateDeviceDetectionMsgCallback);

        // Mag Yaw-Drift correction
        // We will test to see if we are already calibrated by the
        // Calibration tool
        MagCal.SetInitialCalibarationState();
        UpdateFunctions += MagCal.UpdateMagYawDriftCorrection;
        MagCal.SetOVRCameraController(ref CameraController);

        // Crosshair functionality
        Crosshair.Init();
        Crosshair.SetCrosshairTexture(ref CrosshairImage);
        Crosshair.SetOVRCameraController(ref CameraController);
        Crosshair.SetOVRPlayerController(ref PlayerController);
        UpdateFunctions += Crosshair.UpdateCrosshair;

        // Check for HMD and sensor
        CheckIfRiftPresent();

        // Reset tracker position.
        // We assume that the CameraController is at the desired neck location
        Vector3 eyeOffset = Vector3.zero;

        if (CameraController != null)
        {
            CameraController.GetEyeCenterPosition(ref eyeOffset);
        }

        OVRCamera.ResetCameraPositionOrientation(ref eyeOffset, true, false, false);
    }
Exemplo n.º 8
0
    // Start
    void Start()
    {
        AlphaFadeValue = 1.0f;
        CurrentLevel   = 0;
        PrevStartDown  = false;
        PrevHatDown    = false;
        PrevHatUp      = false;
        ShowVRVars	   = false;
        OldSpaceHit    = false;
        strFPS         = "FPS: 0";
        LoadingLevel   = false;

        sShowLevels    = false;

        // Ensure that camera controller variables have been properly
        // initialized before we start reading them
        if(CameraController != null)
            CameraController.InitCameraControllerVariables();

        // Attach GUI texture to GUI object and GUI object to Camera
        if(GUIRenderTexture != null && GUIRenderObject != null)
        {
            GUIRenderObject.renderer.material.mainTexture = GUIRenderTexture;

            if(CameraController != null)
            {
                // Grab transform of GUI object
                Transform t = GUIRenderObject.transform;
                // Attach the GUI object to the camera
                CameraController.AttachGameObjectToCamera(ref GUIRenderObject);
                // Reset the transform values (we will be maintaining state of the GUI object
                // in local state)
                OVRUtils.SetLocalTransform(ref GUIRenderObject, ref t);
                // Deactivate object until we have completed the fade-in
                // Also, we may want to deactive the render object if there is nothing being rendered
                // into the UI
                GUIRenderObject.SetActive(false);
            }
        }

        // Save default values initially
        StoreSnapshot("DEFAULT");

        // Make sure to hide cursor
        Screen.showCursor = false;
        Screen.lockCursor = true;

        // Add delegates to update; useful for ordering menu tasks, if required
        UpdateFunctions += UpdateFPS;

        // CameraController updates
        if(CameraController != null)
        {
            UpdateFunctions += UpdateIPD;
            UpdateFunctions += UpdatePrediction;
            UpdateFunctions += UpdateFOV;
            UpdateFunctions += UpdateDistortionCoefs;
            UpdateFunctions += UpdateHeightOffset;
        }

        // PlayerController updates
        if(PlayerController != null)
        {
            UpdateFunctions += UpdateSpeedAndRotationScaleMultiplier;
        }

        // MainMenu updates
        UpdateFunctions += UpdateSelectCurrentLevel;
        UpdateFunctions += UpdateHandleSnapshots;

        // Device updates
        UpdateFunctions += UpdateDeviceDetection;
        UpdateFunctions += UpdateResetOrientation;
        OVRMessenger.AddListener<Device, bool>("Sensor_Attached", UpdateDeviceDetectionMsgCallback);

        // Mag Yaw-Drift correction
        UpdateFunctions += MagCal.UpdateMagYawDriftCorrection;

        MagCal.SetOVRCameraController(ref CameraController);

        // Check for HMD and sensor
        CheckIfRiftPresent();

        // Init static members
        sShowLevels = false;
    }
Exemplo n.º 9
0
    // Use this for initialization
    void Start()
    {
        // Ensure that camera controller variables have been properly
        // initialized before we start reading them
        if (m_CameraController != null)
        {
            m_CameraController.InitCameraControllerVariables();
            m_GuiHelper.SetCameraController(ref m_CameraController);
        }

        // Set the GUI target
        m_GUIRenderObject = GameObject.Instantiate(Resources.Load("OVRGUIObjectMain")) as GameObject;

        if (m_GUIRenderObject != null)
        {
            if (m_GUIRenderTexture == null)
            {
                int w = Screen.width;
                int h = Screen.height;

                if (m_CameraController.PortraitMode == true)
                {
                    int t = h;
                    h = w;
                    w = t;
                }

                m_GUIRenderTexture = new RenderTexture(w, h, 24);
                m_GuiHelper.SetPixelResolution(w, h);
                m_GuiHelper.SetDisplayResolution(OVRDevice.HResolution, OVRDevice.VResolution);
            }
        }

        // Attach GUI texture to GUI object and GUI object to Camera
        if (m_GUIRenderTexture != null && m_GUIRenderObject != null)
        {
            m_GUIRenderObject.renderer.material.mainTexture = m_GUIRenderTexture;

            if (m_CameraController != null)
            {
                // Grab transform of GUI object
                Transform t = m_GUIRenderObject.transform;
                // Attach the GUI object to the camera
                m_CameraController.AttachGameObjectToCamera(ref m_GUIRenderObject);
                // Reset the transform values (we will be maintaining state of the GUI object
                // in local state)
                OVRUtils.SetLocalTransform(ref m_GUIRenderObject, ref t);
                // Deactivate object until we have completed the fade-in
                // Also, we may want to deactive the render object if there is nothing being rendered
                // into the UI
                // we will move the position of everything over to the left, so get
                // IPD / 2 and position camera towards negative X
                Vector3 lp = m_GUIRenderObject.transform.localPosition;
                float ipd = 0.0f;
                m_CameraController.GetIPD(ref ipd);
                lp.x -= ipd * 0.5f;
                m_GUIRenderObject.transform.localPosition = lp;

                m_GUIRenderObject.SetActive(false);
            }
        }

        // Make sure to hide cursor
        if (Application.isEditor == false)
        {
            Screen.showCursor = false;
            Screen.lockCursor = true;
        }

        // Device updates
        UpdateFunctions += UpdateDeviceDetection;

        // Mag Yaw-Drift correction
        UpdateFunctions += m_MagCal.UpdateMagYawDriftCorrection;
        m_MagCal.SetOVRCameraController(ref m_CameraController);

        // Crosshair functionality
        m_Crosshair.Init();
        m_Crosshair.SetCrosshairTexture(ref m_CrosshairImage);
        m_Crosshair.SetOVRCameraController (ref m_CameraController);
        m_Crosshair.SetTarget(ref m_Target);
        //m_Crosshair.SetContinuousInputController (ref m_continuous_input_controller);
        UpdateFunctions += m_Crosshair.UpdateCrosshair;

        // Check for HMD and sensor
        CheckIfRiftPresent();
    }