Debian Codegraph @

scene/3d/xr/xr_nodes.h

raw symbols SCIP
1 /**************************************************************************/
2 /* xr_nodes.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
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 #pragma once
32
33 #include "scene/3d/camera_3d.h"
34 #include "servers/xr/xr_positional_tracker.h"
35
36 /*
37 XRCamera is a subclass of camera which will register itself with its parent XROrigin and as a result is automatically positioned
38 */
39
40 class XRCamera3D : public Camera3D {
41 GDCLASS(XRCamera3D, Camera3D);
42
43 protected:
44 // The name and pose for our HMD tracker is currently the only hardcoded bit.
45 // If we ever are able to support multiple HMDs we may need to make this settable.
46 StringName tracker_name = "head";
47 StringName pose_name = SceneStringName(default_);
48 Ref<XRPositionalTracker> tracker;
49
50 void _validate_property(PropertyInfo &p_property) const;
51
52 void _bind_tracker();
53 void _unbind_tracker();
54 void _changed_tracker(const StringName &p_tracker_name, int p_tracker_type);
55 void _removed_tracker(const StringName &p_tracker_name, int p_tracker_type);
56 void _pose_changed(const Ref<XRPose> &p_pose);
57 virtual void _physics_interpolated_changed() override;
58
59 public:
60 PackedStringArray get_configuration_warnings() const override;
61
62 virtual Vector3 project_local_ray_normal(const Point2 &p_pos) const override;
63 virtual Point2 unproject_position(const Vector3 &p_pos) const override;
64 virtual Vector3 project_position(const Point2 &p_point, real_t p_z_depth) const override;
65 virtual Vector<Plane> get_frustum() const override;
66
67 XRCamera3D();
68 ~XRCamera3D();
69 };
70
71 /*
72 XRNode3D is a helper node that implements binding to a tracker.
73
74 It must be a child node of our XROrigin node
75 */
76
77 class XRNode3D : public Node3D {
78 GDCLASS(XRNode3D, Node3D);
79
80 private:
81 StringName tracker_name;
82 StringName pose_name = SceneStringName(default_);
83 bool has_tracking_data = false;
84 bool show_when_tracked = false;
85
86 protected:
87 Ref<XRPositionalTracker> tracker;
88
89 static void _bind_methods();
90
91 virtual void _bind_tracker();
92 virtual void _unbind_tracker();
93 void _changed_tracker(const StringName &p_tracker_name, int p_tracker_type);
94 void _removed_tracker(const StringName &p_tracker_name, int p_tracker_type);
95
96 void _pose_changed(const Ref<XRPose> &p_pose);
97 void _pose_lost_tracking(const Ref<XRPose> &p_pose);
98 void _set_has_tracking_data(bool p_has_tracking_data);
99
100 void _update_visibility();
101 virtual void _physics_interpolated_changed() override;
102
103 public:
104 void _validate_property(PropertyInfo &p_property) const;
105 void set_tracker(const StringName &p_tracker_name);
106 StringName get_tracker() const;
107
108 void set_pose_name(const StringName &p_pose);
109 StringName get_pose_name() const;
110
111 bool get_is_active() const;
112 bool get_has_tracking_data() const;
113
114 void set_show_when_tracked(bool p_show);
115 bool get_show_when_tracked() const;
116
117 void trigger_haptic_pulse(const String &p_action_name, double p_frequency, double p_amplitude, double p_duration_sec, double p_delay_sec = 0);
118
119 Ref<XRPose> get_pose();
120
121 PackedStringArray get_configuration_warnings() const override;
122
123 XRNode3D();
124 ~XRNode3D();
125 };
126
127 /*
128 XRController3D is a helper node that automatically updates its position based on tracker data.
129
130 It must be a child node of our XROrigin node
131 */
132
133 class XRController3D : public XRNode3D {
134 GDCLASS(XRController3D, XRNode3D);
135
136 private:
137 protected:
138 static void _bind_methods();
139
140 virtual void _bind_tracker() override;
141 virtual void _unbind_tracker() override;
142
143 void _button_pressed(const String &p_name);
144 void _button_released(const String &p_name);
145 void _input_float_changed(const String &p_name, float p_value);
146 void _input_vector2_changed(const String &p_name, Vector2 p_value);
147 void _profile_changed(const String &p_role);
148
149 public:
150 bool is_button_pressed(const StringName &p_name) const;
151 Variant get_input(const StringName &p_name) const;
152 float get_float(const StringName &p_name) const;
153 Vector2 get_vector2(const StringName &p_name) const;
154
155 XRPositionalTracker::TrackerHand get_tracker_hand() const;
156 };
157
158 /*
159 XRAnchor3D is a helper node that automatically updates its position based on anchor data, it represents a real world location.
160 It must be a child node of our XROrigin3D node
161 */
162
163 class XRAnchor3D : public XRNode3D {
164 GDCLASS(XRAnchor3D, XRNode3D);
165
166 private:
167 Vector3 size;
168
169 protected:
170 static void _bind_methods();
171
172 public:
173 Vector3 get_size() const;
174 Plane get_plane() const;
175 };
176
177 /*
178 XROrigin3D is special spatial node that acts as our origin point mapping our real world center of our tracking volume into our virtual world.
179
180 It is this point that you will move around the world as the player 'moves while standing still', i.e. the player moves through teleporting or controller inputs as opposed to physically moving.
181
182 Our camera and controllers will always be child nodes and thus place relative to this origin point.
183 This node will automatically locate any camera child nodes and update its position while our XRController3D node will handle tracked controllers.
184 */
185
186 class XROrigin3D : public Node3D {
187 GDCLASS(XROrigin3D, Node3D);
188
189 private:
190 bool current = false;
191 static Vector<XROrigin3D *> origin_nodes; // all origin nodes in tree
192
193 void _set_current(bool p_enabled, bool p_update_others);
194
195 protected:
196 void _notification(int p_what);
197 static void _bind_methods();
198 virtual void _physics_interpolated_changed() override;
199
200 public:
201 PackedStringArray get_configuration_warnings() const override;
202
203 real_t get_world_scale() const;
204 void set_world_scale(real_t p_world_scale);
205
206 void set_current(bool p_enabled);
207 bool is_current() const;
208 };