// Update is called once per frame void Update() { //targetText.text = targets.ToString(); //RaycastHit hit; //Ray grabbingRay = new Ray (transform.position, Vector3.forward); //CharacterController charContr = GetComponent<CharacterController>(); //Debug.DrawRay (transform.position, Vector3.forward * grabHeight); PDIposition = VRPN.vrpnTrackerPos("TrackerJohn@localhost", 1); transform.position = PDIposition; if (Input.GetKeyDown("space")) //if (Physics.Raycast (grabbingRay, out hit, grabHeight) && hit.collider.tag=="calibrate") { //Debug.Log ("hit the avatar"); xpos.Add(PDIposition[0]); ypos.Add(PDIposition[1]); zpos.Add(PDIposition[2]); // hit.collider.transform //movedCircle = GameObject.FindWithTag("avatar"); //Destroy(hit.transform.gameObject); //touchedCircle = caliCircles.GetChild(targets); // DestroyObject(touchedCircle); targets++; targetNumber = targets.ToString(); pointNumber = string.Concat("point", targetNumber); GameObject removePoint = GameObject.Find(pointNumber); Destroy(removePoint); } else { } if (targets > 0) // participant only aims at middle dot. { getVirtualOrigin(); //getTableScale(); //getVirtualSurface(); Debug.Log("Calibration Completed"); Debug.Log(virtualOrigin); if (Input.GetKeyDown("s")) { SceneManager.LoadScene("ITI"); } } }
private IEnumerator Position() { while (true) { Vector3 pos = VRPN.vrpnTrackerPos(trackerAddress, channel); if (convertToLeft) { pos.x = Interlocked.Exchange(ref pos.z, pos.x); pos.y *= -1; transform.localPosition = pos; } else { transform.localPosition = pos; } //float temp = pos.z; //pos.z = pos.x; //pos.x = temp; // pos.y = -pos.y; yield return(null); } }
void InputDataGloves(string addressRight, string addressLeft) { tuplel[0] = VRPN.vrpnAnalog(addressLeft, 0); tuplel[1] = VRPN.vrpnAnalog(addressLeft, 1); tuplel[2] = VRPN.vrpnAnalog(addressLeft, 2); tuplel[3] = VRPN.vrpnAnalog(addressLeft, 3); tuplel[4] = VRPN.vrpnAnalog(addressLeft, 4); tuplel[5] = VRPN.vrpnAnalog(addressLeft, 5); tuplel[6] = VRPN.vrpnAnalog(addressLeft, 6); tuplel[7] = VRPN.vrpnAnalog(addressLeft, 7); tuplel[8] = VRPN.vrpnAnalog(addressLeft, 8); tuplel[9] = VRPN.vrpnAnalog(addressLeft, 9); tuplel[10] = VRPN.vrpnAnalog(addressLeft, 10); tuplel[11] = VRPN.vrpnAnalog(addressLeft, 11); tuplel[12] = VRPN.vrpnAnalog(addressLeft, 12); tuplel[13] = VRPN.vrpnAnalog(addressLeft, 13); meansl = GetMeansFromFile(filenamesl, 2); //TODO infol = TestFingers(tuplel, meansl); /* * Debug.Log("Glove raw left = " + String.Join(", ", * new List<double>(tuplel) * .ConvertAll(i => i.ToString()) * .ToArray())); * Debug.Log("GloveL = " + String.Join(", ", * new List<int>(infol) * .ConvertAll(i => i.ToString()) * .ToArray())); */ tuple[0] = VRPN.vrpnAnalog(addressRight, 0); tuple[1] = VRPN.vrpnAnalog(addressRight, 1); tuple[2] = VRPN.vrpnAnalog(addressRight, 2); tuple[3] = VRPN.vrpnAnalog(addressRight, 3); tuple[4] = VRPN.vrpnAnalog(addressRight, 4); tuple[5] = VRPN.vrpnAnalog(addressRight, 5); tuple[6] = VRPN.vrpnAnalog(addressRight, 6); tuple[7] = VRPN.vrpnAnalog(addressRight, 7); tuple[8] = VRPN.vrpnAnalog(addressRight, 8); tuple[9] = VRPN.vrpnAnalog(addressRight, 9); tuple[10] = VRPN.vrpnAnalog(addressRight, 10); tuple[11] = VRPN.vrpnAnalog(addressRight, 11); tuple[12] = VRPN.vrpnAnalog(addressRight, 12); tuple[13] = VRPN.vrpnAnalog(addressRight, 13); means = GetMeansFromFile(filenames, 2); //TODO info = TestFingers(tuple, means); //TODO /* * Debug.Log("Glove raw right= " + String.Join(", ", * new List<double>(tuple) * .ConvertAll(i => i.ToString()) * .ToArray())); * Debug.Log("GloveR = " + String.Join(", ", * new List<int>(info) * .ConvertAll(i => i.ToString()) * .ToArray())); */ }
public static Quaternion vrpnTrackerQuat(string address, int channel) { var quaternion = VRPN.vrpnTrackerQuat(address, channel); return(new Quaternion(-quaternion.x, -quaternion.z, -quaternion.y, quaternion.w)); //Quaternion quaternion = VRPN.vrpnTrackerQuat(address, channel); //if (quaternion == new Quaternion(-505, -505, -505, -505)) // return Quaternion.identity; ////Vector3 euler = quaternion.eulerAngles; //quaternion = ConvertRightHandedToLeftHandedQuaternion(quaternion); //Vector3 euler = quaternion2Euler(quaternion, RotSeq.zyx); ////quaternion = ConvertToRightHand(euler); ////euler = new Vector3(euler.x, euler.y, euler.z); ////quaternion = Quaternion.Euler(euler); ////quaternion = ConvertRightHandedToLeftHandedQuaternion(quaternion); ////euler = Quaternion.ToEulerAngles(quaternion)*Mathf.Rad2Deg; ////euler = new Vector3(euler.x, euler.z, euler.y); ////quaternion = Quaternion.Euler(euler); //return Quaternion.Euler(-euler.x, -euler.y, -euler.z); //return quaternion; //return new Quaternion(-quaternion.x, -quaternion.z, -quaternion.y, quaternion.w); }
public static Quaternion vrpnTrackerQuat(string address, int channel) { Quaternion quaternion = VRPN.vrpnTrackerQuat(address, channel); Vector3 euler = quaternion.eulerAngles; return(Quaternion.Euler(euler.x, -euler.y, -euler.z)); }
private IEnumerator Rotation() { while (true) { Quaternion rotation = VRPN.vrpnTrackerQuat(trackerAddress, channel); if (convertToLeft) { rotation.x = Interlocked.Exchange(ref rotation.z, rotation.x); rotation.y *= -1; transform.localRotation = rotation * Quaternion.Euler(trackerRotationOffset); } else { Vector3 fixedRotation = new Vector3(); fixedRotation.x = trackerRotationOffset.z; fixedRotation.y = trackerRotationOffset.y; fixedRotation.z = trackerRotationOffset.x; transform.localRotation = rotation * Quaternion.Euler(fixedRotation); } yield return(null); } }
private void OnAnimatorIK(int layerIndex) { transform.localPosition = new Vector3(controller.center.x, offset.y - 0.1f, controller.center.z); if (animator) { //Head movement animator.SetBoneLocalRotation(HumanBodyBones.Head, convertHeadRotation(headTransform.rotation)); //Spine movement Quaternion spineRotation = VRPN.vrpnTrackerQuat("CC_FLAT_PUCK0@" + CC_CONFIG.innovatorIP, 0) * Quaternion.AngleAxis(-90, Vector3.up) * Quaternion.AngleAxis(90, Vector3.forward); spineRotation = Quaternion.Euler(90f + spineRotation.eulerAngles.y, spineRotation.eulerAngles.x, 90f - spineRotation.eulerAngles.z); if (mirror) { spineRotation = Quaternion.Euler(spineRotation.eulerAngles.x, -spineRotation.eulerAngles.y, spineRotation.eulerAngles.z); } animator.SetBoneLocalRotation(HumanBodyBones.Spine, spineRotation); //Hip movement //Hand movement if (mirror) { handUpdate(AvatarIKGoal.LeftHand, rightMirrorGoal.localPosition, rightMirrorGoal.localRotation); handUpdate(AvatarIKGoal.RightHand, leftMirrorGoal.localPosition, leftMirrorGoal.localRotation); } else { //Left hand goal local tranformations leftHandGoal.transform.localPosition = leftHandTransform.localPosition; leftHandGoal.transform.localRotation = leftHandTransform.rotation * Quaternion.LookRotation(transform.forward); /* * Quaternion temp = leftHandGoal.transform.rotation; * if (reverseX) { * leftHandGoal.transform.rotation = new Quaternion(temp.x, temp.y, temp.z, -temp.w); * } * if (reverseZ) { * leftHandGoal.transform.rotation = new Quaternion(temp.x, temp.y, -temp.z, temp.w); * } */ //Right hand goal local transformations rightHandGoal.transform.localPosition = rightHandTransform.localPosition; rightHandGoal.transform.localRotation = rightHandTransform.localRotation * Quaternion.LookRotation(transform.forward); } //Update hand transforms handUpdate(AvatarIKGoal.LeftHand, leftHandGoal.transform.position, leftHandGoal.transform.rotation); handUpdate(AvatarIKGoal.RightHand, rightHandGoal.transform.position, rightHandGoal.transform.rotation); } }
private IEnumerator Position() { while (true) { transform.localPosition = VRPN.vrpnTrackerPos(trackerAddress, channel); yield return(null); } }
private void GetTrackerData(string name, int sensor) { PosVRPN = VRPN.vrpnTrackerPos(name, sensor); PosTracker.x = PosVRPN.x; PosTracker.y = -PosVRPN.z; PosTracker.z = -PosVRPN.y; //Debug.Log("X: "+PosTracker.x.ToString("N5")+" Y: " + PosTracker.y.ToString("N5") + " Z: "+ PosTracker.z.ToString("N5")); }
private Vector3 convertPuckPosition(Vector3 currentPos, int puckNum) { Vector3 rawVRPNpos = VRPN.vrpnTrackerPos("CC_FLAT_PUCK" + puckNum + "@" + CC_CONFIG.innovatorIP, 0); if ((rawVRPNpos.x != -505) || (rawVRPNpos.y != -505) || (rawVRPNpos.z != -505)) { return(convertPosition(convertToLeftHandPosition(rawVRPNpos))); } return(currentPos); }
/// <summary> /// Check to see if innovator tracking is valid. /// </summary> private bool checkInnovatorTracking() { /*if (VRPN.vrpnTrackerPos("CC_FLAT_HEAD@" + CC_CONFIG.trackerIP, 0) == new Vector3(-505, -505, -505)) { * return false; * }*/ if (VRPN.vrpnTrackerPos("CC_FLAT_HEAD@" + CC_CONFIG.innovatorIP, 0) == new Vector3(-505, -505, -505)) { return(false); } return(true); }
void InputDataTracker(string address) { posVRPN = VRPN.vrpnTrackerPos(address, 2); x = 1 * posVRPN.x; y = -1 * posVRPN.z; z = -1 * posVRPN.y; actualTracker = new Vector3(x, y, z); Debug.Log(new Vector3(x * 1000, y * 1000, z * 1000)); }
// Update is called once per frame void Update() { if (trackPosition) { transform.position = VRPN.vrpnTrackerPos(obj + "@" + host, channel); } if (trackRotation) { transform.rotation = VRPN.vrpnTrackerQuat(obj + "@" + host, channel); } }
/// <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); } }
// Update is called once per frame void Update() { System.DateTime epochStart = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc); int now = (int)(System.DateTime.UtcNow - epochStart).TotalSeconds; if (now - started > timeout) { //Remove do vetor para poder inserir novamente caso seja necessario VRPN vrpn = GameObject.Find("starter").GetComponent <VRPN> (); vrpn.removeFromGuide(this.gameObject.transform.position); Destroy(this.gameObject); } }
/// <summary> /// Asyncronous method that handles all the input from the analog stick /// </summary> /// <returns></returns> private IEnumerator Analog() { while (true) { //Get the X and Y values from the joystick double analogVertical = VRPN.vrpnAnalog(trackerAddress, channelVertical); double analogHorizontal = VRPN.vrpnAnalog(trackerAddress, channelHorizontal); //Translate the holder toolManager.handleAnalog(analogHorizontal, analogVertical); yield return(null); } }
// Use this for initialization void Start () { vrpn = GameObject.Find ("starter").GetComponent<VRPN> (); trackerNameField = GameObject.Find ("trackerNameField").GetComponent<InputField>(); toogle = GetComponent<Toggle> (); updateIsOn (); anotherToogles = new Toggle[anotherChecks.Length]; for (int i = 0; i < anotherChecks.Length; i++) { anotherToogles[i] = anotherChecks[i].GetComponent<Toggle> (); } updateTrackerField (); }
////////////// THREADING /////////////////// // Put what you want threaded in Task.Run *see below) // This gets called in Start(); void GetPolhemusData() { Vector3 PDIposition = VRPN.vrpnTrackerPos(deviceName + "@" + deviceIP, sensor); float xpos = PDIposition [0]; float ypos = PDIposition [1]; float zpos = -1 * PDIposition [2]; //string dataString = (xpos + "," + ypos + "," + zpos.ToString); Vector3 scalePDIposition = new Vector3(tableScaleX * xpos, tableScaleY * ypos, zpos); //Vector3 tablePosition = scalePDIposition - tableOrigin; // SensorString.Add(dataString); SensorData.Add(scalePDIposition.ToString("F3")); //SensorData.Add(scalePDIposition,DateTime.UtcNow.ToString("hh:mm:ss.ffffff")); }
// Use this for initialization void Start() { //Initial calls to VRPN for puck 0, 1, 2 entries for (int i = 0; i < 3; i++) { VRPN.vrpnTrackerPos("CC_FLAT_PUCK" + i + "@" + CC_CONFIG.innovatorIP, 0); VRPN.vrpnTrackerQuat("CC_FLAT_PUCK" + i + "@" + CC_CONFIG.innovatorIP, 0); } headReference = transform.GetChild(0).gameObject.transform; leftWandReference = transform.GetChild(1).gameObject.transform; rightWandReference = transform.GetChild(2).gameObject.transform; waistReference = transform.GetChild(3).gameObject.transform; leftFootReference = transform.GetChild(4).gameObject.transform; rightFootReference = transform.GetChild(5).gameObject.transform; }
void InputDataTracker(string address) { posVRPN = VRPN.vrpnTrackerPos(address, 3); x = 1 * posVRPN.x; y = -1 * posVRPN.z; z = -1 * posVRPN.y; Vector3 qVector = new Vector3(x, y, z); bufferTracker.Enqueue(qVector); if (bufferTracker.Count > tamBuffer) { bufferTracker.Dequeue(); } }
// Update is called once per frame void Update() { // Get data from the Polhemus updatePDIposition = VRPN.vrpnTrackerPos(deviceName + "@" + deviceIP, sensor); float xpos = updatePDIposition [0]; float ypos = updatePDIposition [1]; float zpos = -1 * updatePDIposition [2]; // rescale to UNITY Table dimensions updatescalePDIposition = new Vector3(tableScaleX * xpos, tableScaleY * ypos, scale * zpos + 2); frame++; // if (frame > 1){ // tablePositionLast = tablePosition; // set last position // } ////// TESTING positions in Console: ///// //Debug.Log (newPDIposition); //Debug.Log (tablePosition); // transform Pohlemus space to table space: tablePosition = updatescalePDIposition - tableOrigin; // tableXpos = tablePosition[0]; // tableYpos = tablePosition[1]; // tableZpos = tablePosition[2]; // if (frame > 1){ // // // position differentiation (instantaneous velocity) // sensorVelocity = (tablePosition - tablePositionLast)/Time.deltaTime; // // // velX = (tablePosition[0]-tablePositionLast[0])/ Time.deltaTime; // isolated by axis // // velY = (tablePosition[1]-tablePositionLast[1])/ Time.deltaTime; // // velZ = (tablePosition[2]-tablePositionLast[2])/ Time.deltaTime; // } ////////// ROTATION DATA //////////////////////// //updatePDIrotation = VRPN.vrpnTrackerQuat("TrackerJohn@localhost",sensor); }
/// <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); }
void Update() { foreach (VRPNConnection vrpnC in _connectionList.Values) { if (vrpnC._VRPNObject != null) { Vector3 tmpPos = VRPN.vrpnTrackerPos(vrpnC._VRPNObject, 0); Quaternion tmpQuat = VRPN.vrpnTrackerQuat(vrpnC._VRPNObject, 0); Vector3 pos = new Vector3(-tmpPos.x, tmpPos.z, -tmpPos.y); Quaternion quat = new Quaternion(tmpQuat.x, -tmpQuat.z, tmpQuat.y, tmpQuat.w); vrpnC._pos = pos; vrpnC._quat = quat; //NetworkServer.SendToAll (MESSAGE_DATA, new VRPNMessage (pos, quat)); NetworkServer.SendToClient(vrpnC._connectionID, MESSAGE_DATA, new VRPNMessage(pos, quat)); } } }
public void GetFingersData(string nameLeft, string nameRight) { //Left Glove TupleLeft[0] = VRPN.vrpnAnalog(nameLeft, 0); TupleLeft[1] = VRPN.vrpnAnalog(nameLeft, 1); TupleLeft[2] = VRPN.vrpnAnalog(nameLeft, 2); TupleLeft[3] = VRPN.vrpnAnalog(nameLeft, 3); TupleLeft[4] = VRPN.vrpnAnalog(nameLeft, 4); TupleLeft[5] = VRPN.vrpnAnalog(nameLeft, 5); TupleLeft[6] = VRPN.vrpnAnalog(nameLeft, 6); TupleLeft[7] = VRPN.vrpnAnalog(nameLeft, 7); TupleLeft[8] = VRPN.vrpnAnalog(nameLeft, 8); TupleLeft[9] = VRPN.vrpnAnalog(nameLeft, 9); TupleLeft[10] = VRPN.vrpnAnalog(nameLeft, 10); TupleLeft[11] = VRPN.vrpnAnalog(nameLeft, 11); TupleLeft[12] = VRPN.vrpnAnalog(nameLeft, 12); TupleLeft[13] = VRPN.vrpnAnalog(nameLeft, 13); MeansLeft = GetMeansFromFile(FilenamesLeft, 2); //TODO InfoLeft = TestFingers(TupleLeft, MeansLeft); //Right Glove TupleRight[0] = VRPN.vrpnAnalog(nameRight, 0); TupleRight[1] = VRPN.vrpnAnalog(nameRight, 1); TupleRight[2] = VRPN.vrpnAnalog(nameRight, 2); TupleRight[3] = VRPN.vrpnAnalog(nameRight, 3); TupleRight[4] = VRPN.vrpnAnalog(nameRight, 4); TupleRight[5] = VRPN.vrpnAnalog(nameRight, 5); TupleRight[6] = VRPN.vrpnAnalog(nameRight, 6); TupleRight[7] = VRPN.vrpnAnalog(nameRight, 7); TupleRight[8] = VRPN.vrpnAnalog(nameRight, 8); TupleRight[9] = VRPN.vrpnAnalog(nameRight, 9); TupleRight[10] = VRPN.vrpnAnalog(nameRight, 10); TupleRight[11] = VRPN.vrpnAnalog(nameRight, 11); TupleRight[12] = VRPN.vrpnAnalog(nameRight, 12); TupleRight[13] = VRPN.vrpnAnalog(nameRight, 13); Means = GetMeansFromFile(Filenames, 2); //TODO InfoRight = TestFingers(TupleRight, Means); //TODO //Old data if (InfoRight != null && InfoLeft != null) { InfoRightAnt = InfoRight; InfoLeftAnt = InfoLeft; } }
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); }
// Use this for initialization void Start() { animator = GetComponent <Animator>(); controller = CC_CANOE.CanoeCharacterController(); parentTransform = transform.GetComponentInParent <Transform>(); headTransform = CC_CANOE.HeadGameObject().gameObject.transform; leftHandTransform = CC_CANOE.WandGameObject(Wand.Left).gameObject.transform; rightHandTransform = CC_CANOE.WandGameObject(Wand.Right).gameObject.transform; //Initial call to chest puck VRPN.vrpnTrackerQuat("CC_FLAT_PUCK0@" + CC_CONFIG.innovatorIP, 0); //Brings model out of ground offset = new Vector3(0, 2f * transform.GetChild(0).GetComponent <SkinnedMeshRenderer>().bounds.extents.x, 0); transform.localPosition = offset; leftMirrorGoal = transform.parent.GetChild(1).transform; rightMirrorGoal = transform.parent.GetChild(2).transform; }
////////////// THREADING /////////////////// public void PolhemusDataThread() { Task.Run(() => { //int totSampleint = Convert.ToInt32(totSample); // [...] Code to be executed in auxiliary thread for (int i = 0; i < 1000; i++) { int value = i; Vector3 PDIposition = VRPN.vrpnTrackerPos(deviceName + "@" + deviceIP, sensor); float xpos = PDIposition [0]; float ypos = PDIposition [1]; float zpos = -1 * PDIposition [2]; Vector3 scalePDIposition = new Vector3(scale * xpos, scale * ypos, scale * zpos + 2); Vector3 tablePosition = scalePDIposition - tableOrigin; SensorData.Add(tablePosition); // sleep in millisec (1/ (sleep/1000) = sampleRate System.Threading.Thread.Sleep(10); } }); //.ContinueInMainThreadWith(Update); }
public static Vector3 vrpnTrackerPos(string address, int channel) { var vector = VRPN.vrpnTrackerPos(address, channel); return(new Vector3(-vector.x, vector.y, vector.z)); }
void Start() { vrpn = GetComponent<VRPN> (); }