]> git.tdb.fi Git - libs/vr.git/blobdiff - source/libovr/libovrcamera.cpp
Name LibOVR classes after the API, not the device
[libs/vr.git] / source / libovr / libovrcamera.cpp
diff --git a/source/libovr/libovrcamera.cpp b/source/libovr/libovrcamera.cpp
new file mode 100644 (file)
index 0000000..7446086
--- /dev/null
@@ -0,0 +1,36 @@
+#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