Overte C++ Documentation
Input.h
1 //
2 // Created by Bradley Austin Davis on 2015/10/18
3 // (based on UserInputMapper inner class created by Sam Gateau on 4/27/15)
4 // Copyright 2015 High Fidelity, Inc.
5 //
6 // Distributed under the Apache License, Version 2.0.
7 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
8 //
9 
10 #pragma once
11 #ifndef hifi_controllers_Input_h
12 #define hifi_controllers_Input_h
13 
14 #include <GLMHelpers.h>
15 
16 namespace controller {
17 
18 enum class HmdAvatarAlignmentType {
19  Eyes = 0, // align the user's eyes with the avatars eyes
20  Head // align the user's head with the avatars head
21 };
22 
23 struct InputCalibrationData {
24  glm::mat4 sensorToWorldMat; // sensor to world
25  glm::mat4 avatarMat; // avatar to world
26  glm::mat4 hmdSensorMat; // hmd pos and orientation in sensor space
27  glm::mat4 defaultCenterEyeMat; // default pose for the center of the eyes in sensor space.
28  glm::mat4 defaultHeadMat; // default pose for head joint in sensor space
29  glm::mat4 defaultSpine2; // default pose for spine2 joint in sensor space
30  glm::mat4 defaultHips; // default pose for hips joint in sensor space
31  glm::mat4 defaultLeftFoot; // default pose for leftFoot joint in sensor space
32  glm::mat4 defaultRightFoot; // default pose for rightFoot joint in sensor space
33  glm::mat4 defaultRightArm; // default pose for rightArm joint in sensor space
34  glm::mat4 defaultLeftArm; // default pose for leftArm joint in sensor space
35  glm::mat4 defaultRightHand; // default pose for rightHand joint in sensor space
36  glm::mat4 defaultLeftHand; // default pose for leftHand joint in sensor space
37  HmdAvatarAlignmentType hmdAvatarAlignmentType;
38 };
39 
40 enum class ChannelType {
41  UNKNOWN = 0,
42  BUTTON,
43  AXIS,
44  POSE,
45  RUMBLE,
46  INVALID = 0x7
47 };
48 
49 // Input is the unique identifier to find a n input channel of a particular device
50 // Devices are responsible for registering to the UseInputMapper so their input channels can be sued and mapped
51 // to the Action channels
52 struct Input {
53  union {
54  uint32_t id{ 0 }; // by default Input is 0 meaning invalid
55  struct {
56  uint16_t device; // Up to 64K possible devices
57  uint16_t channel : 12 ; // 2^12 possible channel per Device
58  uint16_t type : 3; // 2 bits to store the Type directly in the ID
59  uint16_t padding : 1; // 2 bits to store the Type directly in the ID
60  };
61  };
62 
63  bool isValid() const { return (id != INVALID_INPUT.id); }
64 
65  uint16_t getDevice() const { return device; }
66  uint16_t getChannel() const { return channel; }
67  uint32_t getID() const { return id; }
68  ChannelType getType() const { return (ChannelType) type; }
69 
70  bool isButton() const { return getType() == ChannelType::BUTTON; }
71  bool isAxis() const { return getType() == ChannelType::AXIS; }
72  bool isPose() const { return getType() == ChannelType::POSE; }
73 
74  // WORKAROUND: the explicit initializer here avoids a bug in GCC-4.8.2 (but not found in 4.9.2)
75  // where the default initializer (a C++-11ism) for the union data above is not applied.
76  explicit Input() {}
77  explicit Input(uint32_t id) : id(id) {}
78  explicit Input(uint16_t device, uint16_t channel, ChannelType type) : device(device), channel(channel), type(uint16_t(type)), padding(0) {}
79  Input(const Input& src) : id(src.id) {}
80  Input& operator = (const Input& src) { id = src.id; return (*this); }
81  bool operator ==(const Input& right) const { return INVALID_INPUT.id != id && INVALID_INPUT.id != right.id && id == right.id; }
82  bool operator !=(const Input& right) const { return !(*this == right); }
83  bool operator < (const Input& src) const { return id < src.id; }
84 
85  static const Input INVALID_INPUT;
86  static const uint16_t INVALID_DEVICE;
87  static const uint16_t INVALID_CHANNEL;
88  static const uint16_t INVALID_TYPE;
89 
90  using NamedPair = QPair<Input, QString>;
91  using NamedVector = QVector<NamedPair>;
92 
93  static const Input& invalidInput();
94 };
95 
96 }
97 
98 #endif