Example #1
0
        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 if (viveTracker)
                {
                    Quaternion viveQuat;
                    viveQuat.x = rotation.z;
                    viveQuat.y = rotation.x;
                    viveQuat.z = rotation.y;
                    viveQuat.w = rotation.w;
                    transform.localRotation = viveQuat * Quaternion.Euler(trackerRotationOffset);
                }
                else
                {
                    transform.localRotation = rotation * Quaternion.Euler(trackerRotationOffset);
                }

                yield return(null);
            }
        }
Example #2
0
        private IEnumerator Position()
        {
            while (true)
            {
                Vector3 pos = VRPN.vrpnTrackerPos(trackerAddress, channel) + trackerPositionOffset;

                if (convertToLeft)
                {
                    pos.x  = Interlocked.Exchange(ref pos.z, pos.x);
                    pos.y *= -1;
                    transform.localPosition = pos;
                }
                else if (viveTracker)
                {
                    Vector3 vivePos;
                    vivePos.x = pos.z;
                    vivePos.y = pos.x;
                    vivePos.z = pos.y;
                    transform.localPosition = vivePos;
                }
                else
                {
                    transform.localPosition = pos;
                }

                yield return(null);
            }
        }
Example #3
0
        /// <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);
            }
        }
Example #4
0
        /// <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);
            }
        }
Example #5
0
 /// <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);
 }
Example #6
0
        private IEnumerator Position()
        {
            while (true)
            {
                Vector3 pos = VRPN.vrpnTrackerPos(trackerAddress, channel) + trackerPositionOffset;

                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);
            }
        }