From 697c2e06a90574c4526afe2d7d57edca099d2ceb Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 6 Oct 2016 20:08:51 +0300 Subject: [PATCH] Add a getter and signal to indicate if a controller is tracked --- Build | 1 + source/motioncontroller.h | 4 ++++ source/openvr/openvrcontroller.cpp | 2 ++ source/openvr/openvrcontroller.h | 1 + 4 files changed, 8 insertions(+) diff --git a/Build b/Build index fa837ec..43581de 100644 --- a/Build +++ b/Build @@ -3,6 +3,7 @@ package "mspvr" description "OpenGL-based virtual reality library"; version "0.1"; + require "sigc++-2.0"; require "mspcore"; require "mspgl"; require "mspgui"; diff --git a/source/motioncontroller.h b/source/motioncontroller.h index 9cdd622..959e056 100644 --- a/source/motioncontroller.h +++ b/source/motioncontroller.h @@ -11,6 +11,9 @@ class StereoView; class MotionController: public Input::Device { +public: + sigc::signal signal_tracking_state_changed; + protected: StereoView *view; Msp::GL::Matrix matrix; @@ -21,6 +24,7 @@ public: void attach_to_view(StereoView &); void detach_from_view(); + virtual bool is_tracked() const = 0; const GL::Matrix &get_matrix() const { return matrix; } virtual void update() = 0; protected: diff --git a/source/openvr/openvrcontroller.cpp b/source/openvr/openvrcontroller.cpp index 9ab957d..405cd2f 100644 --- a/source/openvr/openvrcontroller.cpp +++ b/source/openvr/openvrcontroller.cpp @@ -58,9 +58,11 @@ void OpenVRController::event(const Event &ev) { case vr::VREvent_TrackedDeviceActivated: index = ev.trackedDeviceIndex; + signal_tracking_state_changed.emit(true); break; case vr::VREvent_TrackedDeviceDeactivated: index = -1; + signal_tracking_state_changed.emit(false); break; case vr::VREvent_ButtonPress: set_button_state(ev.data.controller.button, true, true); diff --git a/source/openvr/openvrcontroller.h b/source/openvr/openvrcontroller.h index 18c5774..00ae1c0 100644 --- a/source/openvr/openvrcontroller.h +++ b/source/openvr/openvrcontroller.h @@ -26,6 +26,7 @@ public: virtual std::string get_axis_name(unsigned) const; int get_index() const { return index; } + virtual bool is_tracked() const { return index>=0; } void event(const Event &); virtual void update(); -- 2.45.2