+#include "libovrcamera.h"
+#include "libovrsystem.h"
+#include "libovrsystem_private.h"
+
+namespace Msp {
+namespace VR {
+
+LibOVRCamera::LibOVRCamera(const LibOVRSystem &d, const GL::Camera &c):
+ HeadTrackingCamera(c),
+ device(d)
+{
+ unsigned supported = ovrTrackingCap_Orientation|ovrTrackingCap_MagYawCorrection|ovrTrackingCap_Position;
+ ovrHmd_ConfigureTracking(device.get_private().ovr_hmd, supported, 0);
+}
+
+void LibOVRCamera::reset_tracking()
+{
+ ovrHmd_RecenterPose(device.get_private().ovr_hmd);
+}
+
+void LibOVRCamera::update()
+{
+ double time;
+ if(device.is_timing_active())
+ time = device.get_tracking_time();
+ else
+ time = device.get_current_time();
+
+ ovrTrackingState state = ovrHmd_GetTrackingState(device.get_private().ovr_hmd, time);
+ OVR::Posef head_pose = state.HeadPose.ThePose;
+ OVR::Matrix4f tracking_matrix(head_pose);
+ update_from_matrix(transpose(GL::Matrix(&tracking_matrix.M[0][0])));
+}
+
+} // namespace VR
+} // namespace Msp