// // KinectPlugin.h // // Created by Brad Hefta-Gaub on 2016/12/7 // Copyright 2016 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #ifndef hifi_KinectPlugin_h #define hifi_KinectPlugin_h #ifdef HAVE_KINECT #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #endif // Windows Header Files #include #include // Kinect Header files #include #include // Safe release for interfaces template inline void SafeRelease(Interface *& pInterfaceToRelease) { if (pInterfaceToRelease != NULL) { pInterfaceToRelease->Release(); pInterfaceToRelease = NULL; } } #endif #include #include #include // Handles interaction with the Kinect SDK class KinectPlugin : public InputPlugin { Q_OBJECT public: bool isHandController() const override; bool isHeadController() const override; // Plugin functions virtual void init() override; virtual bool isSupported() const override; virtual const QString getName() const override { return NAME; } const QString getID() const override { return KINECT_ID_STRING; } virtual bool activate() override; virtual void deactivate() override; virtual void pluginFocusOutEvent() override { _inputDevice->focusOutEvent(); } virtual void pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override; virtual void saveSettings() const override; virtual void loadSettings() override; private: // add variables for moving average ThreadSafeMovingAverage _LeftHandOrientationAverage; ThreadSafeMovingAverage _RightHandOrientationAverage; protected: struct KinectJoint { glm::vec3 position; glm::quat orientation; }; class InputDevice : public controller::InputDevice { public: friend class KinectPlugin; InputDevice() : controller::InputDevice("Kinect") {} // Device functions virtual controller::Input::NamedVector getAvailableInputs() const override; virtual QString getDefaultMappingConfig() const override; virtual void update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override {}; virtual void focusOutEvent() override {}; void update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData, const std::vector& joints, const std::vector& prevJoints); void clearState(); }; std::shared_ptr _inputDevice { std::make_shared() }; static const char* NAME; static const char* KINECT_ID_STRING; bool _enabled { false }; bool _debug { false }; mutable bool _initialized { false }; // copy of data directly from the KinectDataReader SDK std::vector _joints; // one frame old copy of _joints, used to caluclate angular and linear velocity. std::vector _prevJoints; // Kinect SDK related items... bool KinectPlugin::initializeDefaultSensor() const; void updateBody(); #ifdef HAVE_KINECT void ProcessBody(INT64 time, int bodyCount, IBody** bodies); // Current Kinect mutable IKinectSensor* _kinectSensor { nullptr }; mutable ICoordinateMapper* _coordinateMapper { nullptr }; // Body reader mutable IBodyFrameReader* _bodyFrameReader { nullptr }; #endif }; #endif // hifi_KinectPlugin_h