mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-07 10:02:24 +02:00
fix kinect plugin claiming to have hands when not enabled
This commit is contained in:
parent
68de18a3bb
commit
2a20ce6062
2 changed files with 49 additions and 12 deletions
|
@ -227,15 +227,26 @@ void KinectPlugin::init() {
|
|||
static const QString KINECT_PLUGIN { "Kinect" };
|
||||
{
|
||||
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);
|
||||
preferences->addPreference(preference);
|
||||
}
|
||||
}
|
||||
|
||||
bool KinectPlugin::isSupported() const {
|
||||
// FIXME -- check to see if there's a camera or not...
|
||||
return true;
|
||||
bool supported = false;
|
||||
#ifdef HAVE_KINECT
|
||||
supported = initializeDefaultSensor();
|
||||
#endif
|
||||
return supported;
|
||||
}
|
||||
|
||||
bool KinectPlugin::activate() {
|
||||
|
@ -250,13 +261,29 @@ bool KinectPlugin::activate() {
|
|||
userInputMapper->registerDevice(_inputDevice);
|
||||
|
||||
return initializeDefaultSensor();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool KinectPlugin::initializeDefaultSensor() {
|
||||
bool KinectPlugin::isHandController() const {
|
||||
bool sensorAvailable = false;
|
||||
#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;
|
||||
|
||||
hr = GetDefaultKinectSensor(&_kinectSensor);
|
||||
|
@ -289,6 +316,7 @@ bool KinectPlugin::initializeDefaultSensor() {
|
|||
return false;
|
||||
}
|
||||
|
||||
_initialized = true;
|
||||
return true;
|
||||
#else
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ template<class Interface> inline void SafeRelease(Interface *& pInterfaceToRelea
|
|||
class KinectPlugin : public InputPlugin {
|
||||
Q_OBJECT
|
||||
public:
|
||||
bool isHandController() const override { return true; }
|
||||
bool isHandController() const override;
|
||||
|
||||
// Plugin functions
|
||||
virtual void init() override;
|
||||
|
@ -79,6 +79,8 @@ protected:
|
|||
|
||||
void update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData,
|
||||
const std::vector<KinectPlugin::KinectJoint>& joints, const std::vector<KinectPlugin::KinectJoint>& prevJoints);
|
||||
|
||||
void clearState();
|
||||
};
|
||||
|
||||
std::shared_ptr<InputDevice> _inputDevice { std::make_shared<InputDevice>() };
|
||||
|
@ -86,7 +88,8 @@ protected:
|
|||
static const char* NAME;
|
||||
static const char* KINECT_ID_STRING;
|
||||
|
||||
bool _enabled;
|
||||
bool _enabled { false };
|
||||
mutable bool _initialized { false };
|
||||
|
||||
// copy of data directly from the KinectDataReader SDK
|
||||
std::vector<KinectJoint> _joints;
|
||||
|
@ -97,18 +100,18 @@ protected:
|
|||
|
||||
// Kinect SDK related items...
|
||||
|
||||
bool KinectPlugin::initializeDefaultSensor();
|
||||
bool KinectPlugin::initializeDefaultSensor() const;
|
||||
void updateBody();
|
||||
|
||||
#ifdef HAVE_KINECT
|
||||
void ProcessBody(INT64 time, int bodyCount, IBody** bodies);
|
||||
|
||||
// Current Kinect
|
||||
IKinectSensor* _kinectSensor { nullptr };
|
||||
ICoordinateMapper* _coordinateMapper { nullptr };
|
||||
mutable IKinectSensor* _kinectSensor { nullptr };
|
||||
mutable ICoordinateMapper* _coordinateMapper { nullptr };
|
||||
|
||||
// Body reader
|
||||
IBodyFrameReader* _bodyFrameReader { nullptr };
|
||||
mutable IBodyFrameReader* _bodyFrameReader { nullptr };
|
||||
#endif
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue