/// <summary> /// Asynchronous method taking in button input and sending it to the current selected tool /// </summary> /// <returns></returns> private IEnumerator Button() { int maxButtons = trackerButtonList.getMaxButtons(); while (true) { Vector3 origin = wandObject.transform.position; Vector3 direction = wandObject.transform.forward; //i tracks the number of the current button for (int i = 0; i < maxButtons; ++i) { //Current value of the button bool curValue = VRPN.vrpnButton(trackerAddress, i); TrackerButton currentButton = trackerButtonList.MapButton(i); //If the previous state is true and the current value is false it is a button click if (buttonState.ContainsKey(currentButton) && buttonState[currentButton] && !curValue) { //Fire the event toolManager.handleButtonClick(currentButton, origin, direction); //hasStarted = false; hit = new RaycastHit(); //temp; } //If the current and previous are true then it is a buttondrag event else if (buttonState.ContainsKey(currentButton) && buttonState[currentButton] && curValue && (currentButton == TrackerButton.Trigger)) { if (hit.distance > 0) { //Fire the event toolManager.handleButtonDrag(currentButton, hit, offset, origin, direction); } } //If the previous is false and the current is true else if (!(buttonState.ContainsKey(currentButton) && buttonState[currentButton]) && curValue && (currentButton == TrackerButton.Trigger)) { Physics.Raycast(origin, direction * rayLength, out hit); if (hit.distance > 0) { offset = hit.transform.position - hit.point; } toolManager.handleButtonDown(currentButton, hit, origin, direction); } //update the previous value buttonState[currentButton] = curValue; } yield return(null); } }
/// <summary> /// Obtains the correct trackpad and trigger button values directly from VRPN and sets /// ClusterInput entries to correct value. Implemented because initial values /// from ClusterInput are incorrect. /// </summary> private static System.Collections.IEnumerator endOfFrameForMaster() { yield return new WaitForEndOfFrame(); //Trackpad button updates ClusterInput.SetButton("leftTrackpad", VRPN.vrpnButton("CC_FLAT_WAND0@" + CC_CONFIG.serverIP, 32)); ClusterInput.SetButton("rightTrackpad", VRPN.vrpnButton("CC_FLAT_WAND1@" + CC_CONFIG.serverIP, 32)); //Trackpad axis updates ClusterInput.SetAxis("leftXAxis", (float)VRPN.vrpnAnalog("CC_FLAT_WAND0@" + CC_CONFIG.serverIP, 0)); ClusterInput.SetAxis("leftYAxis", (float)VRPN.vrpnAnalog("CC_FLAT_WAND0@" + CC_CONFIG.serverIP, 1)); ClusterInput.SetAxis("rightXAxis", (float)VRPN.vrpnAnalog("CC_FLAT_WAND1@" + CC_CONFIG.serverIP, 0)); ClusterInput.SetAxis("rightYAxis", (float)VRPN.vrpnAnalog("CC_FLAT_WAND1@" + CC_CONFIG.serverIP, 1)); //Trigger button updates ClusterInput.SetButton("leftTrigger", VRPN.vrpnButton("CC_FLAT_WAND0@" + CC_CONFIG.serverIP, 33)); ClusterInput.SetButton("rightTrigger", VRPN.vrpnButton("CC_FLAT_WAND1@" + CC_CONFIG.serverIP, 33)); //Trigger axis updates ClusterInput.SetAxis("leftTriggerAxis", (float)VRPN.vrpnAnalog("CC_FLAT_WAND0@" + CC_CONFIG.serverIP, 2)); ClusterInput.SetAxis("rightTriggerAxis", (float)VRPN.vrpnAnalog("CC_FLAT_WAND1@" + CC_CONFIG.serverIP, 2)); }
/// <summary> /// Initial call to VRPN to allow data retrieval later /// in the program. /// </summary> private static System.Collections.IEnumerator oneTimeServerVrpnSet() { yield return new WaitForEndOfFrame(); //Trackpad button entries VRPN.vrpnButton("CC_FLAT_WAND0@" + CC_CONFIG.serverIP, 32); VRPN.vrpnButton("CC_FLAT_WAND1@" + CC_CONFIG.serverIP, 32); //Trackpad axis entries VRPN.vrpnAnalog("CC_FLAT_WAND0@" + CC_CONFIG.serverIP, 0); VRPN.vrpnAnalog("CC_FLAT_WAND0@" + CC_CONFIG.serverIP, 1); VRPN.vrpnAnalog("CC_FLAT_WAND1@" + CC_CONFIG.serverIP, 0); VRPN.vrpnAnalog("CC_FLAT_WAND1@" + CC_CONFIG.serverIP, 1); //Trigger button entries VRPN.vrpnButton("CC_FLAT_WAND0@" + CC_CONFIG.serverIP, 33); VRPN.vrpnButton("CC_FLAT_WAND1@" + CC_CONFIG.serverIP, 33); //Trigger axis entry VRPN.vrpnAnalog("CC_FLAT_WAND0@" + CC_CONFIG.serverIP, 2); VRPN.vrpnAnalog("CC_FLAT_WAND1@" + CC_CONFIG.serverIP, 2); }
private IEnumerator Button() { while (true) { for (int i = 0; i < numButtons; ++i) { if (VRPN.vrpnButton(trackerAddress, i)) { if (debugOutput) { Debug.Log("Button " + i + " pressed on channel " + channel); } yield return(new WaitForSeconds(.2f)); } } yield return(null); } }
/// <summary> /// Gets the latest pushed button on tracker from vrpn. Stops after a preset amount of time (2 seconds currently). /// </summary> /// <returns>The number of the pushed button (0...n-1) or -1 if no button is pushed on tracker.</returns> public int GetPushedButton() { lastButtonPressed = -1; for (int ii = 0; ii < MAX_LOOPS_BUTTON_CHECK; ii++) { for (int jj = 0; jj < maxButtons; jj++) { bool btnValue = VRPN.vrpnButton(trackerAddress, jj, ii); if (btnValue) { lastButtonPressed = jj; } } if (lastButtonPressed > -1) { return(lastButtonPressed); } Thread.Sleep(SLEEP_TIMEOUT); } return(-1); }
//added by pohl 9.12.16 public static bool vrpnTrackerButton(string address, int channel) { return(VRPN.vrpnButton(address, channel)); }