X-Git-Url: http://git.tdb.fi/?p=libs%2Fvr.git;a=blobdiff_plain;f=source%2Foculusriftcamera.cpp;h=0eede270de864b92f17bf18031c0d012cf2b1a65;hp=db07bce716b7ba070e0afb118d832c12bce0d318;hb=8d1197440f07062a1020d902619ae8e9a494baa0;hpb=34427ceec58bf5f9c0c98e5a93dfd22d3f6cc2b1 diff --git a/source/oculusriftcamera.cpp b/source/oculusriftcamera.cpp index db07bce..0eede27 100644 --- a/source/oculusriftcamera.cpp +++ b/source/oculusriftcamera.cpp @@ -9,23 +9,34 @@ OculusRiftCamera::OculusRiftCamera(const OculusRiftDevice &d, const GL::Camera & device(d), base_camera(c) { - const OculusRiftDevice::Private &dev_priv = device.get_private(); - unsigned supported = ovrTrackingCap_Orientation|ovrTrackingCap_MagYawCorrection; - ovrHmd_ConfigureTracking(dev_priv.ovr_hmd, supported, 0); + unsigned supported = ovrTrackingCap_Orientation|ovrTrackingCap_MagYawCorrection|ovrTrackingCap_Position; + ovrHmd_ConfigureTracking(device.get_private().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()); + 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.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());