diff --git a/OSVR-Unity/Assets/OSVRUnity/src/VREye.cs b/OSVR-Unity/Assets/OSVRUnity/src/VREye.cs index 711f36b..eb24a33 100644 --- a/OSVR-Unity/Assets/OSVRUnity/src/VREye.cs +++ b/OSVR-Unity/Assets/OSVRUnity/src/VREye.cs @@ -46,6 +46,8 @@ public class VREye : MonoBehaviour [HideInInspector] public Transform cachedTransform; [HideInInspector] + public VRHead head; + [HideInInspector] public K1RadialDistortion DistortionEffect { get @@ -97,6 +99,10 @@ void Init() { clientKit = GameObject.FindObjectOfType(); } + if (head == null) + { + gameObject.GetComponentInParent(); + } //cache: cachedTransform = transform; @@ -130,12 +136,16 @@ private void SetViewportRects() } } - //Called after a camera finishes rendering the scene. + //Called before a camera renders the scene. //the goal here is to update the client often to make sure we have the most recent tracker data //this helps reduce latency - void OnPostRender() + void OnPreRender() { clientKit.context.update(); + if (head) + { + head.UpdatePose(); + } } #endregion diff --git a/OSVR-Unity/Assets/OSVRUnity/src/VRHead.cs b/OSVR-Unity/Assets/OSVRUnity/src/VRHead.cs index c9f6ab0..510c908 100644 --- a/OSVR-Unity/Assets/OSVRUnity/src/VRHead.cs +++ b/OSVR-Unity/Assets/OSVRUnity/src/VRHead.cs @@ -55,6 +55,7 @@ public class VRHead : MonoBehaviour private DeviceDescriptor _deviceDescriptor; private DisplayInterface _displayInterface; private bool _initDisplayInterface = false; + private PoseInterface _poseIf; #endregion #region Init @@ -69,6 +70,7 @@ void Start() } */ _displayInterface = GetComponent(); + _poseIf = GetComponent(); //update VRHead with info from the display interface if it has been initialized //it might not be initialized if it is still parsing a display json file @@ -103,6 +105,12 @@ void Update() UpdateViewMode(); } } + public void UpdatePose() + { + var state = _poseIf.Interface.GetState(); + transform.localPosition = state.Value.Position; + transform.localRotation = state.Value.Rotation; + } #endregion #region Public Methods @@ -165,6 +173,8 @@ void CatalogEyes() switch (currentEye.eye) { case Eye.left: + // Only need one eye to update the head. + currentEye.head = this; _leftEye = currentEye; break;