// Update is called once per frame public void Update() { if (MiddleVR.VRClusterMgr.IsClient() && m_STScript != null) { if (m_tracker == null && MiddleVR.VRDeviceMgr != null) { m_tracker = MiddleVR.VRDeviceMgr.GetTracker(m_STScript.ShareName); MiddleVRTools.Log("[+] Acquired shared tracker " + m_tracker.GetName()); } if (m_tracker != null) { // Get rid of anything that could move the object //Destroy(rigidbody); vrVec3 pos = m_tracker.GetPosition(); vrQuat or = m_tracker.GetOrientation(); Vector3 p = new Vector3(pos.x(), pos.y(), pos.z()); Quaternion q = new Quaternion((float)or.x(), (float)or.y(), (float)or.z(), (float)or.w()); transform.position = p; transform.rotation = q; //MiddleVRTools.Log("Client applying data : " + p.z ); } } }
// Update is called once per frame void Update() { // Get the input vector from keyboard or analog stick Vector3 directionVector; directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); //print (directionVector); if (CAVE) { print("CAAAAVVVVVEEEEEE"); vrTracker wand = null; vrAxis axis = null; if (MiddleVR.VRDeviceMgr != null) { wand = MiddleVR.VRDeviceMgr.GetTracker("VRPNTracker0.Tracker1"); axis = MiddleVR.VRDeviceMgr.GetAxis("VRPNAxis0.Axis"); } print("Wand_[x,y,z]: " + wand.GetPosition().x() + "," + wand.GetPosition().y() + "," + wand.GetPosition().z()); print("Axis Value: " + axis.GetValue(0) + ", " + axis.GetValue(1)); directionVector = new Vector3(0, 0, axis.GetValue(1)); print("directionVector = " + directionVector); } if (directionVector != Vector3.zero) { // Get the length of the directon vector and then normalize it // Dividing by the length is cheaper than normalizing when we already have the length anyway float directionLength = directionVector.magnitude; directionVector = directionVector / directionLength; // Make sure the length is no bigger than 1 directionLength = Mathf.Min(1, directionLength); // Make the input vector more sensitive towards the extremes and less sensitive in the middle // This makes it easier to control slow speeds when using analog sticks directionLength = directionLength * directionLength; // Multiply the normalized direction vector by the modified length directionVector = directionVector * directionLength; } // Apply the direction to the CharacterMotor cmotor.inputMoveDirection = transform.rotation * directionVector; cmotor.inputJump = Input.GetButton("Jump"); }
private void TestDevices() { vrTracker tracker = null; vrJoystick joy = null; vrAxis axis = null; vrButtons buttons = null; var deviceMgr = MiddleVR.VRDeviceMgr; // Getting a reference to different device types if (deviceMgr != null) { tracker = deviceMgr.GetTracker("VRPNTracker0.Tracker0"); joy = deviceMgr.GetJoystickByIndex(0); axis = deviceMgr.GetAxis("VRPNAxis0.Axis"); buttons = deviceMgr.GetButtons("VRPNButtons0.Buttons"); } // Getting tracker data if (tracker != null) { MVRTools.Log("TrackerX : " + tracker.GetPosition().x()); } // Testing joystick button if (joy != null && joy.IsButtonPressed(0)) { MVRTools.Log("Joystick!"); } // Testing axis value if (axis != null && axis.GetValue(0) > 0) { MVRTools.Log("Axis Value: " + axis.GetValue(0)); } // Testing button state if (buttons != null) { if (buttons.IsToggled(0)) { MVRTools.Log("Button 0 pressed !"); } if (buttons.IsToggled(0, false)) { MVRTools.Log("Button 0 released !"); } } }
// Grab latest controller data void Update() { leftJoyInput.x = leftJoystick.GetAxisValue(0); leftJoyInput.y = leftJoystick.GetAxisValue(1); rightJoyInput.x = rightJoystick.GetAxisValue(0); rightJoyInput.y = rightJoystick.GetAxisValue(1); leftTrackerPos = MiddleVRTools.ToUnity(leftTracker.GetPosition()); rightTrackerPos = MiddleVRTools.ToUnity(rightTracker.GetPosition()); leftTrackerAccel = (leftTrackerPos - lastLeftTrackerPos) * Time.deltaTime * 100000f; rightTrackerAccel = (rightTrackerPos - lastRightTrackerPos) * Time.deltaTime * 100000f; balance = Mathf.Clamp((leftTrackerPos.y - rightTrackerPos.y) * 100f, -30f, 30f); balanceZ = Mathf.Clamp((leftTrackerPos.z - rightTrackerPos.z) * 100f, -30f, 30f); lastLeftTrackerPos = leftTrackerPos; lastRightTrackerPos = rightTrackerPos; leftTrigger = leftJoystick.IsButtonPressed(0); rightTrigger = rightJoystick.IsButtonPressed(0); }