arvr_positional_tracker.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*************************************************************************/
  2. /* arvr_positional_tracker.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 ARVR_POSITIONAL_TRACKER_H
  31. #define ARVR_POSITIONAL_TRACKER_H
  32. #include "core/os/thread_safe.h"
  33. #include "servers/arvr_server.h"
  34. /**
  35. @author Bastiaan Olij <mux213@gmail.com>
  36. The positional tracker object as an object that represents the position and orientation of a tracked object like a controller or headset.
  37. An AR/VR Interface will registered the trackers it manages with our AR/VR server and update its position and orientation.
  38. This is where potentially additional AR/VR interfaces may be active as there are AR/VR SDKs that solely deal with positional tracking.
  39. @TODO:
  40. - create subclass of spatial node that uses one of our positional trackers to automatically determine its position
  41. */
  42. class ARVRPositionalTracker : public Object {
  43. GDCLASS(ARVRPositionalTracker, Object);
  44. _THREAD_SAFE_CLASS_
  45. public:
  46. enum TrackerHand {
  47. TRACKER_HAND_UNKNOWN, /* unknown or not applicable */
  48. TRACKER_LEFT_HAND, /* controller is the left hand controller */
  49. TRACKER_RIGHT_HAND /* controller is the right hand controller */
  50. };
  51. private:
  52. ARVRServer::TrackerType type; // type of tracker
  53. StringName name; // (unique) name of the tracker
  54. int tracker_id; // tracker index id that is unique per type
  55. int joy_id; // if we also have a related joystick entity, the id of the joystick
  56. bool tracks_orientation; // do we track orientation?
  57. Basis orientation; // our orientation
  58. bool tracks_position; // do we track position?
  59. Vector3 rw_position; // our position "in the real world, so without world_scale applied"
  60. TrackerHand hand; // if known, the hand this tracker is held in
  61. real_t rumble; // rumble strength, 0.0 is off, 1.0 is maximum, note that we only record here, arvr_interface is responsible for execution
  62. protected:
  63. static void _bind_methods();
  64. public:
  65. void set_type(ARVRServer::TrackerType p_type);
  66. ARVRServer::TrackerType get_type() const;
  67. void set_name(const String p_name);
  68. StringName get_name() const;
  69. int get_tracker_id() const;
  70. void set_joy_id(int p_joy_id);
  71. int get_joy_id() const;
  72. bool get_tracks_orientation() const;
  73. void set_orientation(const Basis &p_orientation);
  74. Basis get_orientation() const;
  75. bool get_tracks_position() const;
  76. void set_position(const Vector3 &p_position); // set position with world_scale applied
  77. Vector3 get_position() const; // get position with world_scale applied
  78. void set_rw_position(const Vector3 &p_rw_position);
  79. Vector3 get_rw_position() const;
  80. ARVRPositionalTracker::TrackerHand get_hand() const;
  81. void set_hand(const ARVRPositionalTracker::TrackerHand p_hand);
  82. real_t get_rumble() const;
  83. void set_rumble(real_t p_rumble);
  84. Transform get_transform(bool p_adjust_by_reference_frame) const;
  85. ARVRPositionalTracker();
  86. ~ARVRPositionalTracker();
  87. };
  88. VARIANT_ENUM_CAST(ARVRPositionalTracker::TrackerHand);
  89. #endif