openxr_hand_tracking_extension.h 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**************************************************************************/
  2. /* openxr_hand_tracking_extension.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 OPENXR_HAND_TRACKING_EXTENSION_H
  31. #define OPENXR_HAND_TRACKING_EXTENSION_H
  32. #include "../util.h"
  33. #include "openxr_extension_wrapper.h"
  34. #define MAX_OPENXR_TRACKED_HANDS 2
  35. class OpenXRHandTrackingExtension : public OpenXRExtensionWrapper {
  36. public:
  37. struct HandTracker {
  38. bool is_initialized = false;
  39. XrHandJointsMotionRangeEXT motion_range = XR_HAND_JOINTS_MOTION_RANGE_UNOBSTRUCTED_EXT;
  40. XrHandTrackerEXT hand_tracker = XR_NULL_HANDLE;
  41. XrHandJointLocationEXT joint_locations[XR_HAND_JOINT_COUNT_EXT];
  42. XrHandJointVelocityEXT joint_velocities[XR_HAND_JOINT_COUNT_EXT];
  43. XrHandTrackingAimStateFB aimState;
  44. XrHandJointVelocitiesEXT velocities;
  45. XrHandJointLocationsEXT locations;
  46. };
  47. static OpenXRHandTrackingExtension *get_singleton();
  48. OpenXRHandTrackingExtension();
  49. virtual ~OpenXRHandTrackingExtension() override;
  50. virtual HashMap<String, bool *> get_requested_extensions() override;
  51. virtual void on_instance_created(const XrInstance p_instance) override;
  52. virtual void on_instance_destroyed() override;
  53. virtual void on_session_destroyed() override;
  54. virtual void *set_system_properties_and_get_next_pointer(void *p_next_pointer) override;
  55. virtual void on_state_ready() override;
  56. virtual void on_process() override;
  57. virtual void on_state_stopping() override;
  58. bool get_active();
  59. const HandTracker *get_hand_tracker(uint32_t p_hand) const;
  60. XrHandJointsMotionRangeEXT get_motion_range(uint32_t p_hand) const;
  61. void set_motion_range(uint32_t p_hand, XrHandJointsMotionRangeEXT p_motion_range);
  62. private:
  63. static OpenXRHandTrackingExtension *singleton;
  64. // state
  65. XrSystemHandTrackingPropertiesEXT handTrackingSystemProperties;
  66. HandTracker hand_trackers[MAX_OPENXR_TRACKED_HANDS]; // Fixed for left and right hand
  67. // related extensions
  68. bool hand_tracking_ext = false;
  69. bool hand_motion_range_ext = false;
  70. bool hand_tracking_aim_state_ext = false;
  71. // functions
  72. void cleanup_hand_tracking();
  73. // OpenXR API call wrappers
  74. EXT_PROTO_XRRESULT_FUNC3(xrCreateHandTrackerEXT, (XrSession), p_session, (const XrHandTrackerCreateInfoEXT *), p_createInfo, (XrHandTrackerEXT *), p_handTracker)
  75. EXT_PROTO_XRRESULT_FUNC1(xrDestroyHandTrackerEXT, (XrHandTrackerEXT), p_handTracker)
  76. EXT_PROTO_XRRESULT_FUNC3(xrLocateHandJointsEXT, (XrHandTrackerEXT), p_handTracker, (const XrHandJointsLocateInfoEXT *), p_locateInfo, (XrHandJointLocationsEXT *), p_locations)
  77. };
  78. #endif // OPENXR_HAND_TRACKING_EXTENSION_H