Example #1
0
        // Update is called once per frame
        void Update()
        {
            if (deviceController != null && deviceController.GetDevice() != null)
            {
                CVirtDevice virtDevice = deviceController.GetDevice();

                float sumForce = 0;

                foreach (CVirtHapticEmitter emitter in emitters)
                {
                    float distance = Vector3.Distance(this.transform.position, emitter.transform.position);
                    if (distance < maxRange && distance < emitter.distance)
                    {
                        float force = emitter.EvaluateForce(this.transform.position);
                        if (sumForce < force)
                        {
                            sumForce = force;
                        }
                        //sumForce = SumUpDecibal(force, force);
                    }
                }

                if (virtDevice.HasHaptic())
                {
                    virtDevice.HapticSetVolume(Mathf.FloorToInt(100f * sumForce));
                }
            }
        }
Example #2
0
 // Update is called once per frame
 void Update()
 {
     //If device controller is not present switch to OVRMainMenu automatically
     if (deviceController != null && deviceController.GetDevice() != null)
     {
         // R will reset the orientation based on player input ('R' key)
         UpdateResetOrientation();
     }
     else
     {
         SwitchToOVRMainMenu();
     }
 }
Example #3
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));
                    }
                }
            }
        }
    }
Example #4
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;
        }
    }