1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_dom_gamepad_GamepadPoseState_h_
8 #define mozilla_dom_gamepad_GamepadPoseState_h_
9 
10 namespace mozilla {
11 namespace dom {
12 
13 enum class GamepadCapabilityFlags : uint16_t {
14   Cap_None = 0,
15   /**
16    * Cap_Position is set if the Gamepad is capable of tracking its position.
17    */
18   Cap_Position = 1 << 1,
19   /**
20    * Cap_Orientation is set if the Gamepad is capable of tracking its
21    * orientation.
22    */
23   Cap_Orientation = 1 << 2,
24   /**
25    * Cap_AngularAcceleration is set if the Gamepad is capable of tracking its
26    * angular acceleration.
27    */
28   Cap_AngularAcceleration = 1 << 3,
29   /**
30    * Cap_LinearAcceleration is set if the Gamepad is capable of tracking its
31    * linear acceleration.
32    */
33   Cap_LinearAcceleration = 1 << 4,
34   /**
35    * Cap_GripSpacePosition is set if the Gamepad has a grip space position.
36    */
37   Cap_GripSpacePosition = 1 << 5,
38   /**
39    * Cap_PositionEmulated is set if the VRDisplay is capable of setting a
40    * emulated position (e.g. neck model) even if still doesn't support 6DOF
41    * tracking.
42    */
43   Cap_PositionEmulated = 1 << 6,
44   /**
45    * Cap_All used for validity checking during IPC serialization
46    */
47   Cap_All = (1 << 7) - 1
48 };
49 
50 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(GamepadCapabilityFlags)
51 
52 struct GamepadPoseState {
53   GamepadCapabilityFlags flags;
54   float orientation[4];
55   float position[3];
56   float angularVelocity[3];
57   float angularAcceleration[3];
58   float linearVelocity[3];
59   float linearAcceleration[3];
60   bool isPositionValid;
61   bool isOrientationValid;
62 
GamepadPoseStateGamepadPoseState63   GamepadPoseState()
64       : flags(GamepadCapabilityFlags::Cap_None),
65         orientation{0, 0, 0, 0},
66         position{0, 0, 0},
67         angularVelocity{0, 0, 0},
68         angularAcceleration{0, 0, 0},
69         linearVelocity{0, 0, 0},
70         linearAcceleration{0, 0, 0},
71         isPositionValid(false),
72         isOrientationValid(false) {}
73 
74   bool operator==(const GamepadPoseState& aPose) const {
75     return flags == aPose.flags && orientation[0] == aPose.orientation[0] &&
76            orientation[1] == aPose.orientation[1] &&
77            orientation[2] == aPose.orientation[2] &&
78            orientation[3] == aPose.orientation[3] &&
79            position[0] == aPose.position[0] &&
80            position[1] == aPose.position[1] &&
81            position[2] == aPose.position[2] &&
82            angularVelocity[0] == aPose.angularVelocity[0] &&
83            angularVelocity[1] == aPose.angularVelocity[1] &&
84            angularVelocity[2] == aPose.angularVelocity[2] &&
85            angularAcceleration[0] == aPose.angularAcceleration[0] &&
86            angularAcceleration[1] == aPose.angularAcceleration[1] &&
87            angularAcceleration[2] == aPose.angularAcceleration[2] &&
88            linearVelocity[0] == aPose.linearVelocity[0] &&
89            linearVelocity[1] == aPose.linearVelocity[1] &&
90            linearVelocity[2] == aPose.linearVelocity[2] &&
91            linearAcceleration[0] == aPose.linearAcceleration[0] &&
92            linearAcceleration[1] == aPose.linearAcceleration[1] &&
93            linearAcceleration[2] == aPose.linearAcceleration[2] &&
94            isPositionValid == aPose.isPositionValid &&
95            isOrientationValid == aPose.isOrientationValid;
96   }
97 
98   bool operator!=(const GamepadPoseState& aPose) const {
99     return !(*this == aPose);
100   }
101 
ClearGamepadPoseState102   void Clear() {
103     memset(&flags, 0,
104            reinterpret_cast<char*>(&isOrientationValid) +
105                sizeof(isOrientationValid) - reinterpret_cast<char*>(&flags));
106   }
107 };
108 
109 }  // namespace dom
110 }  // namespace mozilla
111 
112 #endif  // mozilla_dom_gamepad_GamepadPoseState_h_
113