From c64d00fb87f039f48c45161682d188a31d0c2889 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Sun, 30 Aug 2015 18:14:13 -0500 Subject: [PATCH 1/2] Make the eye call update in OnPreRender, not OnPostRender. --- OSVR-Unity/Assets/OSVRUnity/src/VREye.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OSVR-Unity/Assets/OSVRUnity/src/VREye.cs b/OSVR-Unity/Assets/OSVRUnity/src/VREye.cs index 711f36b..9e6fbb3 100644 --- a/OSVR-Unity/Assets/OSVRUnity/src/VREye.cs +++ b/OSVR-Unity/Assets/OSVRUnity/src/VREye.cs @@ -130,10 +130,10 @@ 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(); } From 69cc177473444d66b0061e4e7e16ce815290ba9d Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Sun, 30 Aug 2015 18:14:42 -0500 Subject: [PATCH 2/2] Make the eye actually update the head's transform in OnPreRender. --- OSVR-Unity/Assets/OSVRUnity/src/VREye.cs | 10 ++++++++++ OSVR-Unity/Assets/OSVRUnity/src/VRHead.cs | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/OSVR-Unity/Assets/OSVRUnity/src/VREye.cs b/OSVR-Unity/Assets/OSVRUnity/src/VREye.cs index 9e6fbb3..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; @@ -136,6 +142,10 @@ private void SetViewportRects() 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;