summaryrefslogtreecommitdiffstats
path: root/dom/gamepad/GamepadPoseState.h
blob: dc5903aba6245fc36792c982ff102ea55cccfb2f (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

#ifndef mozilla_dom_gamepad_GamepadPoseState_h_
#define mozilla_dom_gamepad_GamepadPoseState_h_

#include "mozilla/TypedEnumBits.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_All used for validity checking during IPC serialization
   */
  Cap_All = (1 << 5) - 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];

  GamepadPoseState()
  {
    Clear();
  }

  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];
  }

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

  void Clear() {
    memset(this, 0, sizeof(GamepadPoseState));
  }
};

}// namespace dom
}// namespace mozilla

#endif // mozilla_dom_gamepad_GamepadPoseState_h_