1 /*************************************************************************/ 2 /* arvr_nodes.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 ARVR_NODES_H 32 #define ARVR_NODES_H 33 34 #include "scene/3d/camera.h" 35 #include "scene/3d/spatial.h" 36 #include "scene/resources/mesh.h" 37 #include "servers/arvr/arvr_positional_tracker.h" 38 39 /** 40 @author Bastiaan Olij <mux213@gmail.com> 41 **/ 42 43 /* 44 ARVRCamera is a subclass of camera which will register itself with its parent ARVROrigin and as a result is automatically positioned 45 */ 46 class ARVRCamera : public Camera { 47 48 GDCLASS(ARVRCamera, Camera); 49 50 protected: 51 void _notification(int p_what); 52 53 public: 54 String get_configuration_warning() const; 55 56 virtual Vector3 project_local_ray_normal(const Point2 &p_pos) const; 57 virtual Point2 unproject_position(const Vector3 &p_pos) const; 58 virtual Vector3 project_position(const Point2 &p_point, float p_z_depth) const; 59 virtual Vector<Plane> get_frustum() const; 60 61 ARVRCamera(); 62 ~ARVRCamera(); 63 }; 64 65 /* 66 ARVRController is a helper node that automatically updates its position based on tracker data. 67 68 It must be a child node of our ARVROrigin node 69 */ 70 71 class ARVRController : public Spatial { 72 73 GDCLASS(ARVRController, Spatial); 74 75 private: 76 int controller_id; 77 bool is_active; 78 int button_states; 79 Ref<Mesh> mesh; 80 81 protected: 82 void _notification(int p_what); 83 static void _bind_methods(); 84 85 public: 86 void set_controller_id(int p_controller_id); 87 int get_controller_id(void) const; 88 String get_controller_name(void) const; 89 90 int get_joystick_id() const; 91 int is_button_pressed(int p_button) const; 92 float get_joystick_axis(int p_axis) const; 93 94 real_t get_rumble() const; 95 void set_rumble(real_t p_rumble); 96 97 bool get_is_active() const; 98 ARVRPositionalTracker::TrackerHand get_hand() const; 99 100 Ref<Mesh> get_mesh(void) const; 101 102 String get_configuration_warning() const; 103 104 ARVRController(); 105 ~ARVRController(); 106 }; 107 108 /* 109 ARVRAnchor is a helper node that automatically updates its position based on anchor data, it represents a real world location. 110 It must be a child node of our ARVROrigin node 111 */ 112 113 class ARVRAnchor : public Spatial { 114 GDCLASS(ARVRAnchor, Spatial); 115 116 private: 117 int anchor_id; 118 bool is_active; 119 Vector3 size; 120 Ref<Mesh> mesh; 121 122 protected: 123 void _notification(int p_what); 124 static void _bind_methods(); 125 126 public: 127 void set_anchor_id(int p_anchor_id); 128 int get_anchor_id(void) const; 129 String get_anchor_name(void) const; 130 131 bool get_is_active() const; 132 Vector3 get_size() const; 133 134 Plane get_plane() const; 135 136 Ref<Mesh> get_mesh(void) const; 137 138 String get_configuration_warning() const; 139 140 ARVRAnchor(); 141 ~ARVRAnchor(); 142 }; 143 144 /* 145 ARVROrigin is special spatial node that acts as our origin point mapping our real world center of our tracking volume into our virtual world. 146 147 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. 148 149 Our camera and controllers will always be child nodes and thus place relative to this origin point. 150 This node will automatically locate any camera child nodes and update its position while our ARVRController node will handle tracked controllers. 151 */ 152 class ARVROrigin : public Spatial { 153 154 GDCLASS(ARVROrigin, Spatial); 155 156 private: 157 ARVRCamera *tracked_camera; 158 159 protected: 160 void _notification(int p_what); 161 static void _bind_methods(); 162 163 public: 164 String get_configuration_warning() const; 165 166 void set_tracked_camera(ARVRCamera *p_tracked_camera); 167 void clear_tracked_camera_if(ARVRCamera *p_tracked_camera); 168 169 float get_world_scale() const; 170 void set_world_scale(float p_world_scale); 171 172 ARVROrigin(); 173 ~ARVROrigin(); 174 }; 175 176 #endif /* ARVR_NODES_H */ 177