Skip to content

Commit e98758a

Browse files
committed
Merge pull request #73 from OSVR/adjust-head-update
Adjust head update
2 parents f25043b + 69cc177 commit e98758a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

OSVR-Unity/Assets/OSVRUnity/src/VREye.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public class VREye : MonoBehaviour
4646
[HideInInspector]
4747
public Transform cachedTransform;
4848
[HideInInspector]
49+
public VRHead head;
50+
[HideInInspector]
4951
public K1RadialDistortion DistortionEffect
5052
{
5153
get
@@ -97,6 +99,10 @@ void Init()
9799
{
98100
clientKit = GameObject.FindObjectOfType<ClientKit>();
99101
}
102+
if (head == null)
103+
{
104+
gameObject.GetComponentInParent<VRHead>();
105+
}
100106
//cache:
101107
cachedTransform = transform;
102108

@@ -130,12 +136,16 @@ private void SetViewportRects()
130136
}
131137
}
132138

133-
//Called after a camera finishes rendering the scene.
139+
//Called before a camera renders the scene.
134140
//the goal here is to update the client often to make sure we have the most recent tracker data
135141
//this helps reduce latency
136-
void OnPostRender()
142+
void OnPreRender()
137143
{
138144
clientKit.context.update();
145+
if (head)
146+
{
147+
head.UpdatePose();
148+
}
139149
}
140150
#endregion
141151

OSVR-Unity/Assets/OSVRUnity/src/VRHead.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class VRHead : MonoBehaviour
5555
private DeviceDescriptor _deviceDescriptor;
5656
private DisplayInterface _displayInterface;
5757
private bool _initDisplayInterface = false;
58+
private PoseInterface _poseIf;
5859
#endregion
5960

6061
#region Init
@@ -69,6 +70,7 @@ void Start()
6970
}
7071
*/
7172
_displayInterface = GetComponent<DisplayInterface>();
73+
_poseIf = GetComponent<PoseInterface>();
7274

7375
//update VRHead with info from the display interface if it has been initialized
7476
//it might not be initialized if it is still parsing a display json file
@@ -103,6 +105,12 @@ void Update()
103105
UpdateViewMode();
104106
}
105107
}
108+
public void UpdatePose()
109+
{
110+
var state = _poseIf.Interface.GetState();
111+
transform.localPosition = state.Value.Position;
112+
transform.localRotation = state.Value.Rotation;
113+
}
106114
#endregion
107115

108116
#region Public Methods
@@ -165,6 +173,8 @@ void CatalogEyes()
165173
switch (currentEye.eye)
166174
{
167175
case Eye.left:
176+
// Only need one eye to update the head.
177+
currentEye.head = this;
168178
_leftEye = currentEye;
169179
break;
170180

0 commit comments

Comments
 (0)