// 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..."); } }
// 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; } } } }