Example #1
0
    private void Freeze()
    {
        utilisateur.transform.position = endPos;
        utilisateur.transform.rotation = endRot;

        if (keyb.IsKeyPressed(MiddleVR.VRK_DOWN) || keyb.IsKeyPressed(MiddleVR.VRK_S))
        {
            StartReverseGlide();
        }
    }
Example #2
0
    private void Freeze()
    {
        utilisateur.transform.position = endPos;
        utilisateur.transform.rotation = endRot;
        //wand.transform.localPosition.Set(0, 0, 0);

        if (keyb.IsKeyPressed(MiddleVR.VRK_DOWN) ||
            keyb.IsKeyPressed(MiddleVR.VRK_S) ||
            MiddleVR.VRDeviceMgr.IsWandButtonPressed((uint)cancelButton))
        {
            StartReverseGlide();
        }
    }
Example #3
0
    ///<summary>
    ///Allows the user to move his avatar forward, backward, left and right.
    ///</summary>
    void moving(vrKeyboard keyb)
    {
        //forward will be modified in case we push the up/down key of the keyboard
        float forward = 0.0f;
        //speed will be a modified value of forward, depending of a given sensibility
        float strafe = 0.0f;

        //Get MiddleVR's keyboard inputs
        if (keyb.IsKeyPressed(MiddleVR.VRK_UP) || keyb.IsKeyPressed(MiddleVR.VRK_W))
        {
            forward = 1.0f;
        }
        if (keyb.IsKeyPressed(MiddleVR.VRK_DOWN) || keyb.IsKeyPressed(MiddleVR.VRK_S))
        {
            forward = -1.0f;
        }

        //Get MiddleVR's keyboard inputs
        if (keyb.IsKeyPressed(MiddleVR.VRK_RIGHT) || keyb.IsKeyPressed(MiddleVR.VRK_D))
        {
            strafe = 1.0f;
        }

        if (keyb.IsKeyPressed(MiddleVR.VRK_LEFT) || keyb.IsKeyPressed(MiddleVR.VRK_A))
        {
            strafe = -1.0f;
        }
        Vector3 directionVector = new Vector3(strafe, 0, forward) * Sensibility;

        charController.SimpleMove(m_RefNode.transform.TransformDirection(directionVector));
    }
Example #4
0
    void Update()
    {
        vrKeyboard keyb = MiddleVR.VRDeviceMgr.GetKeyboard();

        // Reload Simulation (level 0)
        if (keyb != null && keyb.IsKeyToggled(MiddleVR.VRK_R) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)) && (keyb.IsKeyPressed(MiddleVR.VRK_LCONTROL) || keyb.IsKeyPressed(MiddleVR.VRK_RCONTROL)))
        {
            Application.LoadLevel(0);
        }
        // Reload last loaded level
        else if (keyb != null && keyb.IsKeyToggled(MiddleVR.VRK_R) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
        {
            Application.LoadLevel(Application.loadedLevel);
        }
    }
    // Update is called once per frame
    void Update()
    {
        vrKeyboard keyb = MiddleVR.VRDeviceMgr.GetKeyboard();

        if (!GetComponent <Animation>().isPlaying&& keyb.IsKeyPressed(MiddleVR.VRK_S))
        {
            GetComponent <Animation>().Play();
        }

        if (keyb.IsKeyPressed(MiddleVR.VRK_R))
        {
            //Application.LoadLevel(0);
            GetComponent <Animation>().Stop();
            transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y * 1.005f, transform.localScale.z);
            GetComponent <Animation>().Play();
        }

        if (keyb.IsKeyPressed(MiddleVR.VRK_F))
        {
            //Application.LoadLevel(0);
            GetComponent <Animation>().Stop();
            transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y * 0.995f, transform.localScale.z);
            GetComponent <Animation>().Play();
        }

        if (keyb.IsKeyPressed(MiddleVR.VRK_T))
        {
            //Application.LoadLevel(0);
            GetComponent <Animation>().Stop();
            transform.localScale = new Vector3(transform.localScale.x * 1.005f, transform.localScale.y, transform.localScale.z * 1.005f);
            GetComponent <Animation>().Play();
        }

        if (keyb.IsKeyPressed(MiddleVR.VRK_G))
        {
            //Application.LoadLevel(0);
            GetComponent <Animation>().Stop();
            transform.localScale = new Vector3(transform.localScale.x * 0.995f, transform.localScale.y, transform.localScale.z * 0.995f);
            GetComponent <Animation>().Play();
        }

        if (Input.GetKey(KeyCode.Return))
        {
            Application.LoadLevel(0);
        }
    }
    // Update is called once per frame
    void Update()
    {
        //MiddleVRTools.Log("VRManagerUpdate");

        if (m_isInit)
        {
            MiddleVRTools.Log(4, "[>] Unity Update - Start");

            if (kernel.GetFrame() >= 1 && !m_isGeometrySet && !Application.isEditor)
            {
                if (!DontChangeWindowGeometry)
                {
                    displayMgr.SetUnityWindowGeometry();
                }
                m_isGeometrySet = true;
            }

            kernel.Update();
            UpdateInput();

            if (ShowFPS)
            {
                guiText.text = kernel.GetFPS().ToString("f2");
            }

            MiddleVRTools.UpdateNodes();

            if (m_displayLog)
            {
                string txt = kernel.GetLogString(true);
                print(txt);
                m_GUI.text = txt;
            }

            vrKeyboard keyb = MiddleVR.VRDeviceMgr.GetKeyboard();

            if (keyb != null && keyb.IsKeyToggled(MiddleVR.VRK_F) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                ShowFPS         = !ShowFPS;
                guiText.enabled = ShowFPS;
            }

            if (keyb != null && (keyb.IsKeyToggled(MiddleVR.VRK_W) || keyb.IsKeyToggled(MiddleVR.VRK_Z)) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                ShowWand = !ShowWand;
                ShowWandGeometry(ShowWand);
            }

            DeltaTime = kernel.GetDeltaTime();

            MiddleVRTools.Log(4, "[<] Unity Update - End");
        }
        else
        {
            //Debug.LogWarning("[ ] If you have an error mentionning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable.");
        }
    }
Example #7
0
    protected void Update()
    {
        vrKeyboard keyboard = MiddleVR.VRDeviceMgr.GetKeyboard();

        if (keyboard != null &&
            keyboard.IsKeyToggled(MiddleVR.VRK_R) &&
            (keyboard.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyboard.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
        {
            if ((keyboard.IsKeyPressed(MiddleVR.VRK_LCONTROL) || keyboard.IsKeyPressed(MiddleVR.VRK_RCONTROL)))
            {
                // Reload Simulation (level 0).
                Application.LoadLevel(0);
            }
            else
            {
                // Reload last loaded level.
                Application.LoadLevel(Application.loadedLevel);
            }
        }
    }
    protected void Update()
    {
        vrKeyboard keyboard = MiddleVR.VRDeviceMgr.GetKeyboard();

        if (keyboard != null &&
            keyboard.IsKeyToggled(MiddleVR.VRK_R) &&
            (keyboard.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyboard.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
        {
            if ((keyboard.IsKeyPressed(MiddleVR.VRK_LCONTROL) || keyboard.IsKeyPressed(MiddleVR.VRK_RCONTROL)))
            {
                // Reload Simulation (level 0).
                SceneManager.LoadScene(0);
            }
            else
            {
                // Reload last loaded level.
                Scene scene = SceneManager.GetActiveScene();
                SceneManager.LoadScene(scene.name);
            }
        }
    }
    private IEnumerator PostFrameUpdate()
    {
        yield return(new WaitForEndOfFrame());

        VRManagerScript mgr = GetComponent <VRManagerScript>();

        if (mgr != null && MiddleVR.VRKernel == null)
        {
            Debug.LogWarning("[ ] If you have an error mentioning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable.");
            mgr.GetComponent <GUIText>().text = "[ ] Check the console window to check if you have an error mentioning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable.";
        }

        MVRTools.Log(4, "[>] Unity: Start of VR PostFrameUpdate.");

        if (kernel == null || deviceMgr == null || clusterMgr == null)
        {
            InitManagers();
        }

        if (deviceMgr != null)
        {
            vrKeyboard keyboard = deviceMgr.GetKeyboard();
            if (keyboard != null)
            {
                if (mgr != null && mgr.QuitOnEsc && keyboard.IsKeyPressed((uint)MiddleVR.VRK_ESCAPE))
                {
                    mgr.QuitApplication();
                }
            }
            else
            {
                if (!LoggedNoKeyboard)
                {
                    MVRTools.Log("[X] No VR keyboard.");
                    LoggedNoKeyboard = true;
                }
            }
        }

        if (kernel != null)
        {
            kernel.PostFrameUpdate();
        }

        MVRTools.Log(4, "[<] Unity: End of VR PostFrameUpdate.");

        if (kernel != null && kernel.GetFrame() == 2 && !Application.isEditor)
        {
            MVRTools.Log(2, "[ ] If the application is stuck here and you're using Quad-buffer active stereoscopy, make sure that in the Player Settings of Unity, the option 'Run in Background' is checked.");
        }
    }
    protected void Update()
    {
        vrKeyboard keyboard = MiddleVR.VRDeviceMgr.GetKeyboard();

        // Invert eyes.
        if (keyboard != null &&
            keyboard.IsKeyToggled(MiddleVR.VRK_I) &&
            (keyboard.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyboard.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
        {
            var displayMgr = MiddleVR.VRDisplayMgr;

            // For each vrCameraStereo, invert inter eye distance.
            for (uint i = 0, iEnd = displayMgr.GetCamerasNb(); i < iEnd; ++i)
            {
                vrCamera cam = displayMgr.GetCameraByIndex(i);
                if (cam.IsA("CameraStereo"))
                {
                    vrCameraStereo stereoCam = displayMgr.GetCameraStereoById(cam.GetId());
                    stereoCam.SetInterEyeDistance(-stereoCam.GetInterEyeDistance());
                }
            }
        }
    }
Example #11
0
 /// <summary>
 /// Checks if the menu is in its current state from more than 0.5s and, eventually, changes its state if the user is pressing F12
 /// The user can't move when menu is displayed
 /// </summary>
 void Update()
 {
     timeInCurrentState += MiddleVR.VRKernel.GetDeltaTime();
     if (timeInCurrentState > 0.5)
     {
         if (keyb.IsKeyPressed(MiddleVR.VRK_F12) && menu.activeSelf == false)
         {
             menu.SetActive(true);
             timeInCurrentState = 0.0;
             controller.lockCamera();
         }
         else if (keyb.IsKeyPressed(MiddleVR.VRK_F12) && menu.activeSelf == true)
         {
             menu.SetActive(false);
             timeInCurrentState = 0.0;
             controller.unLockCamera();
         }
         //menu.transform.position = headNode.transform.position;
         //menu.transform.rotation = headNode.transform.rotation;
         //menu.transform.Rotate(90f, 180f, 0);
         //menu.transform.Translate(0, -0.2f, 0f);
     }
 }
Example #12
0
    /// <summary>
    /// If X is pressed, the phone starts ringing for 10sec
    /// Used for test ONLY : has to be automatised later
    /// </summary>
    void Update()
    {
        if (keyb.IsKeyPressed(MiddleVR.VRK_X))
        {
            source.Play();
            duration = 0.0f;
        }

        duration += (float)MiddleVR.VRKernel.GetDeltaTime();

        if (duration > MaxDuration)
        {
            source.Stop();
        }
    }
Example #13
0
    void Update()
    {
        vrKeyboard keyb = MiddleVR.VRDeviceMgr.GetKeyboard();

        // Invert eye
        if (keyb != null && keyb.IsKeyToggled(MiddleVR.VRK_I) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
        {
            // For each vrCameraStereo, invert inter eye distance
            uint camNb = MiddleVR.VRDisplayMgr.GetCamerasNb();
            for (uint i = 0; i < camNb; ++i)
            {
                vrCamera cam = MiddleVR.VRDisplayMgr.GetCameraByIndex(i);
                if (cam.IsA("CameraStereo"))
                {
                    vrCameraStereo stereoCam = MiddleVR.VRDisplayMgr.GetCameraStereo(cam.GetName());
                    stereoCam.SetInterEyeDistance(-stereoCam.GetInterEyeDistance());
                }
            }
        }
    }
Example #14
0
    void moving(vrKeyboard keyb)
    {
        //forward will be modified in case we push the up/down key of the keyboard
        float forward = 0.0f;
        //speed will be a modified value of forward, depending of a given sensibility
        float strafe = 0.0f;

        //forward = (float)MiddleVR.VRKernel.GetDeltaTime() * MiddleVR.VRDeviceMgr.GetWandVerticalAxisValue() * Speed;

        //Get MiddleVR's keyboard inputs
        if (keyb.IsKeyPressed(MiddleVR.VRK_UP) || keyb.IsKeyPressed(MiddleVR.VRK_W))
        {
            forward = 1.0f;
            //unLockCamera();
        }
        if (keyb.IsKeyPressed(MiddleVR.VRK_DOWN) || keyb.IsKeyPressed(MiddleVR.VRK_S))
        {
            forward = -1.0f;
            //unLockCamera();
        }

        //Get MiddleVR's keyboard inputs
        if (keyb.IsKeyPressed(MiddleVR.VRK_RIGHT) || keyb.IsKeyPressed(MiddleVR.VRK_D))
        {
            strafe = 1.0f;
            //unLockCamera();
        }

        if (keyb.IsKeyPressed(MiddleVR.VRK_LEFT) || keyb.IsKeyPressed(MiddleVR.VRK_A))
        {
            strafe = -1.0f;
            //unLockCamera();
        }

        Vector3 directionVector = new Vector3(strafe, 0, forward) * Sensibility;

        controller.SimpleMove(m_RefNode.transform.TransformDirection(directionVector));
    }
Example #15
0
    // Update is called once per frame
    void Update()
    {
        if (keyb.IsKeyToggled(reloadScene))
        {
            Application.LoadLevel(Application.loadedLevel);
        }

        if (keyb.IsKeyToggled(quitScene))
        {
            Application.Quit();
        }

        if (keyb.IsKeyToggled(modeAssiste))
        {
            gameManager.CurrentMode = Modelisation.Mode.Assisted;
        }


        if (keyb.IsKeyToggled(modeAutonome))
        {
            gameManager.CurrentMode = Modelisation.Mode.Auto;
        }

        if (keyb.IsKeyToggled(scenarioAppelSimple))
        {
            Debug.Log("Scenario appel d'un ami");
            gameManager.loadScenario("appel");
        }

        if (keyb.IsKeyToggled(scenarioAppelInfirmier))
        {
            Debug.Log("Scenario appel d'un infirmier");
            gameManager.loadScenario("infirmier");
        }

        if (keyb.IsKeyToggled(scenarioVisiteInconnu))
        {
            Debug.Log("Scenario appel d'un inconnu");
            gameManager.loadScenario("inconnu");
        }

        if (keyb.IsKeyToggled(noScenario))
        {
            gameManager.loadScenario("aucun");
        }

        if ((keyb.IsKeyToggled(sensibilityUp) && keyb.IsKeyPressed(sensibilityDown)) ||
            (keyb.IsKeyToggled(sensibilityDown) && keyb.IsKeyPressed(sensibilityUp)))
        {
            vrfps.Sensibility = 3.0f;
        }
        else if (keyb.IsKeyToggled(lookSensibilityDown) && keyb.IsKeyPressed(lookSensibilityUp))
        {
            vrfps.lookSensibility = 1.0f;
        }

        else if (keyb.IsKeyToggled(sensibilityUp))
        {
            vrfps.Sensibility *= sensibilityFactor;
        }

        else if (keyb.IsKeyToggled(sensibilityDown))
        {
            vrfps.Sensibility /= sensibilityFactor;
        }

        else if (keyb.IsKeyToggled(lookSensibilityUp))
        {
            vrfps.lookSensibility *= lookSensibilityFactor;
        }

        else if (keyb.IsKeyToggled(lookSensibilityDown))
        {
            vrfps.lookSensibility /= lookSensibilityFactor;
        }
    }
Example #16
0
    // Use this for initialization

    /*void Start()
     * {
     *
     *      GameObject Wand = GameObject.Find("VRWand");
     *
     *      if (Wand != null)
     *      {
     *              Wand.GetComponent<VRWandNavigation>().enabled = false;
     *              MiddleVRTools.Log("[ ] VRFPSInputController deactivated VRWandNavigation. Make sure you set the VR Root Node to the First Person Controller.");
     *      }
     * }*/


    void FixedUpdate()
    {
        CharacterMotor motor = GetComponent <CharacterMotor>();

        vrKeyboard keyb = null;

        if (MiddleVR.VRDeviceMgr.GetKeyboard() != null)
        {
            keyb = MiddleVR.VRDeviceMgr.GetKeyboard();
        }

        GameObject refNode = GameObject.Find(ReferenceNode);

        float speed   = 0.0f;
        float speedR  = 0.0f;
        float forward = 0.0f;

        // Choosing active vertical axis, later ones will overwrite previous ones

        // First test Unity's inputs
        if (Math.Abs(Input.GetAxis("Vertical")) > 0)
        {
            forward = Input.GetAxis("Vertical");
        }

        // Then test MiddleVR's keyboard
        //If MiddleVR is correctly tracking the keyboard, ie keyb != null, this will overwrite forward
        if (keyb != null)
        {
            if (keyb.IsKeyPressed(MiddleVR.VRK_UP) || keyb.IsKeyPressed(MiddleVR.VRK_Z))
            {
                forward = 1.0f;
            }

            if (keyb.IsKeyPressed(MiddleVR.VRK_DOWN) || keyb.IsKeyPressed(MiddleVR.VRK_S))
            {
                forward = -1.0f;
            }
        }

        // Computing speed
        if (Math.Abs(forward) > 0.1)
        {
            speed = forward * Time.deltaTime * 30;
        }

        //print("Speed: " + speed);


        // Choosing active horizontal axis
        float rotation = 0.0f;

        // First test Unity's inputs
        if (Math.Abs(Input.GetAxis("Horizontal")) > 0)
        {
            rotation = Input.GetAxis("Horizontal");
        }

        // Then test MiddleVR's keyboard
        if (keyb != null)
        {
            if (keyb.IsKeyPressed(MiddleVR.VRK_LEFT) || keyb.IsKeyPressed(MiddleVR.VRK_Q))
            {
                rotation = -1.0f;
            }

            if (keyb.IsKeyPressed(MiddleVR.VRK_RIGHT) || keyb.IsKeyPressed(MiddleVR.VRK_D))
            {
                rotation = 1.0f;
            }
        }

        if (Math.Abs(rotation) > 0.1)
        {
            speedR = rotation * Time.deltaTime * 50;
        }

        Vector3 directionVector = new Vector3(speedR, 0, speed);

        if (refNode == null)
        {
            if (m_SearchedRefNode == false)
            {
                MiddleVRTools.Log("[ ] Didn't find reference node " + ReferenceNode);
                m_SearchedRefNode = true;
            }

            motor.inputMoveDirection = directionVector;
        }
        else
        {
            motor.inputMoveDirection = refNode.transform.TransformDirection(directionVector);

            //print(motor.inputMoveDirection);
        }

        bool jump = false;

        if (Input.GetButton("Jump") == true)
        {
            jump = true;
        }

        if (keyb != null)
        {
            if (keyb.IsKeyPressed(MiddleVR.VRK_SPACE))
            {
                jump = true;
            }
        }

        if (MiddleVR.VRDeviceMgr.IsWandButtonToggled(1) == true)
        {
            jump = true;
        }

        motor.inputJump = jump;
    }
Example #17
0
    // Update is called once per frame
    protected void Update()
    {
        // Initialize interactions
        if (!m_InteractionsInitialized)
        {
            _SetNavigation(Navigation);
            _SetManipulation(Manipulation);
            _SetVirtualHandMapping(VirtualHandMapping);

            m_InteractionsInitialized = true;
        }

        MVRNodesMapper nodesMapper = MVRNodesMapper.Instance;

        nodesMapper.UpdateNodesUnityToMiddleVR();

        if (m_isInit)
        {
            MVRTools.Log(4, "[>] Unity Update - Start");

            if (m_Kernel.GetFrame() >= m_FirstFrameAfterReset + 1 && !m_isGeometrySet && !Application.isEditor)
            {
                if (!DontChangeWindowGeometry)
                {
                    m_DisplayMgr.SetUnityWindowGeometry();
                }
                m_isGeometrySet = true;
            }

            // Set the random seed in kernel for dispatching only during start-up.
            if (m_Kernel.GetFrame() == 0)
            {
                // Disable obsolescence warning for Random.seed as we only use it to initalize
                // the MiddleVR random seed.
                // Using Random.seed was deprecated because it is a single integer and does not
                // contain the full state of the random number generator and thus could not be
                // used for restoring or synchronizing the state.
#pragma warning disable 618
                // The cast is safe because the seed is always positive.
                m_Kernel._SetRandomSeed((uint)UnityEngine.Random.seed);
#pragma warning restore 618

                // With clustering, a client will be set by a call to kernel.Update().
                if (m_ClusterMgr.IsCluster())
                {
                    if (m_shareRandomStateCommand == null)
                    {
                        m_shareRandomStateCommand = new vrCommand("MVR_ShareRandomState", (vrValue val) =>
                        {
                            UnityEngine.Random.state = JsonUtility.FromJson <UnityEngine.Random.State>(val.GetString());
                            return(new vrValue());
                        });
                    }

                    if (m_ClusterMgr.IsServer())
                    {
                        m_shareRandomStateCommand.Do(new vrValue(JsonUtility.ToJson(UnityEngine.Random.state)));
                    }
                }
            }

            m_Kernel.Update();

            UpdateInput();

            if (ShowFPS)
            {
                m_FPSText.text = m_Kernel.GetFPS().ToString("f2");
            }

            nodesMapper.UpdateNodesMiddleVRToUnity(false);

            MVRTools.UpdateCameraProperties(m_Kernel, m_DisplayMgr, nodesMapper);

            vrKeyboard keyb = m_DeviceMgr.GetKeyboard();

            if (keyb != null)
            {
                if (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT))
                {
                    if (keyb.IsKeyToggled(MiddleVR.VRK_D))
                    {
                        ShowFPS = !ShowFPS;
                    }

                    if (keyb.IsKeyToggled(MiddleVR.VRK_W) || keyb.IsKeyToggled(MiddleVR.VRK_Z))
                    {
                        ShowWand = !ShowWand;
                        ShowWandGeometry(ShowWand);
                    }

                    // Toggle Fly mode on interactions
                    if (keyb.IsKeyToggled(MiddleVR.VRK_F))
                    {
                        Fly = !Fly;
                    }

                    // Navigation mode switch
                    if (keyb.IsKeyToggled(MiddleVR.VRK_N))
                    {
                        vrInteraction navigation = _GetNextInteraction("ContinuousNavigation");
                        if (navigation != null)
                        {
                            MiddleVR.VRInteractionMgr.Activate(navigation);
                        }
                    }
                }
            }

            DeltaTime = m_Kernel.GetDeltaTime();

            MVRTools.Log(4, "[<] Unity Update - End");
        }
        else
        {
            //Debug.LogWarning("[ ] If you have an error mentioning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable.");
        }
    }
Example #18
0
    // Update is called once per frame
    void Update()
    {
        //MiddleVRTools.Log("VRManagerUpdate");

        if (m_isInit)
        {
            MiddleVRTools.Log(4, "[>] Unity Update - Start");

            if (kernel.GetFrame() >= m_FirstFrameAfterReset + 1 && !m_isGeometrySet && !Application.isEditor)
            {
                if (!DontChangeWindowGeometry)
                {
                    displayMgr.SetUnityWindowGeometry();
                }
                m_isGeometrySet = true;
            }

            kernel.Update();
            UpdateInput();

            if (ShowFPS)
            {
                guiText.text = kernel.GetFPS().ToString("f2");
            }

            MiddleVRTools.UpdateNodes();

            if (m_displayLog)
            {
                string txt = kernel.GetLogString(true);
                print(txt);
                m_GUI.text = txt;
            }

            vrKeyboard keyb = MiddleVR.VRDeviceMgr.GetKeyboard();

            if (keyb != null && keyb.IsKeyToggled(MiddleVR.VRK_F) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                ShowFPS         = !ShowFPS;
                guiText.enabled = ShowFPS;
            }

            if (keyb != null && (keyb.IsKeyToggled(MiddleVR.VRK_W) || keyb.IsKeyToggled(MiddleVR.VRK_Z)) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                ShowWand = !ShowWand;
                ShowWandGeometry(ShowWand);
            }

            DeltaTime = kernel.GetDeltaTime();

            MiddleVRTools.Log(4, "[<] Unity Update - End");
        }
        else
        {
            //Debug.LogWarning("[ ] If you have an error mentionning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable.");
        }

        // If QualityLevel changed, we have to reset the Unity Manager
        if (m_NeedDelayedRenderingReset)
        {
            if (m_RenderingResetDelay == 0)
            {
                MiddleVRTools.Log(3, "[ ] Graphic quality forced, reset Unity Manager.");
                MiddleVRTools.VRReset();
                MiddleVRTools.CreateViewportsAndCameras(DontChangeWindowGeometry, m_AllowRenderTargetAA);
                m_isGeometrySet             = false;
                m_NeedDelayedRenderingReset = false;
            }
            else
            {
                --m_RenderingResetDelay;
            }
        }
    }
Example #19
0
    IEnumerator EndOfFrame()
    {
        yield return(new WaitForEndOfFrame());

        VRManagerScript mgr = GetComponent <VRManagerScript>();

        if (mgr != null && MiddleVR.VRKernel == null)
        {
            Debug.LogWarning("[ ] If you have an error mentionning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable.");
            mgr.guiText.text = "[ ] Check the console window to check if you have an error mentionning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable.";
        }

        MiddleVRTools.Log(4, "[>] VR End of Frame.");

        if (kernel == null)
        {
            kernel = MiddleVR.VRKernel;
        }

        if (dmgr == null)
        {
            dmgr = MiddleVR.VRDeviceMgr;
        }

        if (dmgr != null)
        {
            vrKeyboard keyb = dmgr.GetKeyboard();
            if (keyb != null)
            {
                VRManagerScript vrmgr = GetComponent <VRManagerScript>();

                if (vrmgr != null && vrmgr.QuitOnEsc && keyb.IsKeyPressed((uint)MiddleVR.VRK_ESCAPE))
                {
                    if (Application.isEditor)
                    {
                        MiddleVRTools.Log("[ ] If we were in player mode, MiddleVR would exit.");
                    }
                    else
                    {
                        MiddleVRTools.Log("[ ] Unity says we're quitting.");
                        MiddleVR.VRKernel.SetQuitting();
                        Application.Quit();
                    }
                }
            }
            else
            {
                if (!LoggedNoKeyboard)
                {
                    MiddleVRTools.Log("[X] No VR keyboard");
                    LoggedNoKeyboard = true;
                }
            }
        }

        if (kernel != null)
        {
            /*
             * MiddleVRTools.Log("SavingRT"); ;
             * SaveRT();
             */
            kernel.PostFrameUpdate();
        }

        MiddleVRTools.Log(4, "[<] End of VR End of Frame.");

        if (kernel != null && kernel.GetFrame() == 2 && !Application.isEditor)
        {
            MiddleVRTools.Log(2, "[ ] If the application is stuck here and you're using Quad-buffer active stereoscopy, make sure that in the Player Settings of Unity, the option 'Run in Background' is checked.");
        }
    }
Example #20
0
    // Update is called once per frame
    void Update()
    {
        //MiddleVRTools.Log("VRManagerUpdate");

        if (m_isInit)
        {
            MiddleVRTools.Log(4, "[>] Unity Update - Start");

            if (kernel.GetFrame() >= m_FirstFrameAfterReset + 1 && !m_isGeometrySet && !Application.isEditor)
            {
                if (!DontChangeWindowGeometry)
                {
                    displayMgr.SetUnityWindowGeometry();
                }
                m_isGeometrySet = true;
            }

            kernel.Update();
            UpdateInput();

            if (ShowFPS)
            {
                guiText.text = kernel.GetFPS().ToString("f2");
            }

            MiddleVRTools.UpdateNodes();

            if (m_displayLog)
            {
                string txt = kernel.GetLogString(true);
                print(txt);
                m_GUI.text = txt;
            }

            vrKeyboard keyb = MiddleVR.VRDeviceMgr.GetKeyboard();

            if (keyb != null && keyb.IsKeyToggled(MiddleVR.VRK_D) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                ShowFPS         = !ShowFPS;
                guiText.enabled = ShowFPS;
            }

            if (keyb != null && (keyb.IsKeyToggled(MiddleVR.VRK_W) || keyb.IsKeyToggled(MiddleVR.VRK_Z)) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                ShowWand = !ShowWand;
                ShowWandGeometry(ShowWand);
            }

            // Toggle Fly mode on interactions
            if (keyb != null && keyb.IsKeyToggled(MiddleVR.VRK_F) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                vrInteractionManager interMan = vrInteractionManager.GetInstance();
                uint interactionNb            = interMan.GetInteractionsNb();
                for (uint i = 0; i < interactionNb; ++i)
                {
                    vrProperty flyProp = interMan.GetInteractionByIndex(i).GetProperty("Fly");
                    if (flyProp != null)
                    {
                        flyProp.SetBool(!flyProp.GetBool());
                    }
                }
            }

            // Navigation mode switch
            if (keyb != null && keyb.IsKeyToggled(MiddleVR.VRK_N) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                // Disable current nav
                MonoBehaviour currentNavigation = (MonoBehaviour)m_Wand.GetComponent((string)m_NavigationScipts[m_CurrentNavigationNb]);
                if (currentNavigation != null)
                {
                    currentNavigation.enabled = false;
                }

                // Enable next nav
                m_CurrentNavigationNb = (m_CurrentNavigationNb + 1) % m_NavigationScipts.Count;

                currentNavigation = (MonoBehaviour)m_Wand.GetComponent((string)m_NavigationScipts[m_CurrentNavigationNb]);
                if (currentNavigation != null)
                {
                    currentNavigation.enabled = true;
                }
            }

            DeltaTime = kernel.GetDeltaTime();

            MiddleVRTools.Log(4, "[<] Unity Update - End");
        }
        else
        {
            //Debug.LogWarning("[ ] If you have an error mentionning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable.");
        }

        // If QualityLevel changed, we have to reset the Unity Manager
        if (m_NeedDelayedRenderingReset)
        {
            if (m_RenderingResetDelay == 0)
            {
                MiddleVRTools.Log(3, "[ ] Graphic quality forced, reset Unity Manager.");
                MiddleVRTools.VRReset();
                MiddleVRTools.CreateViewportsAndCameras(DontChangeWindowGeometry, m_AllowRenderTargetAA);
                m_isGeometrySet             = false;
                m_NeedDelayedRenderingReset = false;
            }
            else
            {
                --m_RenderingResetDelay;
            }
        }
    }
Example #21
0
    // Update is called once per frame
    void Update()
    {
        //MVRTools.Log("VRManagerUpdate");

        // Initialize interactions
        if (!m_InteractionsInitialized)
        {
            _SetNavigation(Navigation);
            _SetManipulation(Manipulation);
            _SetVirtualHandMapping(VirtualHandMapping);

            m_InteractionsInitialized = true;
        }

        MVRNodesMapper nodesMapper = MVRNodesMapper.Instance;

        nodesMapper.UpdateNodesUnityToMiddleVR();

        if (m_isInit)
        {
            MVRTools.Log(4, "[>] Unity Update - Start");

            if (m_Kernel.GetFrame() >= m_FirstFrameAfterReset + 1 && !m_isGeometrySet && !Application.isEditor)
            {
                if (!DontChangeWindowGeometry)
                {
                    m_DisplayMgr.SetUnityWindowGeometry();
                }
                m_isGeometrySet = true;
            }

            if (m_Kernel.GetFrame() == 0)
            {
                // Set the random seed in kernel for dispatching only during start-up.
                // With clustering, a client will be set by a call to kernel.Update().
                if (!m_ClusterMgr.IsCluster() ||
                    (m_ClusterMgr.IsCluster() && m_ClusterMgr.IsServer()))
                {
                    // The cast is safe because the seed is always positive.
                    uint seed = (uint)UnityEngine.Random.seed;
                    m_Kernel._SetRandomSeed(seed);
                }
            }

            m_Kernel.Update();

            if (m_Kernel.GetFrame() == 0)
            {
                // Set the random seed in a client only during start-up.
                if (m_ClusterMgr.IsCluster() && m_ClusterMgr.IsClient())
                {
                    // The cast is safe because the seed comes from
                    // a previous value of Unity.
                    int seed = (int)m_Kernel.GetRandomSeed();
                    UnityEngine.Random.seed = seed;
                }
            }

            UpdateInput();

            if (ShowFPS)
            {
                this.GetComponent <GUIText>().text = m_Kernel.GetFPS().ToString("f2");
            }

            nodesMapper.UpdateNodesMiddleVRToUnity(false);

            MVRTools.UpdateCameraProperties();

            if (m_displayLog)
            {
                string txt = m_Kernel.GetLogString(true);
                print(txt);
                m_GUI.text = txt;
            }

            vrKeyboard keyb = m_DeviceMgr.GetKeyboard();

            if (keyb != null)
            {
                if (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT))
                {
                    if (keyb.IsKeyToggled(MiddleVR.VRK_D))
                    {
                        ShowFPS = !ShowFPS;
                    }

                    if (keyb.IsKeyToggled(MiddleVR.VRK_W) || keyb.IsKeyToggled(MiddleVR.VRK_Z))
                    {
                        ShowWand = !ShowWand;
                        ShowWandGeometry(ShowWand);
                    }

                    // Toggle Fly mode on interactions
                    if (keyb.IsKeyToggled(MiddleVR.VRK_F))
                    {
                        Fly = !Fly;
                    }

                    // Navigation mode switch
                    if (keyb.IsKeyToggled(MiddleVR.VRK_N))
                    {
                        vrInteraction navigation = _GetNextInteraction("ContinuousNavigation");
                        if (navigation != null)
                        {
                            MiddleVR.VRInteractionMgr.Activate(navigation);
                        }
                    }
                }
            }

            DeltaTime = m_Kernel.GetDeltaTime();

            MVRTools.Log(4, "[<] Unity Update - End");
        }
        else
        {
            //Debug.LogWarning("[ ] If you have an error mentioning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable.");
        }

        // If QualityLevel changed, we have to reset the Unity Manager
        if (m_NeedDelayedRenderingReset)
        {
            if (m_RenderingResetDelay == 0)
            {
                MVRTools.Log(3, "[ ] Graphic quality forced, reset Unity Manager.");
                MVRTools.VRReset();
                MVRTools.CreateViewportsAndCameras(DontChangeWindowGeometry, m_AllowRenderTargetAA);
                m_isGeometrySet             = false;
                m_NeedDelayedRenderingReset = false;
            }
            else
            {
                --m_RenderingResetDelay;
            }
        }
    }
Example #22
0
    void Update()
    {
        if (!begin)
        {
            return;
        }

        vrKeyboard keyboard = MiddleVR.VRDeviceMgr.GetKeyboard();

        // Apply new transform
        if (keyboard != null)
        {
            // Hold down W to activate x, y move
            if (keyboard.IsKeyPressed(MiddleVR.VRK_W))
            {
                if (keyboard.IsKeyPressed(MiddleVR.VRK_RIGHT))
                {
                    xDist += increment;
                }
                if (keyboard.IsKeyPressed(MiddleVR.VRK_LEFT))
                {
                    xDist -= increment;
                }
                if (keyboard.IsKeyPressed(MiddleVR.VRK_UP))
                {
                    yDist += increment;
                }
                if (keyboard.IsKeyPressed(MiddleVR.VRK_DOWN))
                {
                    yDist -= increment;
                }
            }
            // Hold down E to activate y, z rotation
            if (keyboard.IsKeyPressed(MiddleVR.VRK_E))
            {
                if (keyboard.IsKeyPressed(MiddleVR.VRK_RIGHT))
                {
                    roll += increment;
                }
                if (keyboard.IsKeyPressed(MiddleVR.VRK_LEFT))
                {
                    roll -= increment;
                }
                if (keyboard.IsKeyPressed(MiddleVR.VRK_UP))
                {
                    yaw += increment;
                }
                if (keyboard.IsKeyPressed(MiddleVR.VRK_DOWN))
                {
                    yaw -= increment;
                }
            }
            //	Press R to reset
            if (keyboard.IsKeyToggled(MiddleVR.VRK_R))
            {
                if (wantToReset)
                {
                    reset();
                }
                else
                {
                    wantToReset = true;
                }
            }
            // Press + to increase movement amount
            if (keyboard.IsKeyToggled(MiddleVR.VRK_EQUALS))
            {
                int magnitude = 1;
                if (keyboard.IsKeyPressed(MiddleVR.VRK_LSHIFT))
                {
                    magnitude = 10;
                }
                increment += (incrementFidelity * magnitude);
            }// Press - to increase movement amount
            if (keyboard.IsKeyToggled(MiddleVR.VRK_MINUS))
            {
                int magnitude = 1;
                if (keyboard.IsKeyPressed(MiddleVR.VRK_LSHIFT))
                {
                    magnitude = 10;
                }
                increment -= (incrementFidelity * magnitude);
                if (increment < 0)
                {
                    increment = 0;
                }
            }
        }

        // Display the values
        string text = "<size=20>Pos:(" + xDist + ", " + yDist + ", 0)</size>\nRot:(0, " + roll + ", " + yaw + ")\n<size=10>Adjustment: " + increment + "</size>";

        GetComponent <TextMesh>().text = text;

        print(text);

        applyOffset();
    }