]> git.tdb.fi Git - libs/vr.git/commitdiff
Add positional tracking support on the Oculus Rift DK2
authorMikko Rasa <tdb@tdb.fi>
Mon, 22 Dec 2014 23:56:13 +0000 (01:56 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 22 Dec 2014 23:56:13 +0000 (01:56 +0200)
source/headtrackingcamera.h
source/oculusriftcamera.cpp
source/oculusriftcamera.h

index b12a92952e1ffaec3478b9486a8843dfb0bbcd35..36f0170209b7ad64b639557cbe1a4b783d521059 100644 (file)
@@ -14,6 +14,7 @@ protected:
 public:
        virtual ~HeadTrackingCamera() { }
 
+       virtual void reset_tracking() { }
        virtual void update() = 0;
 };
 
index db07bce716b7ba070e0afb118d832c12bce0d318..33ed07f261dc35180b5a0dc88727f6ea0be6782e 100644 (file)
@@ -10,22 +10,28 @@ OculusRiftCamera::OculusRiftCamera(const OculusRiftDevice &d, const GL::Camera &
        base_camera(c)
 {
        const OculusRiftDevice::Private &dev_priv = device.get_private();
-       unsigned supported = ovrTrackingCap_Orientation|ovrTrackingCap_MagYawCorrection;
+       unsigned supported = ovrTrackingCap_Orientation|ovrTrackingCap_MagYawCorrection|ovrTrackingCap_Position;
        ovrHmd_ConfigureTracking(dev_priv.ovr_hmd, supported, 0);
 }
 
+void OculusRiftCamera::reset_tracking()
+{
+       ovrHmd_RecenterPose(device.get_private().ovr_hmd);
+}
+
 void OculusRiftCamera::update()
 {
        ovrTrackingState state = ovrHmd_GetTrackingState(device.get_private().ovr_hmd, ovr_GetTimeInSeconds());
        OVR::Posef head_pose = state.HeadPose.ThePose;
        OVR::Matrix4f tracking_matrix(head_pose.Rotation);
+       OVR::Vector3f trans = head_pose.Translation;
        const float *m = &tracking_matrix.M[0][0];
 
        const GL::Vector3 &base_look = base_camera.get_look_direction();
        GL::Vector3 base_right = normalize(cross(base_look, base_camera.get_up_direction()));
        GL::Vector3 base_up = normalize(cross(base_right, base_look));
 
-       set_position(base_camera.get_position());
+       set_position(base_camera.get_position()+trans.x*base_right+trans.y*base_up-trans.z*base_look);
        set_up_direction(base_right*m[1]+base_up*m[5]-base_look*m[9]);
        set_look_direction(-base_right*m[2]-base_up*m[6]+base_look*m[10]);
        set_depth_clip(base_camera.get_near_clip(), base_camera.get_far_clip());
index 29856fb9253f8f9720dc38b13b0d444200c3ace7..7abaa811c365fcc0513001d4cb0df073cb2ecb49 100644 (file)
@@ -17,6 +17,7 @@ private:
 public:
        OculusRiftCamera(const OculusRiftDevice &, const GL::Camera &);
 
+       virtual void reset_tracking();
        virtual void update();
 };