arvr_nodes.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*************************************************************************/
  2. /* arvr_nodes.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_NODES_H
  31. #define ARVR_NODES_H
  32. #include "scene/3d/camera.h"
  33. #include "scene/3d/spatial.h"
  34. #include "servers/arvr/arvr_positional_tracker.h"
  35. /**
  36. @author Bastiaan Olij <mux213@gmail.com>
  37. **/
  38. /*
  39. ARVRCamera is a subclass of camera which will register itself with its parent ARVROrigin and as a result is automatically positioned
  40. */
  41. class ARVRCamera : public Camera {
  42. GDCLASS(ARVRCamera, Camera);
  43. protected:
  44. void _notification(int p_what);
  45. public:
  46. String get_configuration_warning() const;
  47. virtual Vector3 project_local_ray_normal(const Point2 &p_pos) const;
  48. virtual Point2 unproject_position(const Vector3 &p_pos) const;
  49. virtual Vector3 project_position(const Point2 &p_point) const;
  50. virtual Vector<Plane> get_frustum() const;
  51. ARVRCamera();
  52. ~ARVRCamera();
  53. };
  54. /*
  55. ARVRController is a helper node that automatically updates its position based on tracker data.
  56. It must be a child node of our ARVROrigin node
  57. */
  58. class ARVRController : public Spatial {
  59. GDCLASS(ARVRController, Spatial);
  60. private:
  61. int controller_id;
  62. bool is_active;
  63. int button_states;
  64. protected:
  65. void _notification(int p_what);
  66. static void _bind_methods();
  67. public:
  68. void set_controller_id(int p_controller_id);
  69. int get_controller_id(void) const;
  70. String get_controller_name(void) const;
  71. int get_joystick_id() const;
  72. int is_button_pressed(int p_button) const;
  73. float get_joystick_axis(int p_axis) const;
  74. real_t get_rumble() const;
  75. void set_rumble(real_t p_rumble);
  76. bool get_is_active() const;
  77. ARVRPositionalTracker::TrackerHand get_hand() const;
  78. String get_configuration_warning() const;
  79. ARVRController();
  80. ~ARVRController();
  81. };
  82. /*
  83. ARVRAnchor is a helper node that automatically updates its position based on anchor data, it represents a real world location.
  84. It must be a child node of our ARVROrigin node
  85. */
  86. class ARVRAnchor : public Spatial {
  87. GDCLASS(ARVRAnchor, Spatial);
  88. private:
  89. int anchor_id;
  90. bool is_active;
  91. Vector3 size;
  92. protected:
  93. void _notification(int p_what);
  94. static void _bind_methods();
  95. public:
  96. void set_anchor_id(int p_anchor_id);
  97. int get_anchor_id(void) const;
  98. String get_anchor_name(void) const;
  99. bool get_is_active() const;
  100. Vector3 get_size() const;
  101. Plane get_plane() const;
  102. String get_configuration_warning() const;
  103. ARVRAnchor();
  104. ~ARVRAnchor();
  105. };
  106. /*
  107. ARVROrigin is special spatial node that acts as our origin point mapping our real world center of our tracking volume into our virtual world.
  108. It is this point that you will move around the world as the player 'moves while standing still', i.e. the player moves through teleporting or controller inputs as opposed to physically moving.
  109. Our camera and controllers will always be child nodes and thus place relative to this origin point.
  110. This node will automatically locate any camera child nodes and update its position while our ARVRController node will handle tracked controllers.
  111. */
  112. class ARVROrigin : public Spatial {
  113. GDCLASS(ARVROrigin, Spatial);
  114. private:
  115. ARVRCamera *tracked_camera;
  116. protected:
  117. void _notification(int p_what);
  118. static void _bind_methods();
  119. public:
  120. String get_configuration_warning() const;
  121. void set_tracked_camera(ARVRCamera *p_tracked_camera);
  122. void clear_tracked_camera_if(ARVRCamera *p_tracked_camera);
  123. float get_world_scale() const;
  124. void set_world_scale(float p_world_scale);
  125. ARVROrigin();
  126. ~ARVROrigin();
  127. };
  128. #endif /* ARVR_NODES_H */