Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Updating from GetLocalRotation to GetNodeStates

Discussion in 'VR' started by christougher, Jun 15, 2019.

  1. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    Hi, I'm trying to update a script of mine that I use with GoogleVR. Not sure how GetNodeStates should work to replace XRNode.GetLocalRotation as I get a message it is now obsolete in Unity 2019... How would I get CenterEye rotation?

    Thx

    Code (CSharp):
    1. m_gyroscopeRotation = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye);
    2.              
    3. //change to this...
    4.  m_gyroscopeRotation = UnityEngine.XR.InputTracking.GetNodeStates //???
     
  2. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    182
    Hello!

    Here is a simple script to get the center eye rotation:
    Code (CSharp):
    1.  
    2.     // This is so you don't create garbage on every frame, reuse the same list
    3.     List<XRNodeState> nodeStatesCache = new List<XRNodeState>();
    4.     bool TryGetCenterEyeNodeStateRotation(out Quaternion rotation)
    5.     {
    6.         InputTracking.GetNodeStates(nodeStatesCache);
    7.         for (int i = 0; i < nodeStatesCache.Count; i++)
    8.         {
    9.             XRNodeState nodeState = nodeStatesCache[i];
    10.             if(nodeState.nodeType == XRNode.CenterEye)
    11.             {
    12.                 if (nodeState.TryGetRotation(out rotation))
    13.                     return true;
    14.             }
    15.         }
    16.         // This is the fail case, where there was no center eye was available.
    17.         rotation = Quaternion.identity;
    18.         return false;
    19.     }
    20.  
    However, if you are using 2019.x, then I would like to make another suggestion. We are fast moving to using the InputDevice API, which is more centered around devices, and should make this easier. So if you are using 2019.x then I would suggest something closer to this:

    Code (CSharp):
    1.  
    2.     bool TryGetCenterEyeFeature(out Quaternion rotation)
    3.     {
    4.         InputDevice device = InputDevices.GetDeviceAtXRNode(XRNode.CenterEye);
    5.         if(device.isValid)
    6.         {
    7.             if (device.TryGetFeatureValue(CommonUsages.centerEyeRotation, out rotation))
    8.                 return true;
    9.         }
    10.         // This is the fail case, where there was no center eye was available.
    11.         rotation = Quaternion.identity;
    12.         return false;
    13.     }
    14.  
     
    nasos_333, Sarudan, EyePD and 3 others like this.
  3. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,291
    Hi

    What is the latest way to get the left - right camera position in onRender for an image effect ?

    I have spent an enormous amount of hours with no luck, tried all suggestions here and much more i found. Maybe
    miss some reference in my setup ?

    Thanks

    Using unity 2019.3.7f1 and MockHMD