1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/*************************************************************************/
/* arkit_interface.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef ARKIT_INTERFACE_H
#define ARKIT_INTERFACE_H
#include "servers/arvr/arvr_interface.h"
#include "servers/arvr/arvr_positional_tracker.h"
#include "servers/camera/camera_feed.h"
/**
@author Bastiaan Olij <mux213@gmail.com>
ARKit interface between iPhone and Godot
*/
// forward declaration for some needed objects
class ARKitShader;
class ARKitInterface : public ARVRInterface {
GDCLASS(ARKitInterface, ARVRInterface);
private:
bool initialized;
bool session_was_started;
bool plane_detection_is_enabled;
bool light_estimation_is_enabled;
real_t ambient_intensity;
real_t ambient_color_temperature;
Transform transform;
CameraMatrix projection;
float eye_height, z_near, z_far;
Ref<CameraFeed> feed;
int image_width[2];
int image_height[2];
PoolVector<uint8_t> img_data[2];
struct anchor_map {
ARVRPositionalTracker *tracker;
unsigned char uuid[16];
};
///@TODO should use memory map object from Godot?
unsigned int num_anchors;
unsigned int max_anchors;
anchor_map *anchors;
ARVRPositionalTracker *get_anchor_for_uuid(const unsigned char *p_uuid);
void remove_anchor_for_uuid(const unsigned char *p_uuid);
void remove_all_anchors();
protected:
static void _bind_methods();
public:
void start_session();
void stop_session();
bool get_anchor_detection_is_enabled() const;
void set_anchor_detection_is_enabled(bool p_enable);
virtual int get_camera_feed_id();
bool get_light_estimation_is_enabled() const;
void set_light_estimation_is_enabled(bool p_enable);
real_t get_ambient_intensity() const;
real_t get_ambient_color_temperature() const;
/* while Godot has its own raycast logic this takes ARKits camera into account and hits on any ARAnchor */
Array raycast(Vector2 p_screen_coord);
void notification(int p_what);
virtual StringName get_name() const;
virtual int get_capabilities() const;
virtual bool is_initialized() const;
virtual bool initialize();
virtual void uninitialize();
virtual Size2 get_render_targetsize();
virtual bool is_stereo();
virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform);
virtual CameraMatrix get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far);
virtual void commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect);
virtual void process();
// called by delegate (void * because C++ and Obj-C don't always mix, should really change all platform/iphone/*.cpp files to .mm)
void _add_or_update_anchor(void *p_anchor);
void _remove_anchor(void *p_anchor);
ARKitInterface();
~ARKitInterface();
};
#endif /* !ARKIT_INTERFACE_H */
|