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 GamepadHand { | |
dcheng
2017/04/12 23:33:27
Consider making this scoped, since it looks like a
juncai
2017/04/13 23:55:52
Done.
| |
58 kGamepadHandNone = 0, | |
59 kGamepadHandLeft = 1, | |
60 kGamepadHandRight = 2 | |
61 }; | |
62 | |
63 // UTF-16 character type | |
64 #if defined(WIN32) | |
65 typedef wchar_t UChar; | |
dcheng
2017/04/12 23:33:27
Oh... I see.
Nit: prefer using over typedef
juncai
2017/04/13 23:55:52
Done.
| |
66 #else | |
67 typedef unsigned short UChar; | |
68 #endif | |
69 | |
70 // This structure is intentionally POD and fixed size so that it can be shared | |
71 // memory between hardware polling threads and the rest of the browser. See | |
72 // also gamepads.h. | |
73 class Gamepad { | |
74 public: | |
75 static const size_t kIdLengthCap = 128; | |
76 static const size_t kMappingLengthCap = 16; | |
77 static const size_t kAxesLengthCap = 16; | |
78 static const size_t kButtonsLengthCap = 32; | |
79 | |
80 Gamepad(); | |
81 Gamepad(const Gamepad& other); | |
82 | |
83 // Is there a gamepad connected at this index? | |
84 bool connected; | |
85 | |
86 // Device identifier (based on manufacturer, model, etc.). | |
87 UChar id[kIdLengthCap]; | |
88 | |
89 // Monotonically increasing value referring to when the data were last | |
90 // updated. | |
91 unsigned long long timestamp; | |
92 | |
93 // Number of valid entries in the axes array. | |
94 unsigned axes_length; | |
95 | |
96 // Normalized values representing axes, in the range [-1..1]. | |
97 double axes[kAxesLengthCap]; | |
98 | |
99 // Number of valid entries in the buttons array. | |
100 unsigned buttons_length; | |
101 | |
102 // Button states | |
103 GamepadButton buttons[kButtonsLengthCap]; | |
104 | |
105 // Mapping type (for example "standard") | |
106 UChar mapping[kMappingLengthCap]; | |
107 | |
108 GamepadPose pose; | |
109 | |
110 GamepadHand hand; | |
111 | |
112 unsigned display_id; | |
113 }; | |
114 | |
115 #pragma pack(pop) | |
116 | |
117 } // namespace device | |
118 | |
119 #endif // DEVICE_GAMEPAD_PUBLIC_CPP_GAMEPAD_H_ | |
OLD | NEW |