xr_interface.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*************************************************************************/
  2. /* xr_interface.cpp */
  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. #include "xr_interface.h"
  31. // #include "servers/rendering/renderer_compositor.h"
  32. void XRInterface::_bind_methods() {
  33. ClassDB::bind_method(D_METHOD("get_name"), &XRInterface::get_name);
  34. ClassDB::bind_method(D_METHOD("get_capabilities"), &XRInterface::get_capabilities);
  35. ClassDB::bind_method(D_METHOD("is_primary"), &XRInterface::is_primary);
  36. ClassDB::bind_method(D_METHOD("set_primary", "primary"), &XRInterface::set_primary);
  37. ClassDB::bind_method(D_METHOD("is_initialized"), &XRInterface::is_initialized);
  38. ClassDB::bind_method(D_METHOD("initialize"), &XRInterface::initialize);
  39. ClassDB::bind_method(D_METHOD("uninitialize"), &XRInterface::uninitialize);
  40. ClassDB::bind_method(D_METHOD("get_tracking_status"), &XRInterface::get_tracking_status);
  41. ClassDB::bind_method(D_METHOD("get_render_target_size"), &XRInterface::get_render_target_size);
  42. ClassDB::bind_method(D_METHOD("get_view_count"), &XRInterface::get_view_count);
  43. ADD_GROUP("Interface", "interface_");
  44. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interface_is_primary"), "set_primary", "is_primary");
  45. // we don't have any properties specific to VR yet....
  46. // but we do have properties specific to AR....
  47. ClassDB::bind_method(D_METHOD("get_anchor_detection_is_enabled"), &XRInterface::get_anchor_detection_is_enabled);
  48. ClassDB::bind_method(D_METHOD("set_anchor_detection_is_enabled", "enable"), &XRInterface::set_anchor_detection_is_enabled);
  49. ClassDB::bind_method(D_METHOD("get_camera_feed_id"), &XRInterface::get_camera_feed_id);
  50. ADD_GROUP("AR", "ar_");
  51. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ar_is_anchor_detection_enabled"), "set_anchor_detection_is_enabled", "get_anchor_detection_is_enabled");
  52. BIND_ENUM_CONSTANT(XR_NONE);
  53. BIND_ENUM_CONSTANT(XR_MONO);
  54. BIND_ENUM_CONSTANT(XR_STEREO);
  55. BIND_ENUM_CONSTANT(XR_AR);
  56. BIND_ENUM_CONSTANT(XR_EXTERNAL);
  57. BIND_ENUM_CONSTANT(EYE_MONO);
  58. BIND_ENUM_CONSTANT(EYE_LEFT);
  59. BIND_ENUM_CONSTANT(EYE_RIGHT);
  60. BIND_ENUM_CONSTANT(XR_NORMAL_TRACKING);
  61. BIND_ENUM_CONSTANT(XR_EXCESSIVE_MOTION);
  62. BIND_ENUM_CONSTANT(XR_INSUFFICIENT_FEATURES);
  63. BIND_ENUM_CONSTANT(XR_UNKNOWN_TRACKING);
  64. BIND_ENUM_CONSTANT(XR_NOT_TRACKING);
  65. }
  66. bool XRInterface::is_primary() {
  67. XRServer *xr_server = XRServer::get_singleton();
  68. ERR_FAIL_NULL_V(xr_server, false);
  69. return xr_server->get_primary_interface() == this;
  70. }
  71. void XRInterface::set_primary(bool p_primary) {
  72. XRServer *xr_server = XRServer::get_singleton();
  73. ERR_FAIL_NULL(xr_server);
  74. if (p_primary) {
  75. ERR_FAIL_COND(!is_initialized());
  76. xr_server->set_primary_interface(this);
  77. } else if (xr_server->get_primary_interface() == this) {
  78. xr_server->set_primary_interface(nullptr);
  79. }
  80. }
  81. XRInterface::XRInterface() {}
  82. XRInterface::~XRInterface() {}
  83. /** these will only be implemented on AR interfaces, so we want dummies for VR **/
  84. bool XRInterface::get_anchor_detection_is_enabled() const {
  85. return false;
  86. }
  87. void XRInterface::set_anchor_detection_is_enabled(bool p_enable) {
  88. }
  89. int XRInterface::get_camera_feed_id() {
  90. return 0;
  91. }
  92. /** these are optional, so we want dummies **/
  93. XRInterface::TrackingStatus XRInterface::get_tracking_status() const {
  94. return XR_UNKNOWN_TRACKING;
  95. }
  96. void XRInterface::notification(int p_what) {
  97. }