// Use this for initialization
    void Start()
    {
        #if UNITY_EDITOR || UNITY_STANDALONE_WIN
        switch (deviceTypeIndex)
        {
        //Auto selection
        case 0:
            virtDevice = getStandardVirtualizerDevice();
            if (virtDevice == null)
            {
                fallbackToStandardCoupled();
                return;
            }
            break;

        //Standard de-coupled virtualizer input
        case 1:
            virtDevice = getStandardVirtualizerDevice();
            break;

        //TODO: Standard coupled movement input
        case 2:
            fallbackToStandardCoupled();
            return;

        //Faild to find VirtDevice
        default:
            break;
        }
        #endif

        #if UNITY_ANDROID
        virtDevice = new CVirtDeviceBluetooth();
        #endif

        if (virtDevice != null)
        {
            CLogger.Log("Virtualizer device found, connecting...");

            if (virtDevice.Open())
            {
                CLogger.Log("Successfully connected to Virtualizer device.");

                //Reset ResetPlayerOrientation and PlayerHeight
                virtDevice.ResetPlayerOrientation();
                virtDevice.GetPlayerHeight();
            }
            else
            {
                CLogger.LogError("Failed to connect to Virtualizer device.");
            }
        }
        else
        {
            CLogger.LogError("Virtualizer device not found...");
        }
    }
示例#2
0
 ///<summary>
 /// Handle quitting of game, critical errors (Unity crashing) will be thrown if this is not kept/defined
 /// </summary>
 /// <return>void</return>
 public void OnDestroy()
 {
     if (m_DeviceController != null)
     {
         CVirtDevice device = m_DeviceController.GetDevice();
         if (device != null)
         {
             if (device.IsOpen() == true)
             {
                 device.Close();
             }
         }
     }
 }
示例#3
0
    private CVirtDevice getStandardVirtualizerDevice()
    {
        CVirtDevice device = CVirt.FindDevice();

        if (device == null)
        {
            //If mockup is enabled and device null, find mockup input
            switch (deviceMockupTypeIndex)
            {
            case 1:
                device = CVirt.CreateDeviceMockupXInput();
                break;

            default:
                break;
            }
        }

        return(device);
    }
示例#4
0
    // Update is called once per frame
    void Update()
    {
        if (deviceController != null)
        {
            CVirtDevice virtDevice = deviceController.GetDevice();
            if (virtDevice != null)
            {
                // Get Virtualizer raw inputs
                /////////////////////////////
                Vector3 virtOrientation = virtDevice.GetPlayerOrientation();
                /*float virtHeight = virtDevice.GetPlayerHeight();*/
                Vector3 virtDirection = virtDevice.GetMovementDirection();
                float   virtSpeed     = virtDevice.GetMovementSpeed();

                // Turn
                ///////
                Quaternion rotation = new Quaternion();
                rotation.SetLookRotation(virtOrientation, Vector3.up);
                transform.localRotation = rotation;

                //TODO: Crouch
                /////////

                // Move Character
                /////////////////
                if (virtSpeed != 0.0f)
                {
                    virtSpeed = virtSpeed * movementSpeedMultiplier;

                    if (characterController != null)
                    {
                        this.characterController.SimpleMove(transform.TransformDirection(virtDirection * virtSpeed));
                    }
                }
            }
        }
    }
示例#5
0
    // Rotation is handled in the Update (since it is a more "sensitive" operation)
    private void Update()
    {
        if (m_DeviceController != null)
        {
            DebugLogger.Log("[CoupledMovement.cs] :: [1] :: Getting Virtualizer Device\r\n");
            m_Device = m_DeviceController.GetDevice();
        }
        else
        {
            DebugLogger.Log("[CoupledMovement.cs] :: [ERROR] :: Failed To Get Virtualizer Device!\r\n" +
                            "           -- m_DeviceController value is NULL\r\n" +
                            "           -- Is the Virtualizer plugged in?\r\n\r\n");
            Debug.LogException(new System.Exception("[Virtualizer Rig Error]: Device Controller Value Is Null"));
        }

        if (m_Device != null)
        {
            DebugLogger.Log("[CoupledMovement.cs] :: [2] :: Polling Rotation Threshold...\r\n");
            m_RotationThreshold = PlayerPrefs.GetFloat("RotSens");
            DebugLogger.Log("[CoupledMovement.cs] :: [2.1] :: Retrieved a value of [" + m_RotationThreshold.ToString() + "]\r\n");
            if (m_ResetOrientation)
            {
                DebugLogger.Log("[CoupledMovement.cs] :: [2.2] :: Resetting Player Orientation");
                m_Device.ResetPlayerOrientation();
                m_ResetOrientation = false;
            }

            if (useTriggersToTurn)
            {
                DebugLogger.Log("[CoupledMovement.cs] :: [2.3] :: Triggers ARE being used to turn\r\n");
                if (leftController.GetComponent <SteamVR_TrackedController>().triggerFullPress ||
                    rightController.GetComponent <SteamVR_TrackedController>().triggerFullPress)
                {
                    bodyRotation.transform.rotation = new Quaternion(0, cam.transform.rotation.y, 0, cam.transform.rotation.w);
                }
            }
            else
            {
                DebugLogger.Log("[CoupledMovement.cs] :: [2.3] :: Triggers are NOT being used to turn\r\n");


                // the analog nature of the treadmill's rotation ring makes this a somewhat unreliable way
                // of polling the user's rotation, motion capture would be preferable.
                DebugLogger.Log("[CoupledMovement.cs] :: [2.4] :: Polling Raw Device Orientation...\r\n");
                float rotation_raw = m_Device.GetOrientationRaw();
                DebugLogger.Log("       [2.4.1] :: Retrieved [" + rotation_raw.ToString() + "]\r\n");


                DebugLogger.Log("[CoupledMovement.cs] :: [2.5] :: Smoothing raw rotation...\r\n");
                // Smooth the analog data using standard signal smoothing math
                float rotation_smoothed = Filter(rotation_raw);
                DebugLogger.Log("       [2.5.1] :: Result [" + rotation_smoothed.ToString() + "]\r\n");


                // Get degree representation of rotation value
                float rotation_deg = rotation_smoothed * 360;

                //print("Rotation (deg): " + rotation_deg);

                // Create a new rotation from the smoothed data
                Quaternion ring_rot = Quaternion.Euler(0, rotation_deg, 0);


                /* TO DO:
                 * The folowing is not super stable, occasionally the orientation will reset or fail to set correctly
                 * this is needs to be fixed by some more rigourous testing of the angle changing process
                 */


                // Get the angle between the ring rotation and the previously saved rotation
                var curr_angle = Quaternion.Angle(ring_rot, m_OldRotation);


                // If the angle between the current rotation and the old angle is greater than some threshold value then change orientation of user
                if (Mathf.Abs(curr_angle - m_OldAngle) > m_RotationThreshold)
                {
                    bodyRotation.transform.rotation = new Quaternion(0, cam.transform.rotation.y, 0, cam.transform.rotation.w);
                    m_OldRotation = bodyRotation.transform.rotation;
                    m_OldAngle    = curr_angle;
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        float playerHeight = 0.0f;

        if (deviceController != null)
        {
            CVirtDevice virtDevice = deviceController.GetDevice();
            if (virtDevice != null)
            {
                // Get Virtualizer raw inputs
                /////////////////////////////
                Vector3 virtOrientation = virtDevice.GetPlayerOrientation();
                float   virtHeight      = virtDevice.GetPlayerHeight();
                Vector3 virtDirection   = virtDevice.GetMovementDirection();
                float   virtSpeed       = virtDevice.GetMovementSpeed();

                // Turn
                ///////
                Quaternion rotation = new Quaternion();
                rotation.SetLookRotation(virtOrientation, Vector3.up);
                forwardDirection.localRotation = rotation;

                // Hip Height
                /////////
                playerHeight = virtHeight / 100.0f;

                // Move Character
                /////////////////
                if (virtSpeed != 0.0f)
                {
                    virtSpeed = virtSpeed * movementSpeedMultiplier;

                    if (characterController != null)
                    {
                        this.characterController.SimpleMove((forwardDirection.TransformDirection(virtDirection)).normalized * virtSpeed);
                    }
                }
            }
        }

        if (useProfileHeight)
        {
            if (initialPose == null)
            {
                initialPose = new OVRPose()
                {
                    position    = cameraController.transform.localPosition,
                    orientation = cameraController.transform.localRotation
                };
            }

            var p = cameraController.transform.localPosition;
            p.y = (OVRManager.profile.eyeHeight - 0.5f * characterController.height) + playerHeight;
            p.z = OVRManager.profile.eyeDepth;
            cameraController.transform.localPosition = p;
        }
        else if (initialPose != null)
        {
            cameraController.transform.localPosition = initialPose.Value.position;
            cameraController.transform.localRotation = initialPose.Value.orientation;
            initialPose = null;
        }
    }
示例#7
0
    // Update is called once per frame
    void Update()
    {
        bool executeBaseUpdate = true;

        if (this.deviceController != null)
        {
            CVirtDevice device = this.deviceController.GetDevice();
            if (device != null)
            {
                if (device.IsOpen() == false)
                {
                    device.Open();
                }
                else
                {
#if !UNITY_EDITOR
                    executeBaseUpdate = false;
#endif

                    // MOVE
                    ///////////
                    Vector3 input = device.GetMovementDirection();
                    input *= device.GetMovementSpeed();

                    // ROTATION
                    ///////////
                    Vector3 newForward = device.GetPlayerOrientation();
                    if (this.forwardDirection != null)
                    {
                        this.forwardDirection.transform.localRotation = Quaternion.LookRotation(newForward, Vector3.up);
                    }

                    // Get the forward direction
                    Vector3 f = forwardDirection.forward;
                    f.y = 0f;

                    // If not dead, move
                    if (this.movementSpeedMultiplier != 0f)
                    {
                        characterController.SimpleMove(Quaternion.LookRotation(f) * (input * this.movementSpeedMultiplier) + 0.1f * Vector3.down);
                    }
                    else
                    {
                        characterController.SimpleMove(Vector3.zero);
                    }
                }
            }
        }

        // When a Virtualizer isn't plugged and we want
        // to test with keyboard/mouse for example
        ///////////////////////////////////////////////
        if (executeBaseUpdate == true)
        {
            Vector3 input = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));

            // Find the forward direction
            Vector3 f = forwardDirection.forward;
            f.y = 0f;

            characterController.SimpleMove(Quaternion.LookRotation(f) * Vector3.ClampMagnitude(input, 1f) * this.movementSpeedMultiplier * (Input.GetKey(KeyCode.LeftShift) ? 3.0F : 1.0F));           //@Cyberith: Run

            if (Input.GetKeyDown(KeyCode.E))
            {
                transform.rotation = Quaternion.Euler(0f, 45f, 0f) * transform.rotation;
            }
            else if (Input.GetKeyDown(KeyCode.Q))
            {
                transform.rotation = Quaternion.Euler(0f, -45f, 0f) * transform.rotation;
            }

            transform.rotation = Quaternion.Euler(0f, Input.GetAxis("Mouse X") * 2f, 0f) * transform.rotation;
        }
    }