summaryrefslogtreecommitdiffstats
path: root/dom/gamepad/GamepadPoseState.h
blob: 7f0c49223a8d6fdbc4b9a34b4e651c5e4e04c19a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_dom_gamepad_GamepadPoseState_h_
#define mozilla_dom_gamepad_GamepadPoseState_h_

namespace mozilla {
namespace dom {

enum class GamepadCapabilityFlags : uint16_t {
  Cap_None = 0,
  /**
   * Cap_Position is set if the Gamepad is capable of tracking its position.
   */
  Cap_Position = 1 << 1,
  /**
   * Cap_Orientation is set if the Gamepad is capable of tracking its
   * orientation.
   */
  Cap_Orientation = 1 << 2,
  /**
   * Cap_AngularAcceleration is set if the Gamepad is capable of tracking its
   * angular acceleration.
   */
  Cap_AngularAcceleration = 1 << 3,
  /**
   * Cap_LinearAcceleration is set if the Gamepad is capable of tracking its
   * linear acceleration.
   */
  Cap_LinearAcceleration = 1 << 4,
  /**
   * Cap_GripSpacePosition is set if the Gamepad has a grip space position.
   */
  Cap_GripSpacePosition = 1 << 5,
  /**
   * Cap_PositionEmulated is set if the VRDisplay is capable of setting a
   * emulated position (e.g. neck model) even if still doesn't support 6DOF
   * tracking.
   */
  Cap_PositionEmulated = 1 << 6,
  /**
   * Cap_All used for validity checking during IPC serialization
   */
  Cap_All = (1 << 7) - 1
};

MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(GamepadCapabilityFlags)

struct GamepadPoseState {
  GamepadCapabilityFlags flags;
  float orientation[4];
  float position[3];
  float angularVelocity[3];
  float angularAcceleration[3];
  float linearVelocity[3];
  float linearAcceleration[3];
  bool isPositionValid;
  bool isOrientationValid;

  GamepadPoseState()
      : flags(GamepadCapabilityFlags::Cap_None),
        orientation{0, 0, 0, 0},
        position{0, 0, 0},
        angularVelocity{0, 0, 0},
        angularAcceleration{0, 0, 0},
        linearVelocity{0, 0, 0},
        linearAcceleration{0, 0, 0},
        isPositionValid(false),
        isOrientationValid(false) {}

  bool operator==(const GamepadPoseState& aPose) const {
    return flags == aPose.flags && orientation[0] == aPose.orientation[0] &&
           orientation[1] == aPose.orientation[1] &&
           orientation[2] == aPose.orientation[2] &&
           orientation[3] == aPose.orientation[3] &&
           position[0] == aPose.position[0] &&
           position[1] == aPose.position[1] &&
           position[2] == aPose.position[2] &&
           angularVelocity[0] == aPose.angularVelocity[0] &&
           angularVelocity[1] == aPose.angularVelocity[1] &&
           angularVelocity[2] == aPose.angularVelocity[2] &&
           angularAcceleration[0] == aPose.angularAcceleration[0] &&
           angularAcceleration[1] == aPose.angularAcceleration[1] &&
           angularAcceleration[2] == aPose.angularAcceleration[2] &&
           linearVelocity[0] == aPose.linearVelocity[0] &&
           linearVelocity[1] == aPose.linearVelocity[1] &&
           linearVelocity[2] == aPose.linearVelocity[2] &&
           linearAcceleration[0] == aPose.linearAcceleration[0] &&
           linearAcceleration[1] == aPose.linearAcceleration[1] &&
           linearAcceleration[2] == aPose.linearAcceleration[2] &&
           isPositionValid == aPose.isPositionValid &&
           isOrientationValid == aPose.isOrientationValid;
  }

  bool operator!=(const GamepadPoseState& aPose) const {
    return !(*this == aPose);
  }

  void Clear() {
    memset(&flags, 0,
           reinterpret_cast<char*>(&isOrientationValid) +
               sizeof(isOrientationValid) - reinterpret_cast<char*>(&flags));
  }
};

}  // namespace dom
}  // namespace mozilla

#endif  // mozilla_dom_gamepad_GamepadPoseState_h_