Merge pull request #9613 from ZappoMan/fixXboxWithDisabledKinect

fix kinect plugin claiming to have hands when not enabled
This commit is contained in:
Brad Hefta-Gaub 2017-02-06 07:57:05 -08:00 committed by GitHub
commit be5698dce1
2 changed files with 49 additions and 12 deletions

View file

@ -227,15 +227,26 @@ void KinectPlugin::init() {
static const QString KINECT_PLUGIN { "Kinect" }; static const QString KINECT_PLUGIN { "Kinect" };
{ {
auto getter = [this]()->bool { return _enabled; }; auto getter = [this]()->bool { return _enabled; };
auto setter = [this](bool value) { _enabled = value; saveSettings(); }; auto setter = [this](bool value) {
_enabled = value; saveSettings();
if (!_enabled) {
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
userInputMapper->withLock([&, this]() {
_inputDevice->clearState();
});
}
};
auto preference = new CheckPreference(KINECT_PLUGIN, "Enabled", getter, setter); auto preference = new CheckPreference(KINECT_PLUGIN, "Enabled", getter, setter);
preferences->addPreference(preference); preferences->addPreference(preference);
} }
} }
bool KinectPlugin::isSupported() const { bool KinectPlugin::isSupported() const {
// FIXME -- check to see if there's a camera or not... bool supported = false;
return true; #ifdef HAVE_KINECT
supported = initializeDefaultSensor();
#endif
return supported;
} }
bool KinectPlugin::activate() { bool KinectPlugin::activate() {
@ -250,13 +261,29 @@ bool KinectPlugin::activate() {
userInputMapper->registerDevice(_inputDevice); userInputMapper->registerDevice(_inputDevice);
return initializeDefaultSensor(); return initializeDefaultSensor();
} else {
return false;
} }
return false;
} }
bool KinectPlugin::initializeDefaultSensor() { bool KinectPlugin::isHandController() const {
bool sensorAvailable = false;
#ifdef HAVE_KINECT #ifdef HAVE_KINECT
if (_kinectSensor) {
BOOLEAN sensorIsAvailable = FALSE;
HRESULT hr = _kinectSensor->get_IsAvailable(&sensorIsAvailable);
sensorAvailable = SUCCEEDED(hr) && (sensorIsAvailable == TRUE);
}
#endif
return _enabled && _initialized && sensorAvailable;
}
bool KinectPlugin::initializeDefaultSensor() const {
#ifdef HAVE_KINECT
if (_initialized) {
return true;
}
HRESULT hr; HRESULT hr;
hr = GetDefaultKinectSensor(&_kinectSensor); hr = GetDefaultKinectSensor(&_kinectSensor);
@ -289,6 +316,7 @@ bool KinectPlugin::initializeDefaultSensor() {
return false; return false;
} }
_initialized = true;
return true; return true;
#else #else
return false; return false;
@ -527,3 +555,9 @@ void KinectPlugin::InputDevice::update(float deltaTime, const controller::InputC
} }
} }
void KinectPlugin::InputDevice::clearState() {
for (size_t i = 0; i < KinectJointIndex::Size; i++) {
int poseIndex = KinectJointIndexToPoseIndex((KinectJointIndex)i);
_poseStateMap[poseIndex] = controller::Pose();
}
}

View file

@ -41,7 +41,7 @@ template<class Interface> inline void SafeRelease(Interface *& pInterfaceToRelea
class KinectPlugin : public InputPlugin { class KinectPlugin : public InputPlugin {
Q_OBJECT Q_OBJECT
public: public:
bool isHandController() const override { return true; } bool isHandController() const override;
// Plugin functions // Plugin functions
virtual void init() override; virtual void init() override;
@ -79,6 +79,8 @@ protected:
void update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData, void update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData,
const std::vector<KinectPlugin::KinectJoint>& joints, const std::vector<KinectPlugin::KinectJoint>& prevJoints); const std::vector<KinectPlugin::KinectJoint>& joints, const std::vector<KinectPlugin::KinectJoint>& prevJoints);
void clearState();
}; };
std::shared_ptr<InputDevice> _inputDevice { std::make_shared<InputDevice>() }; std::shared_ptr<InputDevice> _inputDevice { std::make_shared<InputDevice>() };
@ -86,7 +88,8 @@ protected:
static const char* NAME; static const char* NAME;
static const char* KINECT_ID_STRING; static const char* KINECT_ID_STRING;
bool _enabled; bool _enabled { false };
mutable bool _initialized { false };
// copy of data directly from the KinectDataReader SDK // copy of data directly from the KinectDataReader SDK
std::vector<KinectJoint> _joints; std::vector<KinectJoint> _joints;
@ -97,18 +100,18 @@ protected:
// Kinect SDK related items... // Kinect SDK related items...
bool KinectPlugin::initializeDefaultSensor(); bool KinectPlugin::initializeDefaultSensor() const;
void updateBody(); void updateBody();
#ifdef HAVE_KINECT #ifdef HAVE_KINECT
void ProcessBody(INT64 time, int bodyCount, IBody** bodies); void ProcessBody(INT64 time, int bodyCount, IBody** bodies);
// Current Kinect // Current Kinect
IKinectSensor* _kinectSensor { nullptr }; mutable IKinectSensor* _kinectSensor { nullptr };
ICoordinateMapper* _coordinateMapper { nullptr }; mutable ICoordinateMapper* _coordinateMapper { nullptr };
// Body reader // Body reader
IBodyFrameReader* _bodyFrameReader { nullptr }; mutable IBodyFrameReader* _bodyFrameReader { nullptr };
#endif #endif
}; };