Exemplo n.º 1
0
 public override void UpdateState()
 {
     if (m_Handle >= 0)
     {
         if (Time.frameCount != m_PrevFrameCount)
         {
             int t = m_PrevFrameCount;
             m_PrevFrameCount = Time.frameCount;
             if (EnsureAnchor())
             {
                 //
                 UpdateAnchor();
                 m_PrevFrameCount = t;
                 base.UpdateState();
                 //
                 if (m_EnableEmulatedHand)
                 {
                     for (int i = 0, imax = m_EmulatedHands.Length; i < imax; ++i)
                     {
                         if (m_EmulatedHands[i].handedness != ControllerType.None)
                         {
                             m_EmulatedHands[i].OnControllerUpdate();
                             if (m_IsRequestVR)
                             {
                                 m_EmulatedHands[i].showGizmos = (XDevicePlugin.GetNodePosition(m_Handle, 0, i, null) & TrackingResult.PositionTracked) == 0;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        public virtual float GetBetterYaw()
        {
            float yaw = getHmdYaw();

            //
            if (yaw >= 0 &&
                (XDevicePlugin.GetNodePosition(m_Handle, 0, 2, null) & TrackingResult.PositionTracked) != 0)
            {
                return(360.0f - yaw);
            }
            else
            {
                return(GetRawYaw() + m_YawOffset);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// The current position of the requested node.
        /// </summary>
        /// <param name="node">Node index.</param>
        /// <returns>Position of node local to its tracking space.</returns>
        public virtual Vector3 GetLocalPosition(int node)
        {
            UpdateState();
            //
            Vector3 position = new Vector3();

            if ((XDevicePlugin.GetNodePosition(m_Handle, 0, node, ref position) & TrackingResult.PositionTracked) != 0)
            {
                position.Scale(sensitivity);
                if (m_UseAnchorProjection && anchor != null)
                {
                    position = m_AnchorMatrix.MultiplyPoint3x4(position);
                }
                return(position);
            }
            else
            {
                //Log.d("TrackerInput","No result when calling GetPosition("+node+","+history+") at "+Time.time+" ms.");
            }
            return(Vector3.zero);
        }
Exemplo n.º 4
0
 public override void UpdateAnchor()
 {
     if (useAutoRecenter)
     {
         TryAlignHmd();
     }
     // TODO : Align Notice
     if (m_LastAlignHmdTime >= 0.0f)
     {
         if (m_UiAlign != null)
         {
             m_UiAlign.fillAmount = Mathf.Clamp01((Time.time - m_LastAlignHmdTime) / alignNeedTime);
             if (m_UiAlign.fillAmount >= 1.0)
             {
                 m_UiAlignFade.FadeOut();
                 m_LastAlignHmdTime = -1.0f;
             }
         }
     }
     else
     // TODO : LookAt Notice
     if (m_IsRequestVR)
     {
         if ((XDevicePlugin.GetNodePosition(m_Handle, 0, 2, null) & TrackingResult.PositionTracked) == 0)
         {
             //
             Vector3 lookAt = m_UiLookAt.parent.InverseTransformPoint(anchor.position); lookAt.z = 0.0f;
             m_UiLookAt.localRotation = Quaternion.LookRotation(lookAt, Vector3.back);
             //
             if (!m_UiLookAtFade.isFadingIn)
             {
                 m_UiLookAtFade.FadeIn();
             }
         }
         else if (m_UiLookAtFade.alpha > 0.0f && !m_UiLookAtFade.isFadingOut)
         {
             m_UiLookAtFade.FadeOut();
         }
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Returns if the node exists at the current frame.
 /// </summary>
 public virtual bool Exists(int node)
 {
     UpdateState();
     //
     return((XDevicePlugin.GetNodePosition(m_Handle, 0, node, null) & TrackingResult.PositionTracked) != 0);
 }
Exemplo n.º 6
0
        public override Vector3 GetLocalPosition(int node)
        {
            Vector3 position = Vector3.zero;

            if (node == m_Controllers[2].value)
            {
                //
                if (useExperimental)
                {
                    //
                    UpdateState();
                    //
                    XDevicePlugin.GetSmoothPosition(2, ref position);
                    //
                    position.Scale(sensitivity);
                    if (m_UseAnchorProjection && anchor != null)
                    {
                        position = m_AnchorMatrix.MultiplyPoint3x4(position);
                    }
                }
                else
                {
                    position = base.GetLocalPosition(node);
                }
                //
                if (m_CenterEye == null)
                {
                    m_CenterEye = VRContext.GetAnchor(VRNode.CenterEye);
                    m_VRDevice  = VRContext.currentDevice;
                }
                if (m_CenterEye != null && m_VRDevice != null)
                {
                    Quaternion rotation = m_VRDevice.GetRotation();
                    //
                    if (useAutoRecenter)
                    {
                        rotation             = Quaternion.AngleAxis(m_YawOffset, Vector3.up) * rotation;
                        m_VRDevice.yawOffset = m_YawOffset;
                    }
                    else
                    {
                    }
                    //
                    position -= rotation * (m_VRDevice.neckToEye + m_VRDevice.outsideInMarkPose.position);
                }
            }
            else
            {
                //
                if (m_EnableEmulatedHand)
                {
                    if ((XDevicePlugin.GetNodePosition(m_Handle, 0, node, null) & TrackingResult.PositionTracked) == 0)
                    {
                        return(GetEmulatedHandPosition(node));
                    }
                }
                //
                if (useExperimental)
                {
                    //
                    UpdateState();
                    //
                    XDevicePlugin.GetSmoothPosition(node, ref position);
                    //
                    position.Scale(sensitivity);
                    if (m_UseAnchorProjection && anchor != null)
                    {
                        position = m_AnchorMatrix.MultiplyPoint3x4(position);
                    }
                }
                else
                {
                    position = base.GetLocalPosition(node);
                }
                //
            }
            return(position);
        }