OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef DEVICE_GAMEPAD_PUBLIC_CPP_GAMEPAD_H_ |
| 6 #define DEVICE_GAMEPAD_PUBLIC_CPP_GAMEPAD_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 |
| 10 namespace device { |
| 11 |
| 12 #pragma pack(push, 4) |
| 13 |
| 14 class GamepadButton { |
| 15 public: |
| 16 GamepadButton() : pressed(false), touched(false), value(0.) {} |
| 17 GamepadButton(bool pressed, bool touched, double value) |
| 18 : pressed(pressed), touched(touched), value(value) {} |
| 19 bool pressed; |
| 20 bool touched; |
| 21 double value; |
| 22 }; |
| 23 |
| 24 class GamepadVector { |
| 25 public: |
| 26 GamepadVector() : not_null(false) {} |
| 27 |
| 28 bool not_null; |
| 29 float x, y, z; |
| 30 }; |
| 31 |
| 32 class GamepadQuaternion { |
| 33 public: |
| 34 GamepadQuaternion() : not_null(false) {} |
| 35 |
| 36 bool not_null; |
| 37 float x, y, z, w; |
| 38 }; |
| 39 |
| 40 class GamepadPose { |
| 41 public: |
| 42 GamepadPose() : not_null(false) {} |
| 43 |
| 44 bool not_null; |
| 45 |
| 46 bool has_orientation; |
| 47 bool has_position; |
| 48 |
| 49 GamepadQuaternion orientation; |
| 50 GamepadVector position; |
| 51 GamepadVector angular_velocity; |
| 52 GamepadVector linear_velocity; |
| 53 GamepadVector angular_acceleration; |
| 54 GamepadVector linear_acceleration; |
| 55 }; |
| 56 |
| 57 enum class GamepadHand { kNone = 0, kLeft = 1, kRight = 2 }; |
| 58 |
| 59 // UTF-16 character type |
| 60 #if defined(WIN32) |
| 61 using UChar = wchar_t; |
| 62 #else |
| 63 using UChar = unsigned short; |
| 64 #endif |
| 65 |
| 66 // This structure is intentionally POD and fixed size so that it can be shared |
| 67 // memory between hardware polling threads and the rest of the browser. See |
| 68 // also gamepads.h. |
| 69 class Gamepad { |
| 70 public: |
| 71 static constexpr size_t kIdLengthCap = 128; |
| 72 static constexpr size_t kMappingLengthCap = 16; |
| 73 static constexpr size_t kAxesLengthCap = 16; |
| 74 static constexpr size_t kButtonsLengthCap = 32; |
| 75 |
| 76 Gamepad(); |
| 77 Gamepad(const Gamepad& other); |
| 78 |
| 79 // Is there a gamepad connected at this index? |
| 80 bool connected; |
| 81 |
| 82 // Device identifier (based on manufacturer, model, etc.). |
| 83 UChar id[kIdLengthCap]; |
| 84 |
| 85 // Monotonically increasing value referring to when the data were last |
| 86 // updated. |
| 87 unsigned long long timestamp; |
| 88 |
| 89 // Number of valid entries in the axes array. |
| 90 unsigned axes_length; |
| 91 |
| 92 // Normalized values representing axes, in the range [-1..1]. |
| 93 double axes[kAxesLengthCap]; |
| 94 |
| 95 // Number of valid entries in the buttons array. |
| 96 unsigned buttons_length; |
| 97 |
| 98 // Button states |
| 99 GamepadButton buttons[kButtonsLengthCap]; |
| 100 |
| 101 // Mapping type (for example "standard") |
| 102 UChar mapping[kMappingLengthCap]; |
| 103 |
| 104 GamepadPose pose; |
| 105 |
| 106 GamepadHand hand; |
| 107 |
| 108 unsigned display_id; |
| 109 }; |
| 110 |
| 111 #pragma pack(pop) |
| 112 |
| 113 } // namespace device |
| 114 |
| 115 #endif // DEVICE_GAMEPAD_PUBLIC_CPP_GAMEPAD_H_ |
OLD | NEW |