arvr_interface.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*************************************************************************/
  2. /* arvr_interface.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_INTERFACE_H
  31. #define ARVR_INTERFACE_H
  32. #include "core/math/camera_matrix.h"
  33. #include "core/os/thread_safe.h"
  34. #include "scene/main/viewport.h"
  35. #include "servers/arvr_server.h"
  36. /**
  37. @author Bastiaan Olij <mux213@gmail.com>
  38. The ARVR interface is a template class ontop of which we build interface to differt AR, VR and tracking SDKs.
  39. The idea is that we subclass this class, implement the logic, and then instantiate a singleton of each interface
  40. when Godot starts. These instances do not initialize themselves but register themselves with the AR/VR server.
  41. If the user wants to enable AR/VR the choose the interface they want to use and initialize it.
  42. Note that we may make this into a fully instantiable class for GDNative support.
  43. */
  44. class ARVRInterface : public Reference {
  45. GDCLASS(ARVRInterface, Reference);
  46. public:
  47. enum Capabilities { /* purely meta data, provides some info about what this interface supports */
  48. ARVR_NONE = 0, /* no capabilities */
  49. ARVR_MONO = 1, /* can be used with mono output */
  50. ARVR_STEREO = 2, /* can be used with stereo output */
  51. ARVR_AR = 4, /* offers a camera feed for AR */
  52. ARVR_EXTERNAL = 8 /* renders to external device */
  53. };
  54. enum Eyes {
  55. EYE_MONO, /* my son says we should call this EYE_CYCLOPS */
  56. EYE_LEFT,
  57. EYE_RIGHT
  58. };
  59. enum Tracking_status { /* tracking status currently based on AR but we can start doing more with this for VR as well */
  60. ARVR_NORMAL_TRACKING,
  61. ARVR_EXCESSIVE_MOTION,
  62. ARVR_INSUFFICIENT_FEATURES,
  63. ARVR_UNKNOWN_TRACKING,
  64. ARVR_NOT_TRACKING
  65. };
  66. protected:
  67. _THREAD_SAFE_CLASS_
  68. Tracking_status tracking_state;
  69. static void _bind_methods();
  70. public:
  71. /** general interface information **/
  72. virtual StringName get_name() const;
  73. virtual int get_capabilities() const = 0;
  74. bool is_primary();
  75. void set_is_primary(bool p_is_primary);
  76. virtual bool is_initialized() const = 0; /* returns true if we've initialized this interface */
  77. void set_is_initialized(bool p_initialized); /* helper function, will call initialize or uninitialize */
  78. virtual bool initialize() = 0; /* initialize this interface, if this has an HMD it becomes the primary interface */
  79. virtual void uninitialize() = 0; /* deinitialize this interface */
  80. Tracking_status get_tracking_status() const; /* get the status of our current tracking */
  81. /** specific to VR **/
  82. // nothing yet
  83. /** specific to AR **/
  84. virtual bool get_anchor_detection_is_enabled() const;
  85. virtual void set_anchor_detection_is_enabled(bool p_enable);
  86. /** rendering and internal **/
  87. virtual Size2 get_render_targetsize() = 0; /* returns the recommended render target size per eye for this device */
  88. virtual bool is_stereo() = 0; /* returns true if this interface requires stereo rendering (for VR HMDs) or mono rendering (for mobile AR) */
  89. virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform) = 0; /* get each eyes camera transform, also implement EYE_MONO */
  90. virtual CameraMatrix get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) = 0; /* get each eyes projection matrix */
  91. virtual void commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) = 0; /* output the left or right eye */
  92. virtual void process() = 0;
  93. ARVRInterface();
  94. ~ARVRInterface();
  95. };
  96. VARIANT_ENUM_CAST(ARVRInterface::Capabilities);
  97. VARIANT_ENUM_CAST(ARVRInterface::Eyes);
  98. VARIANT_ENUM_CAST(ARVRInterface::Tracking_status);
  99. #endif