added Plugin interface to ViveControllerManager

mostly I just added this to add the isSupported method, so it wouldn't
attempt to initialize if there was no HMD attached.
This commit is contained in:
Anthony J. Thibault 2015-07-08 16:31:52 -07:00
parent dcaa294778
commit 0f30da64bc
4 changed files with 68 additions and 6 deletions

View file

@ -669,8 +669,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
ddeTracker->init();
connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled);
#endif
ViveControllerManager::getInstance().activate();
ViveControllerManager::getInstance().init();
if (ViveControllerManager::getInstance().isSupported()) {
ViveControllerManager::getInstance().activate();
}
_oldHandMouseX[0] = -1;
_oldHandMouseY[0] = -1;

View file

@ -481,6 +481,7 @@ void SixenseManager::handleButtonEvent(unsigned int buttons, int index) {
}
void SixenseManager::handlePoseEvent(glm::vec3 position, glm::quat rotation, int index) {
#if HAS_SIXENSE
// Transform the measured position into body frame.
glm::vec3 neck = _neckBase;
// Zeroing y component of the "neck" effectively raises the measured position a little bit.
@ -538,6 +539,7 @@ void SixenseManager::handlePoseEvent(glm::vec3 position, glm::quat rotation, int
// palm->setTipPosition(newTipPosition);
_poseStateMap[makeInput(JointChannel(index)).getChannel()] = UserInputMapper::PoseValue(position, rotation);
#endif
}
void SixenseManager::registerToUserInputMapper(UserInputMapper& mapper) {

View file

@ -21,6 +21,8 @@
Q_DECLARE_LOGGING_CATEGORY(inputplugins)
Q_LOGGING_CATEGORY(inputplugins, "hifi.inputplugins")
const QString ViveControllerManager::NAME("OpenVR (Vive) Hand Controllers");
extern vr::IVRSystem *_hmd;
extern vr::TrackedDevicePose_t _trackedDevicePose[vr::k_unMaxTrackedDeviceCount];
extern mat4 _trackedDevicePoseMat4[vr::k_unMaxTrackedDeviceCount];
@ -55,6 +57,40 @@ ViveControllerManager::~ViveControllerManager() {
}
const QString& ViveControllerManager::getName() const {
return NAME;
}
bool ViveControllerManager::isSupported() const {
return vr::VR_IsHmdPresent();
}
void ViveControllerManager::init() {
;
}
void ViveControllerManager::deinit() {
;
}
void ViveControllerManager::activate(PluginContainer * container) {
activate();
}
/// Called when a plugin is no longer being used. May be called multiple times.
void ViveControllerManager::deactivate() {
;
}
/**
* Called by the application during it's idle phase. If the plugin needs to do
* CPU intensive work, it should launch a thread for that, rather than trying to
* do long operations in the idle call
*/
void ViveControllerManager::idle() {
update();
}
void ViveControllerManager::activate() {
if (!_hmd) {
vr::HmdError eError = vr::HmdError_None;

View file

@ -18,11 +18,30 @@
#include <GLMHelpers.h>
#include "UserInputMapper.h"
#include "plugins/Plugin.h"
class ViveControllerManager : public QObject {
Q_OBJECT
class ViveControllerManager : public Plugin {
public:
virtual const QString& getName() const override;
virtual bool isSupported() const override;
/// Called when plugin is initially loaded, typically at application start
virtual void init() override;
/// Called when application is shutting down
virtual void deinit() override ;
/// Called when a plugin is being activated for use. May be called multiple times.
virtual void activate(PluginContainer * container) override;
/// Called when a plugin is no longer being used. May be called multiple times.
virtual void deactivate() override;
/**
* Called by the application during it's idle phase. If the plugin needs to do
* CPU intensive work, it should launch a thread for that, rather than trying to
* do long operations in the idle call
*/
virtual void idle() override;
enum JoystickAxisChannel {
AXIS_Y_POS = 1U << 1,
AXIS_Y_NEG = 1U << 2,
@ -78,7 +97,9 @@ private:
bool _isInitialized;
bool _isEnabled;
int _trackedControllers;
static const QString NAME;
protected:
int _deviceID = 0;