arvr_interface.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*************************************************************************/
  2. /* arvr_interface.cpp */
  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. #include "arvr_interface.h"
  31. void ARVRInterface::_bind_methods() {
  32. ClassDB::bind_method(D_METHOD("get_name"), &ARVRInterface::get_name);
  33. ClassDB::bind_method(D_METHOD("get_capabilities"), &ARVRInterface::get_capabilities);
  34. ClassDB::bind_method(D_METHOD("is_primary"), &ARVRInterface::is_primary);
  35. ClassDB::bind_method(D_METHOD("set_is_primary", "enable"), &ARVRInterface::set_is_primary);
  36. ClassDB::bind_method(D_METHOD("is_initialized"), &ARVRInterface::is_initialized);
  37. ClassDB::bind_method(D_METHOD("set_is_initialized", "initialized"), &ARVRInterface::set_is_initialized);
  38. ClassDB::bind_method(D_METHOD("initialize"), &ARVRInterface::initialize);
  39. ClassDB::bind_method(D_METHOD("uninitialize"), &ARVRInterface::uninitialize);
  40. ClassDB::bind_method(D_METHOD("get_tracking_status"), &ARVRInterface::get_tracking_status);
  41. ClassDB::bind_method(D_METHOD("get_render_targetsize"), &ARVRInterface::get_render_targetsize);
  42. ClassDB::bind_method(D_METHOD("is_stereo"), &ARVRInterface::is_stereo);
  43. ADD_GROUP("Interface", "interface_");
  44. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interface_is_primary"), "set_is_primary", "is_primary");
  45. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interface_is_initialized"), "set_is_initialized", "is_initialized");
  46. // we don't have any properties specific to VR yet....
  47. // but we do have properties specific to AR....
  48. ClassDB::bind_method(D_METHOD("get_anchor_detection_is_enabled"), &ARVRInterface::get_anchor_detection_is_enabled);
  49. ClassDB::bind_method(D_METHOD("set_anchor_detection_is_enabled", "enable"), &ARVRInterface::set_anchor_detection_is_enabled);
  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(ARVR_NONE);
  53. BIND_ENUM_CONSTANT(ARVR_MONO);
  54. BIND_ENUM_CONSTANT(ARVR_STEREO);
  55. BIND_ENUM_CONSTANT(ARVR_AR);
  56. BIND_ENUM_CONSTANT(ARVR_EXTERNAL);
  57. BIND_ENUM_CONSTANT(EYE_MONO);
  58. BIND_ENUM_CONSTANT(EYE_LEFT);
  59. BIND_ENUM_CONSTANT(EYE_RIGHT);
  60. BIND_ENUM_CONSTANT(ARVR_NORMAL_TRACKING);
  61. BIND_ENUM_CONSTANT(ARVR_EXCESSIVE_MOTION);
  62. BIND_ENUM_CONSTANT(ARVR_INSUFFICIENT_FEATURES);
  63. BIND_ENUM_CONSTANT(ARVR_UNKNOWN_TRACKING);
  64. BIND_ENUM_CONSTANT(ARVR_NOT_TRACKING);
  65. };
  66. StringName ARVRInterface::get_name() const {
  67. return "Unknown";
  68. };
  69. bool ARVRInterface::is_primary() {
  70. ARVRServer *arvr_server = ARVRServer::get_singleton();
  71. ERR_FAIL_NULL_V(arvr_server, false);
  72. return arvr_server->get_primary_interface() == this;
  73. };
  74. void ARVRInterface::set_is_primary(bool p_is_primary) {
  75. ARVRServer *arvr_server = ARVRServer::get_singleton();
  76. ERR_FAIL_NULL(arvr_server);
  77. if (p_is_primary) {
  78. ERR_FAIL_COND(!is_initialized());
  79. arvr_server->set_primary_interface(this);
  80. } else {
  81. arvr_server->clear_primary_interface_if(this);
  82. };
  83. };
  84. void ARVRInterface::set_is_initialized(bool p_initialized) {
  85. if (p_initialized) {
  86. if (!is_initialized()) {
  87. initialize();
  88. };
  89. } else {
  90. if (is_initialized()) {
  91. uninitialize();
  92. };
  93. };
  94. };
  95. ARVRInterface::Tracking_status ARVRInterface::get_tracking_status() const {
  96. return tracking_state;
  97. };
  98. ARVRInterface::ARVRInterface() {
  99. tracking_state = ARVR_UNKNOWN_TRACKING;
  100. };
  101. ARVRInterface::~ARVRInterface(){};
  102. /** these will only be implemented on AR interfaces, so we want dummies for VR **/
  103. bool ARVRInterface::get_anchor_detection_is_enabled() const {
  104. return false;
  105. };
  106. void ARVRInterface::set_anchor_detection_is_enabled(bool p_enable){
  107. // don't do anything here, this needs to be implemented on AR interface to enable/disable things like plane detection etc.
  108. };