xr_interface.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*************************************************************************/
  2. /* xr_interface.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_INTERFACE_H
  31. #define XR_INTERFACE_H
  32. #include "core/math/camera_matrix.h"
  33. #include "core/os/thread_safe.h"
  34. #include "servers/xr_server.h"
  35. /**
  36. @author Bastiaan Olij <[email protected]>
  37. The XR interface is a template class ontop of which we build interface to different AR, VR and tracking SDKs.
  38. The idea is that we subclass this class, implement the logic, and then instantiate a singleton of each interface
  39. when Godot starts. These instances do not initialize themselves but register themselves with the AR/VR server.
  40. If the user wants to enable AR/VR the choose the interface they want to use and initialize it.
  41. Note that we may make this into a fully instantiable class for GDNative support.
  42. */
  43. class XRInterface : public Reference {
  44. GDCLASS(XRInterface, Reference);
  45. public:
  46. enum Capabilities { /* purely meta data, provides some info about what this interface supports */
  47. XR_NONE = 0, /* no capabilities */
  48. XR_MONO = 1, /* can be used with mono output */
  49. XR_STEREO = 2, /* can be used with stereo output */
  50. XR_AR = 4, /* offers a camera feed for AR */
  51. XR_EXTERNAL = 8 /* renders to external device */
  52. };
  53. enum Eyes {
  54. EYE_MONO, /* my son says we should call this EYE_CYCLOPS */
  55. EYE_LEFT,
  56. EYE_RIGHT
  57. };
  58. enum Tracking_status { /* tracking status currently based on AR but we can start doing more with this for VR as well */
  59. XR_NORMAL_TRACKING,
  60. XR_EXCESSIVE_MOTION,
  61. XR_INSUFFICIENT_FEATURES,
  62. XR_UNKNOWN_TRACKING,
  63. XR_NOT_TRACKING
  64. };
  65. protected:
  66. _THREAD_SAFE_CLASS_
  67. Tracking_status tracking_state;
  68. static void _bind_methods();
  69. public:
  70. /** general interface information **/
  71. virtual StringName get_name() const;
  72. virtual int get_capabilities() const = 0;
  73. bool is_primary();
  74. void set_is_primary(bool p_is_primary);
  75. virtual bool is_initialized() const = 0; /* returns true if we've initialized this interface */
  76. void set_is_initialized(bool p_initialized); /* helper function, will call initialize or uninitialize */
  77. virtual bool initialize() = 0; /* initialize this interface, if this has an HMD it becomes the primary interface */
  78. virtual void uninitialize() = 0; /* deinitialize this interface */
  79. Tracking_status get_tracking_status() const; /* get the status of our current tracking */
  80. /** specific to VR **/
  81. // nothing yet
  82. /** specific to AR **/
  83. virtual bool get_anchor_detection_is_enabled() const;
  84. virtual void set_anchor_detection_is_enabled(bool p_enable);
  85. virtual int get_camera_feed_id();
  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(XRInterface::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(XRInterface::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 unsigned int get_external_texture_for_eye(XRInterface::Eyes p_eye); /* if applicable return external texture to render to */
  92. virtual void commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) = 0; /* output the left or right eye */
  93. virtual void process() = 0;
  94. virtual void notification(int p_what) = 0;
  95. XRInterface();
  96. ~XRInterface();
  97. };
  98. VARIANT_ENUM_CAST(XRInterface::Capabilities);
  99. VARIANT_ENUM_CAST(XRInterface::Eyes);
  100. VARIANT_ENUM_CAST(XRInterface::Tracking_status);
  101. #endif