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