xr_body_tracker.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /**************************************************************************/
  2. /* xr_body_tracker.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef XR_BODY_TRACKER_H
  31. #define XR_BODY_TRACKER_H
  32. #include "servers/xr/xr_positional_tracker.h"
  33. class XRBodyTracker : public XRPositionalTracker {
  34. GDCLASS(XRBodyTracker, XRPositionalTracker);
  35. _THREAD_SAFE_CLASS_
  36. public:
  37. enum BodyFlags {
  38. BODY_FLAG_UPPER_BODY_SUPPORTED = 1,
  39. BODY_FLAG_LOWER_BODY_SUPPORTED = 2,
  40. BODY_FLAG_HANDS_SUPPORTED = 4,
  41. };
  42. enum Joint {
  43. JOINT_ROOT,
  44. // Upper Body Joints
  45. JOINT_HIPS,
  46. JOINT_SPINE,
  47. JOINT_CHEST,
  48. JOINT_UPPER_CHEST,
  49. JOINT_NECK,
  50. JOINT_HEAD,
  51. JOINT_HEAD_TIP,
  52. JOINT_LEFT_SHOULDER,
  53. JOINT_LEFT_UPPER_ARM,
  54. JOINT_LEFT_LOWER_ARM,
  55. JOINT_RIGHT_SHOULDER,
  56. JOINT_RIGHT_UPPER_ARM,
  57. JOINT_RIGHT_LOWER_ARM,
  58. // Lower Body Joints
  59. JOINT_LEFT_UPPER_LEG,
  60. JOINT_LEFT_LOWER_LEG,
  61. JOINT_LEFT_FOOT,
  62. JOINT_LEFT_TOES,
  63. JOINT_RIGHT_UPPER_LEG,
  64. JOINT_RIGHT_LOWER_LEG,
  65. JOINT_RIGHT_FOOT,
  66. JOINT_RIGHT_TOES,
  67. // Left Hand Joints
  68. JOINT_LEFT_HAND,
  69. JOINT_LEFT_PALM,
  70. JOINT_LEFT_WRIST,
  71. JOINT_LEFT_THUMB_METACARPAL,
  72. JOINT_LEFT_THUMB_PHALANX_PROXIMAL,
  73. JOINT_LEFT_THUMB_PHALANX_DISTAL,
  74. JOINT_LEFT_THUMB_TIP,
  75. JOINT_LEFT_INDEX_FINGER_METACARPAL,
  76. JOINT_LEFT_INDEX_FINGER_PHALANX_PROXIMAL,
  77. JOINT_LEFT_INDEX_FINGER_PHALANX_INTERMEDIATE,
  78. JOINT_LEFT_INDEX_FINGER_PHALANX_DISTAL,
  79. JOINT_LEFT_INDEX_FINGER_TIP,
  80. JOINT_LEFT_MIDDLE_FINGER_METACARPAL,
  81. JOINT_LEFT_MIDDLE_FINGER_PHALANX_PROXIMAL,
  82. JOINT_LEFT_MIDDLE_FINGER_PHALANX_INTERMEDIATE,
  83. JOINT_LEFT_MIDDLE_FINGER_PHALANX_DISTAL,
  84. JOINT_LEFT_MIDDLE_FINGER_TIP,
  85. JOINT_LEFT_RING_FINGER_METACARPAL,
  86. JOINT_LEFT_RING_FINGER_PHALANX_PROXIMAL,
  87. JOINT_LEFT_RING_FINGER_PHALANX_INTERMEDIATE,
  88. JOINT_LEFT_RING_FINGER_PHALANX_DISTAL,
  89. JOINT_LEFT_RING_FINGER_TIP,
  90. JOINT_LEFT_PINKY_FINGER_METACARPAL,
  91. JOINT_LEFT_PINKY_FINGER_PHALANX_PROXIMAL,
  92. JOINT_LEFT_PINKY_FINGER_PHALANX_INTERMEDIATE,
  93. JOINT_LEFT_PINKY_FINGER_PHALANX_DISTAL,
  94. JOINT_LEFT_PINKY_FINGER_TIP,
  95. // Right Hand Joints
  96. JOINT_RIGHT_HAND,
  97. JOINT_RIGHT_PALM,
  98. JOINT_RIGHT_WRIST,
  99. JOINT_RIGHT_THUMB_METACARPAL,
  100. JOINT_RIGHT_THUMB_PHALANX_PROXIMAL,
  101. JOINT_RIGHT_THUMB_PHALANX_DISTAL,
  102. JOINT_RIGHT_THUMB_TIP,
  103. JOINT_RIGHT_INDEX_FINGER_METACARPAL,
  104. JOINT_RIGHT_INDEX_FINGER_PHALANX_PROXIMAL,
  105. JOINT_RIGHT_INDEX_FINGER_PHALANX_INTERMEDIATE,
  106. JOINT_RIGHT_INDEX_FINGER_PHALANX_DISTAL,
  107. JOINT_RIGHT_INDEX_FINGER_TIP,
  108. JOINT_RIGHT_MIDDLE_FINGER_METACARPAL,
  109. JOINT_RIGHT_MIDDLE_FINGER_PHALANX_PROXIMAL,
  110. JOINT_RIGHT_MIDDLE_FINGER_PHALANX_INTERMEDIATE,
  111. JOINT_RIGHT_MIDDLE_FINGER_PHALANX_DISTAL,
  112. JOINT_RIGHT_MIDDLE_FINGER_TIP,
  113. JOINT_RIGHT_RING_FINGER_METACARPAL,
  114. JOINT_RIGHT_RING_FINGER_PHALANX_PROXIMAL,
  115. JOINT_RIGHT_RING_FINGER_PHALANX_INTERMEDIATE,
  116. JOINT_RIGHT_RING_FINGER_PHALANX_DISTAL,
  117. JOINT_RIGHT_RING_FINGER_TIP,
  118. JOINT_RIGHT_PINKY_FINGER_METACARPAL,
  119. JOINT_RIGHT_PINKY_FINGER_PHALANX_PROXIMAL,
  120. JOINT_RIGHT_PINKY_FINGER_PHALANX_INTERMEDIATE,
  121. JOINT_RIGHT_PINKY_FINGER_PHALANX_DISTAL,
  122. JOINT_RIGHT_PINKY_FINGER_TIP,
  123. JOINT_MAX,
  124. };
  125. enum JointFlags {
  126. JOINT_FLAG_ORIENTATION_VALID = 1,
  127. JOINT_FLAG_ORIENTATION_TRACKED = 2,
  128. JOINT_FLAG_POSITION_VALID = 4,
  129. JOINT_FLAG_POSITION_TRACKED = 8,
  130. };
  131. void set_tracker_type(XRServer::TrackerType p_type) override;
  132. void set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand) override;
  133. void set_has_tracking_data(bool p_has_tracking_data);
  134. bool get_has_tracking_data() const;
  135. void set_body_flags(BitField<BodyFlags> p_body_flags);
  136. BitField<BodyFlags> get_body_flags() const;
  137. void set_joint_flags(Joint p_joint, BitField<JointFlags> p_flags);
  138. BitField<JointFlags> get_joint_flags(Joint p_joint) const;
  139. void set_joint_transform(Joint p_joint, const Transform3D &p_transform);
  140. Transform3D get_joint_transform(Joint p_joint) const;
  141. XRBodyTracker();
  142. protected:
  143. static void _bind_methods();
  144. private:
  145. bool has_tracking_data = false;
  146. BitField<BodyFlags> body_flags;
  147. BitField<JointFlags> joint_flags[JOINT_MAX];
  148. Transform3D joint_transforms[JOINT_MAX];
  149. };
  150. VARIANT_BITFIELD_CAST(XRBodyTracker::BodyFlags)
  151. VARIANT_ENUM_CAST(XRBodyTracker::Joint)
  152. VARIANT_BITFIELD_CAST(XRBodyTracker::JointFlags)
  153. #endif // XR_BODY_TRACKER_H