arkit_interface.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*************************************************************************/
  2. /* arkit_interface.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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 ARKIT_INTERFACE_H
  31. #define ARKIT_INTERFACE_H
  32. #include "servers/arvr/arvr_interface.h"
  33. #include "servers/arvr/arvr_positional_tracker.h"
  34. #include "servers/camera/camera_feed.h"
  35. /**
  36. @author Bastiaan Olij <[email protected]>
  37. ARKit interface between iPhone and Godot
  38. */
  39. // forward declaration for some needed objects
  40. class ARKitShader;
  41. class ARKitInterface : public ARVRInterface {
  42. GDCLASS(ARKitInterface, ARVRInterface);
  43. private:
  44. bool initialized;
  45. bool session_was_started;
  46. bool plane_detection_is_enabled;
  47. bool light_estimation_is_enabled;
  48. real_t ambient_intensity;
  49. real_t ambient_color_temperature;
  50. Transform transform;
  51. CameraMatrix projection;
  52. float eye_height, z_near, z_far;
  53. Ref<CameraFeed> feed;
  54. int image_width[2];
  55. int image_height[2];
  56. PoolVector<uint8_t> img_data[2];
  57. struct anchor_map {
  58. ARVRPositionalTracker *tracker;
  59. unsigned char uuid[16];
  60. };
  61. ///@TODO should use memory map object from Godot?
  62. unsigned int num_anchors;
  63. unsigned int max_anchors;
  64. anchor_map *anchors;
  65. ARVRPositionalTracker *get_anchor_for_uuid(const unsigned char *p_uuid);
  66. void remove_anchor_for_uuid(const unsigned char *p_uuid);
  67. void remove_all_anchors();
  68. protected:
  69. static void _bind_methods();
  70. public:
  71. void start_session();
  72. void stop_session();
  73. bool get_anchor_detection_is_enabled() const;
  74. void set_anchor_detection_is_enabled(bool p_enable);
  75. virtual int get_camera_feed_id();
  76. bool get_light_estimation_is_enabled() const;
  77. void set_light_estimation_is_enabled(bool p_enable);
  78. real_t get_ambient_intensity() const;
  79. real_t get_ambient_color_temperature() const;
  80. /* while Godot has its own raycast logic this takes ARKits camera into account and hits on any ARAnchor */
  81. Array raycast(Vector2 p_screen_coord);
  82. void notification(int p_what);
  83. virtual StringName get_name() const;
  84. virtual int get_capabilities() const;
  85. virtual bool is_initialized() const;
  86. virtual bool initialize();
  87. virtual void uninitialize();
  88. virtual Size2 get_render_targetsize();
  89. virtual bool is_stereo();
  90. virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform);
  91. virtual CameraMatrix get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far);
  92. virtual void commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect);
  93. virtual void process();
  94. // called by delegate (void * because C++ and Obj-C don't always mix, should really change all platform/iphone/*.cpp files to .mm)
  95. void _add_or_update_anchor(void *p_anchor);
  96. void _remove_anchor(void *p_anchor);
  97. ARKitInterface();
  98. ~ARKitInterface();
  99. };
  100. #endif /* !ARKIT_INTERFACE_H */