// 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); } }
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 IEnumerator Position() { while (true) { transform.localPosition = VRPN.vrpnTrackerPos(trackerAddress, channel); yield return(null); } }
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); }
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> /// 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); }
// 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; }
////////////// 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")); }
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); }
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)); } } }
////////////// 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)); }
/// <summary> /// Obtain tracker information. /// </summary> private void getTrackerInformation() { if (CC_CONFIG.IsDestiny()) { Vector3 position = new Vector3(0, 0, 0); Quaternion rotation = Quaternion.identity; if (canoe.isVive()) { //Update head ClusterInput entry position = ClusterInput.GetTrackerPosition("head"); rotation = ClusterInput.GetTrackerRotation("head"); //Angle puck so flat section is bottom //Change "Camera Forward Tilt" in editor to change tilt if hat/helmet is angled rotation *= Quaternion.AngleAxis(90 - canoe.cameraForwardTilt, Vector3.left); rotation *= Quaternion.AngleAxis(180, Vector3.up); convertHeadTracking(position, rotation); //Update left controller ClusterInput entries position = ClusterInput.GetTrackerPosition("leftWand"); rotation = ClusterInput.GetTrackerRotation("leftWand"); convertWandTracking(Wand.Left, position, rotation); //Update right controller ClusterInput entries position = ClusterInput.GetTrackerPosition("rightWand"); rotation = ClusterInput.GetTrackerRotation("rightWand"); convertWandTracking(Wand.Right, position, rotation); //Moving the Character Controller with the head movement float same = CC_CANOE.CanoeCharacterController().center.y; CC_CANOE.CanoeCharacterController().center = new Vector3(headPosition.x, same, headPosition.z); } else if (canoe.isOptiTrack()) { //Head position and rotation position = ClusterInput.GetTrackerPosition("head"); //position = new Vector3(position.x, position.y, -position.z); rotation = ClusterInput.GetTrackerRotation("head"); convertHeadTracking(position, rotation); //Left wand position and rotation position = ClusterInput.GetTrackerPosition("leftWand"); rotation = ClusterInput.GetTrackerRotation("leftWand"); convertWandTracking(Wand.Left, position, rotation); //Right wand position and rotation position = ClusterInput.GetTrackerPosition("rightWand"); rotation = ClusterInput.GetTrackerRotation("rightWand"); convertWandTracking(Wand.Right, position, rotation); //Moving the Character Controller with the head movement float same = CC_CANOE.CanoeCharacterController().center.y; CC_CANOE.CanoeCharacterController().center = new Vector3(headPosition.x, same, headPosition.z); } } else { if (CC_CONFIG.IsInnovator()) { //if (checkInnovatorTracking()) { headPosition = convertToLeftHandPosition(VRPN.vrpnTrackerPos("CC_FLAT_HEAD@" + CC_CONFIG.innovatorIP, 0)); headRotation = convertToLeftHandRotation(VRPN.vrpnTrackerQuat("CC_FLAT_HEAD@" + CC_CONFIG.innovatorIP, 0) * Quaternion.AngleAxis(90 - canoe.cameraForwardTilt, Vector3.left) * Quaternion.AngleAxis(180, Vector3.up)); //Moving the Character Controller with the head movement float same = CC_CANOE.CanoeCharacterController().center.y; CC_CANOE.CanoeCharacterController().center = new Vector3(headPosition.x, same, headPosition.z); //Wands rotation and position. wandPosition[0] = convertToLeftHandPosition(VRPN.vrpnTrackerPos("CC_FLAT_WAND0@" + CC_CONFIG.innovatorIP, 0)); wandPosition[1] = convertToLeftHandPosition(VRPN.vrpnTrackerPos("CC_FLAT_WAND1@" + CC_CONFIG.innovatorIP, 0)); wandRotation[0] = convertToLeftHandRotation(VRPN.vrpnTrackerQuat("CC_FLAT_WAND0@" + CC_CONFIG.innovatorIP, 0)); wandRotation[1] = convertToLeftHandRotation(VRPN.vrpnTrackerQuat("CC_FLAT_WAND1@" + CC_CONFIG.innovatorIP, 0)); } else { setDefaultPositions(); } } }
public static Vector3 vrpnTrackerPos(string address, int channel) { Vector3 pos = VRPN.vrpnTrackerPos(address, channel); return(new Vector3(pos.x, pos.z, pos.y)); }
// Update is called once per frame void Update() { // get the time (add to list) //Clockupdate.Add(DateTime.UtcNow.ToString("hh:mm:ss.ffffff")); // check for children // if the required number of targets have been hit *see TableEvents.cs trigger: // if (TableEvents.triggerCounter.triggerCount > TableEvents.goalHitCounter.goalHit){ // // saveAll(); // save Polhemus data // //SceneManager.LoadScene("4.TableActive"); // } // if trials are timed: // countdown -= Time.deltaTime; // if (countdown < 0){ // saveAll(); // SceneManager.LoadScene("1.splashScreen"); // // } // Get data from the Polhemus updatePDIposition = VRPN.vrpnTrackerPos(deviceName + "@" + deviceIP, sensor); float xpos = updatePDIposition [0]; float ypos = updatePDIposition [1]; // tweeks to center avatar on marker float zpos = -1 * updatePDIposition [2]; // rescale to UNITY Table dimensions updatescalePDIposition = new Vector3(xpos / tableScaleX, ypos / tableScaleY, zpos); // frames necessary if using velocity measure to move: // 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; tablePosition.z = playerSide; // tableXpos = tablePosition[0]; // tableYpos = tablePosition[1]; // tableZpos = tablePosition[2]; // tableSensor object transform.position = Vector3.Lerp(tablePosition, tablePositionLast, Time.deltaTime); tablePositions.Add(tablePosition.ToString("F3")); // 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); }