2
0

xr_positional_tracker.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*************************************************************************/
  2. /* xr_positional_tracker.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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_POSITIONAL_TRACKER_H
  31. #define XR_POSITIONAL_TRACKER_H
  32. #include "core/os/thread_safe.h"
  33. #include "scene/resources/mesh.h"
  34. #include "servers/xr/xr_pose.h"
  35. #include "servers/xr_server.h"
  36. /**
  37. @author Bastiaan Olij <[email protected]>
  38. The positional tracker object as an object that represents the position and orientation of a tracked object like a controller or headset.
  39. An AR/VR Interface will registered the trackers it manages with our AR/VR server and update its position and orientation.
  40. This is where potentially additional AR/VR interfaces may be active as there are AR/VR SDKs that solely deal with positional tracking.
  41. */
  42. class XRPositionalTracker : public RefCounted {
  43. GDCLASS(XRPositionalTracker, RefCounted);
  44. _THREAD_SAFE_CLASS_
  45. public:
  46. enum TrackerHand {
  47. TRACKER_HAND_UNKNOWN, /* unknown or not applicable */
  48. TRACKER_HAND_LEFT, /* controller is the left hand controller */
  49. TRACKER_HAND_RIGHT /* controller is the right hand controller */
  50. };
  51. private:
  52. XRServer::TrackerType type; // type of tracker
  53. StringName name; // (unique) name of the tracker
  54. String description; // description of the tracker, this is interface dependent, for OpenXR this will be the interaction profile bound for to the tracker
  55. TrackerHand hand; // if known, the hand this tracker is held in
  56. Map<StringName, Ref<XRPose>> poses;
  57. Map<StringName, Variant> inputs;
  58. int joy_id; // if we also have a related joystick entity, the id of the joystick
  59. Ref<Mesh> mesh; // when available, a mesh that can be used to render this tracker
  60. real_t rumble; // rumble strength, 0.0 is off, 1.0 is maximum, note that we only record here, xr_interface is responsible for execution
  61. protected:
  62. static void _bind_methods();
  63. public:
  64. void set_tracker_type(XRServer::TrackerType p_type);
  65. XRServer::TrackerType get_tracker_type() const;
  66. void set_tracker_name(const StringName &p_name);
  67. StringName get_tracker_name() const;
  68. void set_tracker_desc(const String &p_desc);
  69. String get_tracker_desc() const;
  70. XRPositionalTracker::TrackerHand get_tracker_hand() const;
  71. void set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand);
  72. bool has_pose(const StringName &p_action_name) const;
  73. Ref<XRPose> get_pose(const StringName &p_action_name) const;
  74. void invalidate_pose(const StringName &p_action_name);
  75. void set_pose(const StringName &p_action_name, const Transform3D &p_transform, const Vector3 &p_linear_velocity, const Vector3 &p_angular_velocity);
  76. Variant get_input(const StringName &p_action_name) const;
  77. void set_input(const StringName &p_action_name, const Variant &p_value);
  78. // TODO replace by new implementation
  79. real_t get_rumble() const;
  80. void set_rumble(real_t p_rumble);
  81. XRPositionalTracker();
  82. ~XRPositionalTracker() {}
  83. };
  84. VARIANT_ENUM_CAST(XRPositionalTracker::TrackerHand);
  85. #endif