GamepadPoseState.h (3926B)
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 #include <cstdint> 11 #include <cstring> 12 13 #include "mozilla/TypedEnumBits.h" 14 15 namespace mozilla::dom { 16 17 enum class GamepadCapabilityFlags : uint16_t { 18 Cap_None = 0, 19 /** 20 * Cap_Position is set if the Gamepad is capable of tracking its position. 21 */ 22 Cap_Position = 1 << 1, 23 /** 24 * Cap_Orientation is set if the Gamepad is capable of tracking its 25 * orientation. 26 */ 27 Cap_Orientation = 1 << 2, 28 /** 29 * Cap_AngularAcceleration is set if the Gamepad is capable of tracking its 30 * angular acceleration. 31 */ 32 Cap_AngularAcceleration = 1 << 3, 33 /** 34 * Cap_LinearAcceleration is set if the Gamepad is capable of tracking its 35 * linear acceleration. 36 */ 37 Cap_LinearAcceleration = 1 << 4, 38 /** 39 * Cap_GripSpacePosition is set if the Gamepad has a grip space position. 40 */ 41 Cap_GripSpacePosition = 1 << 5, 42 /** 43 * Cap_PositionEmulated is set if the VRDisplay is capable of setting a 44 * emulated position (e.g. neck model) even if still doesn't support 6DOF 45 * tracking. 46 */ 47 Cap_PositionEmulated = 1 << 6, 48 /** 49 * Cap_All used for validity checking during IPC serialization 50 */ 51 Cap_All = (1 << 7) - 1 52 }; 53 54 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(GamepadCapabilityFlags) 55 56 struct GamepadPoseState { 57 GamepadCapabilityFlags flags; 58 float orientation[4]; 59 float position[3]; 60 float angularVelocity[3]; 61 float angularAcceleration[3]; 62 float linearVelocity[3]; 63 float linearAcceleration[3]; 64 bool isPositionValid; 65 bool isOrientationValid; 66 67 GamepadPoseState() 68 : flags(GamepadCapabilityFlags::Cap_None), 69 orientation{0, 0, 0, 0}, 70 position{0, 0, 0}, 71 angularVelocity{0, 0, 0}, 72 angularAcceleration{0, 0, 0}, 73 linearVelocity{0, 0, 0}, 74 linearAcceleration{0, 0, 0}, 75 isPositionValid(false), 76 isOrientationValid(false) {} 77 78 bool operator==(const GamepadPoseState& aPose) const { 79 return flags == aPose.flags && orientation[0] == aPose.orientation[0] && 80 orientation[1] == aPose.orientation[1] && 81 orientation[2] == aPose.orientation[2] && 82 orientation[3] == aPose.orientation[3] && 83 position[0] == aPose.position[0] && 84 position[1] == aPose.position[1] && 85 position[2] == aPose.position[2] && 86 angularVelocity[0] == aPose.angularVelocity[0] && 87 angularVelocity[1] == aPose.angularVelocity[1] && 88 angularVelocity[2] == aPose.angularVelocity[2] && 89 angularAcceleration[0] == aPose.angularAcceleration[0] && 90 angularAcceleration[1] == aPose.angularAcceleration[1] && 91 angularAcceleration[2] == aPose.angularAcceleration[2] && 92 linearVelocity[0] == aPose.linearVelocity[0] && 93 linearVelocity[1] == aPose.linearVelocity[1] && 94 linearVelocity[2] == aPose.linearVelocity[2] && 95 linearAcceleration[0] == aPose.linearAcceleration[0] && 96 linearAcceleration[1] == aPose.linearAcceleration[1] && 97 linearAcceleration[2] == aPose.linearAcceleration[2] && 98 isPositionValid == aPose.isPositionValid && 99 isOrientationValid == aPose.isOrientationValid; 100 } 101 102 bool operator!=(const GamepadPoseState& aPose) const { 103 return !(*this == aPose); 104 } 105 106 void Clear() { 107 memset(&flags, 0, 108 reinterpret_cast<char*>(&isOrientationValid) + 109 sizeof(isOrientationValid) - reinterpret_cast<char*>(&flags)); 110 } 111 }; 112 113 } // namespace mozilla::dom 114 115 #endif // mozilla_dom_gamepad_GamepadPoseState_h_