X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fovr%2Foculusriftcamera.cpp;fp=source%2Fovr%2Foculusriftcamera.cpp;h=0eede270de864b92f17bf18031c0d012cf2b1a65;hb=12044b218363bdd93f9fc1b3c71167d700144e45;hp=0000000000000000000000000000000000000000;hpb=8d1197440f07062a1020d902619ae8e9a494baa0;p=libs%2Fvr.git diff --git a/source/ovr/oculusriftcamera.cpp b/source/ovr/oculusriftcamera.cpp new file mode 100644 index 0000000..0eede27 --- /dev/null +++ b/source/ovr/oculusriftcamera.cpp @@ -0,0 +1,48 @@ +#include "oculusriftcamera.h" +#include "oculusriftdevice.h" +#include "oculusriftdevice_private.h" + +namespace Msp { +namespace VR { + +OculusRiftCamera::OculusRiftCamera(const OculusRiftDevice &d, const GL::Camera &c): + device(d), + base_camera(c) +{ + 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() +{ + 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()+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()); + set_field_of_view(base_camera.get_field_of_view()); + set_aspect(base_camera.get_aspect()); +} + +} // namespace VR +} // namespace Msp