Skip to content

Commit 88194d8

Browse files
committed
Simplify PoseInterface through inheriting from InterfaceGameObject.
1 parent 7e35bd8 commit 88194d8

1 file changed

Lines changed: 6 additions & 27 deletions

File tree

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

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,17 @@ namespace Unity
1919
///
2020
/// Attach to a GameObject that you'd like to have updated in this way.
2121
/// </summary>
22-
public class PoseInterface : MonoBehaviour
22+
public class PoseInterface : InterfaceGameObject
2323
{
24-
/// <summary>
25-
/// The interface path you want to connect to.
26-
/// </summary>
27-
public string path;
28-
29-
private OSVR.ClientKit.Interface iface;
30-
private OSVR.ClientKit.PoseCallback cb;
31-
32-
void Start()
33-
{
34-
if (0 == path.Length)
35-
{
36-
Debug.LogError("Missing path for PoseInterface " + gameObject.name);
37-
return;
38-
}
39-
40-
iface = OSVR.Unity.ClientKit.instance.context.getInterface(path);
41-
cb = new OSVR.ClientKit.PoseCallback(callback);
42-
iface.registerCallback(cb, IntPtr.Zero);
43-
}
44-
45-
private void callback(IntPtr userdata, ref OSVR.ClientKit.TimeValue timestamp, ref OSVR.ClientKit.PoseReport report)
24+
new void Start()
4625
{
47-
transform.localPosition = Math.ConvertPosition(report.pose.translation);
48-
transform.localRotation = Math.ConvertOrientation(report.pose.rotation);
26+
osvrInterface.RegisterCallback(callback);
4927
}
5028

51-
void OnDestroy()
29+
private void callback(string source, Vector3 position, Quaternion rotation)
5230
{
53-
iface = null;
31+
transform.localPosition = position;
32+
transform.localRotation = rotation;
5433
}
5534
}
5635
}

0 commit comments

Comments
 (0)