xr_hand_tracker.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**************************************************************************/
  2. /* xr_hand_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_HAND_TRACKER_H
  31. #define XR_HAND_TRACKER_H
  32. #include "servers/xr/xr_positional_tracker.h"
  33. class XRHandTracker : public XRPositionalTracker {
  34. GDCLASS(XRHandTracker, XRPositionalTracker);
  35. _THREAD_SAFE_CLASS_
  36. public:
  37. enum HandTrackingSource {
  38. HAND_TRACKING_SOURCE_UNKNOWN,
  39. HAND_TRACKING_SOURCE_UNOBSTRUCTED,
  40. HAND_TRACKING_SOURCE_CONTROLLER,
  41. HAND_TRACKING_SOURCE_MAX
  42. };
  43. enum HandJoint {
  44. HAND_JOINT_PALM,
  45. HAND_JOINT_WRIST,
  46. HAND_JOINT_THUMB_METACARPAL,
  47. HAND_JOINT_THUMB_PHALANX_PROXIMAL,
  48. HAND_JOINT_THUMB_PHALANX_DISTAL,
  49. HAND_JOINT_THUMB_TIP,
  50. HAND_JOINT_INDEX_FINGER_METACARPAL,
  51. HAND_JOINT_INDEX_FINGER_PHALANX_PROXIMAL,
  52. HAND_JOINT_INDEX_FINGER_PHALANX_INTERMEDIATE,
  53. HAND_JOINT_INDEX_FINGER_PHALANX_DISTAL,
  54. HAND_JOINT_INDEX_FINGER_TIP,
  55. HAND_JOINT_MIDDLE_FINGER_METACARPAL,
  56. HAND_JOINT_MIDDLE_FINGER_PHALANX_PROXIMAL,
  57. HAND_JOINT_MIDDLE_FINGER_PHALANX_INTERMEDIATE,
  58. HAND_JOINT_MIDDLE_FINGER_PHALANX_DISTAL,
  59. HAND_JOINT_MIDDLE_FINGER_TIP,
  60. HAND_JOINT_RING_FINGER_METACARPAL,
  61. HAND_JOINT_RING_FINGER_PHALANX_PROXIMAL,
  62. HAND_JOINT_RING_FINGER_PHALANX_INTERMEDIATE,
  63. HAND_JOINT_RING_FINGER_PHALANX_DISTAL,
  64. HAND_JOINT_RING_FINGER_TIP,
  65. HAND_JOINT_PINKY_FINGER_METACARPAL,
  66. HAND_JOINT_PINKY_FINGER_PHALANX_PROXIMAL,
  67. HAND_JOINT_PINKY_FINGER_PHALANX_INTERMEDIATE,
  68. HAND_JOINT_PINKY_FINGER_PHALANX_DISTAL,
  69. HAND_JOINT_PINKY_FINGER_TIP,
  70. HAND_JOINT_MAX,
  71. };
  72. enum HandJointFlags {
  73. HAND_JOINT_FLAG_ORIENTATION_VALID = 1,
  74. HAND_JOINT_FLAG_ORIENTATION_TRACKED = 2,
  75. HAND_JOINT_FLAG_POSITION_VALID = 4,
  76. HAND_JOINT_FLAG_POSITION_TRACKED = 8,
  77. HAND_JOINT_FLAG_LINEAR_VELOCITY_VALID = 16,
  78. HAND_JOINT_FLAG_ANGULAR_VELOCITY_VALID = 32,
  79. };
  80. void set_tracker_type(XRServer::TrackerType p_type) override;
  81. void set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand) override;
  82. void set_has_tracking_data(bool p_has_tracking_data);
  83. bool get_has_tracking_data() const;
  84. void set_hand_tracking_source(HandTrackingSource p_source);
  85. HandTrackingSource get_hand_tracking_source() const;
  86. void set_hand_joint_flags(HandJoint p_joint, BitField<HandJointFlags> p_flags);
  87. BitField<HandJointFlags> get_hand_joint_flags(HandJoint p_joint) const;
  88. void set_hand_joint_transform(HandJoint p_joint, const Transform3D &p_transform);
  89. Transform3D get_hand_joint_transform(HandJoint p_joint) const;
  90. void set_hand_joint_radius(HandJoint p_joint, float p_radius);
  91. float get_hand_joint_radius(HandJoint p_joint) const;
  92. void set_hand_joint_linear_velocity(HandJoint p_joint, const Vector3 &p_velocity);
  93. Vector3 get_hand_joint_linear_velocity(HandJoint p_joint) const;
  94. void set_hand_joint_angular_velocity(HandJoint p_joint, const Vector3 &p_velocity);
  95. Vector3 get_hand_joint_angular_velocity(HandJoint p_joint) const;
  96. XRHandTracker();
  97. protected:
  98. static void _bind_methods();
  99. private:
  100. bool has_tracking_data = false;
  101. HandTrackingSource hand_tracking_source = HAND_TRACKING_SOURCE_UNKNOWN;
  102. BitField<HandJointFlags> hand_joint_flags[HAND_JOINT_MAX];
  103. Transform3D hand_joint_transforms[HAND_JOINT_MAX];
  104. float hand_joint_radii[HAND_JOINT_MAX] = {};
  105. Vector3 hand_joint_linear_velocities[HAND_JOINT_MAX];
  106. Vector3 hand_joint_angular_velocities[HAND_JOINT_MAX];
  107. };
  108. VARIANT_ENUM_CAST(XRHandTracker::HandTrackingSource)
  109. VARIANT_ENUM_CAST(XRHandTracker::HandJoint)
  110. VARIANT_BITFIELD_CAST(XRHandTracker::HandJointFlags)
  111. #endif // XR_HAND_TRACKER_H