X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fopenvr%2Fopenvrsystem.cpp;h=8c3188c370006edf0e5f38c3da713afe37d0a938;hb=5fe4e511b9eb2f093070270e8f5694bcdf3a4f96;hp=e71ba33b45346935d22eb48fc54b22724f4f4888;hpb=0b9fa4d7eb2acb22f5f4f31bbd508d0216421108;p=libs%2Fvr.git diff --git a/source/openvr/openvrsystem.cpp b/source/openvr/openvrsystem.cpp index e71ba33..8c3188c 100644 --- a/source/openvr/openvrsystem.cpp +++ b/source/openvr/openvrsystem.cpp @@ -23,7 +23,8 @@ namespace VR { unsigned OpenVRSystem::n_instances = 0; -OpenVRSystem::OpenVRSystem() +OpenVRSystem::OpenVRSystem(): + n_tracked_devices(0) { if(!n_instances) { @@ -39,6 +40,12 @@ OpenVRSystem::OpenVRSystem() throw runtime_error("OpenVR compositor initialization failed"); vr::VRCompositor()->SetTrackingSpace(vr::TrackingUniverseSeated); + + for(unsigned i=0; iIsTrackedDeviceConnected(i)) + n_tracked_devices = i+1; + + tracking_matrices.resize(n_tracked_devices); } OpenVRSystem::~OpenVRSystem() @@ -47,6 +54,11 @@ OpenVRSystem::~OpenVRSystem() vr::VR_Shutdown(); } +bool OpenVRSystem::is_maybe_available() +{ + return vr::VR_IsHmdPresent(); +} + void OpenVRSystem::configure_view(StereoView &view) const { vr::IVRSystem *vr_sys = vr::VRSystem(); @@ -74,6 +86,11 @@ void OpenVRSystem::set_absolute_tracking(bool a) vr::VRCompositor()->SetTrackingSpace(a ? vr::TrackingUniverseStanding : vr::TrackingUniverseSeated); } +bool OpenVRSystem::get_absolute_tracking() const +{ + return vr::VRCompositor()->GetTrackingSpace()==vr::TrackingUniverseStanding; +} + OpenVRCamera *OpenVRSystem::create_camera(const GL::Camera &bc) { return new OpenVRCamera(*this, bc); @@ -87,12 +104,25 @@ OpenVRCombiner *OpenVRSystem::create_combiner(GL::View &v) void OpenVRSystem::update_pose_matrices() { vector poses; - poses.resize(vr::k_unTrackedDeviceIndex_Hmd+1); + poses.resize(n_tracked_devices); vr::VRCompositor()->WaitGetPoses(&poses[0], poses.size(), 0, 0); - vr::TrackedDevicePose_t &hmd_pose = poses[vr::k_unTrackedDeviceIndex_Hmd]; - if(hmd_pose.bPoseIsValid) - hmd_matrix = convert_matrix(hmd_pose.mDeviceToAbsoluteTracking); + for(unsigned i=0; i=tracking_matrices.size()) + throw out_of_range("OpenVRSystem::get_tracking_matrix"); + + return tracking_matrices[index]; +} + +const GL::Matrix &OpenVRSystem::get_hmd_matrix() const +{ + return get_tracking_matrix(vr::k_unTrackedDeviceIndex_Hmd); } } // namespace VR