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/. */
7 #ifndef mozilla_dom_gamepad_GamepadPoseState_h_
8 #define mozilla_dom_gamepad_GamepadPoseState_h_
10 namespace mozilla::dom
{
12 enum class GamepadCapabilityFlags
: uint16_t {
15 * Cap_Position is set if the Gamepad is capable of tracking its position.
17 Cap_Position
= 1 << 1,
19 * Cap_Orientation is set if the Gamepad is capable of tracking its
22 Cap_Orientation
= 1 << 2,
24 * Cap_AngularAcceleration is set if the Gamepad is capable of tracking its
25 * angular acceleration.
27 Cap_AngularAcceleration
= 1 << 3,
29 * Cap_LinearAcceleration is set if the Gamepad is capable of tracking its
30 * linear acceleration.
32 Cap_LinearAcceleration
= 1 << 4,
34 * Cap_GripSpacePosition is set if the Gamepad has a grip space position.
36 Cap_GripSpacePosition
= 1 << 5,
38 * Cap_PositionEmulated is set if the VRDisplay is capable of setting a
39 * emulated position (e.g. neck model) even if still doesn't support 6DOF
42 Cap_PositionEmulated
= 1 << 6,
44 * Cap_All used for validity checking during IPC serialization
46 Cap_All
= (1 << 7) - 1
49 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(GamepadCapabilityFlags
)
51 struct GamepadPoseState
{
52 GamepadCapabilityFlags flags
;
55 float angularVelocity
[3];
56 float angularAcceleration
[3];
57 float linearVelocity
[3];
58 float linearAcceleration
[3];
60 bool isOrientationValid
;
63 : flags(GamepadCapabilityFlags::Cap_None
),
64 orientation
{0, 0, 0, 0},
66 angularVelocity
{0, 0, 0},
67 angularAcceleration
{0, 0, 0},
68 linearVelocity
{0, 0, 0},
69 linearAcceleration
{0, 0, 0},
70 isPositionValid(false),
71 isOrientationValid(false) {}
73 bool operator==(const GamepadPoseState
& aPose
) const {
74 return flags
== aPose
.flags
&& orientation
[0] == aPose
.orientation
[0] &&
75 orientation
[1] == aPose
.orientation
[1] &&
76 orientation
[2] == aPose
.orientation
[2] &&
77 orientation
[3] == aPose
.orientation
[3] &&
78 position
[0] == aPose
.position
[0] &&
79 position
[1] == aPose
.position
[1] &&
80 position
[2] == aPose
.position
[2] &&
81 angularVelocity
[0] == aPose
.angularVelocity
[0] &&
82 angularVelocity
[1] == aPose
.angularVelocity
[1] &&
83 angularVelocity
[2] == aPose
.angularVelocity
[2] &&
84 angularAcceleration
[0] == aPose
.angularAcceleration
[0] &&
85 angularAcceleration
[1] == aPose
.angularAcceleration
[1] &&
86 angularAcceleration
[2] == aPose
.angularAcceleration
[2] &&
87 linearVelocity
[0] == aPose
.linearVelocity
[0] &&
88 linearVelocity
[1] == aPose
.linearVelocity
[1] &&
89 linearVelocity
[2] == aPose
.linearVelocity
[2] &&
90 linearAcceleration
[0] == aPose
.linearAcceleration
[0] &&
91 linearAcceleration
[1] == aPose
.linearAcceleration
[1] &&
92 linearAcceleration
[2] == aPose
.linearAcceleration
[2] &&
93 isPositionValid
== aPose
.isPositionValid
&&
94 isOrientationValid
== aPose
.isOrientationValid
;
97 bool operator!=(const GamepadPoseState
& aPose
) const {
98 return !(*this == aPose
);
103 reinterpret_cast<char*>(&isOrientationValid
) +
104 sizeof(isOrientationValid
) - reinterpret_cast<char*>(&flags
));
108 } // namespace mozilla::dom
110 #endif // mozilla_dom_gamepad_GamepadPoseState_h_