Overte C++ Documentation
NeuronPlugin.h
1 //
2 // NeuronPlugin.h
3 // input-plugins/src/input-plugins
4 //
5 // Created by Anthony Thibault on 12/18/2015.
6 // Copyright 2015 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_NeuronPlugin_h
13 #define hifi_NeuronPlugin_h
14 
15 #include <controllers/InputDevice.h>
16 #include <controllers/StandardControls.h>
17 #include <plugins/InputPlugin.h>
18 
19 struct _BvhDataHeaderEx;
20 void FrameDataReceivedCallback(void* context, void* sender, _BvhDataHeaderEx* header, float* data);
21 
22 // Handles interaction with the Neuron SDK
23 class NeuronPlugin : public InputPlugin {
24  Q_OBJECT
25 public:
26  friend void FrameDataReceivedCallback(void* context, void* sender, _BvhDataHeaderEx* header, float* data);
27 
28  // Plugin functions
29  virtual void init() override;
30  virtual bool isSupported() const override;
31  virtual const QString getName() const override { return NAME; }
32  const QString getID() const override { return NEURON_ID_STRING; }
33  bool isRunning() const override { return _active && _enabled; }
34  virtual bool activate() override;
35  virtual void deactivate() override;
36 
37  virtual void pluginFocusOutEvent() override { _inputDevice->focusOutEvent(); }
38  virtual void pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override;
39 
40  virtual void saveSettings() const override;
41  virtual void loadSettings() override;
42 
43 protected:
44 
45  struct NeuronJoint {
46  glm::vec3 pos;
47  glm::vec3 euler;
48  };
49 
50  class InputDevice : public controller::InputDevice {
51  public:
52  friend class NeuronPlugin;
53 
54  InputDevice() : controller::InputDevice("Neuron") {}
55  virtual ~InputDevice() = default;
56 
57  // Device functions
58  virtual controller::Input::NamedVector getAvailableInputs() const override;
59  virtual QString getDefaultMappingConfig() const override;
60  virtual void update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override {};
61  virtual void focusOutEvent() override {};
62 
63  void update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData, const std::vector<NeuronPlugin::NeuronJoint>& joints, const std::vector<NeuronPlugin::NeuronJoint>& prevJoints);
64  };
65 
66  std::shared_ptr<InputDevice> _inputDevice { std::make_shared<InputDevice>() };
67 
68  static const char* NAME;
69  static const char* NEURON_ID_STRING;
70 
71  QString _serverAddress;
72  int _serverPort;
73  void* _socketRef;
74 
75  // used to guard multi-threaded access to _joints
76  std::mutex _jointsMutex;
77 
78  // copy of data directly from the NeuronDataReader SDK
79  std::vector<NeuronJoint> _joints;
80 
81  // one frame old copy of _joints, used to caluclate angular and linear velocity.
82  std::vector<NeuronJoint> _prevJoints;
83 };
84 
85 #endif // hifi_NeuronPlugin_h
86