arvr_nodes.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /*************************************************************************/
  2. /* arvr_nodes.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. #include "arvr_nodes.h"
  31. #include "core/os/input.h"
  32. #include "servers/arvr/arvr_interface.h"
  33. #include "servers/arvr_server.h"
  34. ////////////////////////////////////////////////////////////////////////////////////////////////////
  35. void ARVRCamera::_notification(int p_what) {
  36. switch (p_what) {
  37. case NOTIFICATION_ENTER_TREE: {
  38. // need to find our ARVROrigin parent and let it know we're its camera!
  39. ARVROrigin *origin = Object::cast_to<ARVROrigin>(get_parent());
  40. if (origin != NULL) {
  41. origin->set_tracked_camera(this);
  42. }
  43. }; break;
  44. case NOTIFICATION_EXIT_TREE: {
  45. // need to find our ARVROrigin parent and let it know we're no longer its camera!
  46. ARVROrigin *origin = Object::cast_to<ARVROrigin>(get_parent());
  47. if (origin != NULL) {
  48. origin->clear_tracked_camera_if(this);
  49. }
  50. }; break;
  51. };
  52. };
  53. String ARVRCamera::get_configuration_warning() const {
  54. if (!is_visible() || !is_inside_tree())
  55. return String();
  56. // must be child node of ARVROrigin!
  57. ARVROrigin *origin = Object::cast_to<ARVROrigin>(get_parent());
  58. if (origin == NULL) {
  59. return TTR("ARVRCamera must have an ARVROrigin node as its parent");
  60. };
  61. return String();
  62. };
  63. Vector3 ARVRCamera::project_local_ray_normal(const Point2 &p_pos) const {
  64. // get our ARVRServer
  65. ARVRServer *arvr_server = ARVRServer::get_singleton();
  66. ERR_FAIL_NULL_V(arvr_server, Vector3());
  67. Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface();
  68. if (arvr_interface.is_null()) {
  69. // we might be in the editor or have VR turned off, just call superclass
  70. return Camera::project_local_ray_normal(p_pos);
  71. }
  72. if (!is_inside_tree()) {
  73. ERR_EXPLAIN("Camera is not inside scene.");
  74. ERR_FAIL_COND_V(!is_inside_tree(), Vector3());
  75. };
  76. Size2 viewport_size = get_viewport()->get_camera_rect_size();
  77. Vector2 cpos = get_viewport()->get_camera_coords(p_pos);
  78. Vector3 ray;
  79. CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar());
  80. float screen_w, screen_h;
  81. cm.get_viewport_size(screen_w, screen_h);
  82. ray = Vector3(((cpos.x / viewport_size.width) * 2.0 - 1.0) * screen_w, ((1.0 - (cpos.y / viewport_size.height)) * 2.0 - 1.0) * screen_h, -get_znear()).normalized();
  83. return ray;
  84. };
  85. Point2 ARVRCamera::unproject_position(const Vector3 &p_pos) const {
  86. // get our ARVRServer
  87. ARVRServer *arvr_server = ARVRServer::get_singleton();
  88. ERR_FAIL_NULL_V(arvr_server, Vector2());
  89. Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface();
  90. if (arvr_interface.is_null()) {
  91. // we might be in the editor or have VR turned off, just call superclass
  92. return Camera::unproject_position(p_pos);
  93. }
  94. if (!is_inside_tree()) {
  95. ERR_EXPLAIN("Camera is not inside scene.");
  96. ERR_FAIL_COND_V(!is_inside_tree(), Vector2());
  97. };
  98. Size2 viewport_size = get_viewport()->get_visible_rect().size;
  99. CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar());
  100. Plane p(get_camera_transform().xform_inv(p_pos), 1.0);
  101. p = cm.xform4(p);
  102. p.normal /= p.d;
  103. Point2 res;
  104. res.x = (p.normal.x * 0.5 + 0.5) * viewport_size.x;
  105. res.y = (-p.normal.y * 0.5 + 0.5) * viewport_size.y;
  106. return res;
  107. };
  108. Vector3 ARVRCamera::project_position(const Point2 &p_point) const {
  109. // get our ARVRServer
  110. ARVRServer *arvr_server = ARVRServer::get_singleton();
  111. ERR_FAIL_NULL_V(arvr_server, Vector3());
  112. Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface();
  113. if (arvr_interface.is_null()) {
  114. // we might be in the editor or have VR turned off, just call superclass
  115. return Camera::project_position(p_point);
  116. }
  117. if (!is_inside_tree()) {
  118. ERR_EXPLAIN("Camera is not inside scene.");
  119. ERR_FAIL_COND_V(!is_inside_tree(), Vector3());
  120. };
  121. Size2 viewport_size = get_viewport()->get_visible_rect().size;
  122. CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar());
  123. Size2 vp_size;
  124. cm.get_viewport_size(vp_size.x, vp_size.y);
  125. Vector2 point;
  126. point.x = (p_point.x / viewport_size.x) * 2.0 - 1.0;
  127. point.y = (1.0 - (p_point.y / viewport_size.y)) * 2.0 - 1.0;
  128. point *= vp_size;
  129. Vector3 p(point.x, point.y, -get_znear());
  130. return get_camera_transform().xform(p);
  131. };
  132. Vector<Plane> ARVRCamera::get_frustum() const {
  133. // get our ARVRServer
  134. ARVRServer *arvr_server = ARVRServer::get_singleton();
  135. ERR_FAIL_NULL_V(arvr_server, Vector<Plane>());
  136. Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface();
  137. if (arvr_interface.is_null()) {
  138. // we might be in the editor or have VR turned off, just call superclass
  139. return Camera::get_frustum();
  140. }
  141. ERR_FAIL_COND_V(!is_inside_world(), Vector<Plane>());
  142. Size2 viewport_size = get_viewport()->get_visible_rect().size;
  143. CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar());
  144. return cm.get_projection_planes(get_camera_transform());
  145. };
  146. ARVRCamera::ARVRCamera(){
  147. // nothing to do here yet for now..
  148. };
  149. ARVRCamera::~ARVRCamera(){
  150. // nothing to do here yet for now..
  151. };
  152. ////////////////////////////////////////////////////////////////////////////////////////////////////
  153. void ARVRController::_notification(int p_what) {
  154. switch (p_what) {
  155. case NOTIFICATION_ENTER_TREE: {
  156. set_process_internal(true);
  157. }; break;
  158. case NOTIFICATION_EXIT_TREE: {
  159. set_process_internal(false);
  160. }; break;
  161. case NOTIFICATION_INTERNAL_PROCESS: {
  162. // get our ARVRServer
  163. ARVRServer *arvr_server = ARVRServer::get_singleton();
  164. ERR_FAIL_NULL(arvr_server);
  165. // find the tracker for our controller
  166. ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id);
  167. if (tracker == NULL) {
  168. // this controller is currently turned off
  169. is_active = false;
  170. button_states = 0;
  171. } else {
  172. is_active = true;
  173. set_transform(tracker->get_transform(true));
  174. int joy_id = tracker->get_joy_id();
  175. if (joy_id >= 0) {
  176. int mask = 1;
  177. // check button states
  178. for (int i = 0; i < 16; i++) {
  179. bool was_pressed = (button_states & mask) == mask;
  180. bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, i);
  181. if (!was_pressed && is_pressed) {
  182. emit_signal("button_pressed", i);
  183. button_states += mask;
  184. } else if (was_pressed && !is_pressed) {
  185. emit_signal("button_release", i);
  186. button_states -= mask;
  187. };
  188. mask = mask << 1;
  189. };
  190. } else {
  191. button_states = 0;
  192. };
  193. };
  194. }; break;
  195. default:
  196. break;
  197. };
  198. };
  199. void ARVRController::_bind_methods() {
  200. ClassDB::bind_method(D_METHOD("set_controller_id", "controller_id"), &ARVRController::set_controller_id);
  201. ClassDB::bind_method(D_METHOD("get_controller_id"), &ARVRController::get_controller_id);
  202. ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_id", PROPERTY_HINT_RANGE, "0,32,1"), "set_controller_id", "get_controller_id");
  203. ClassDB::bind_method(D_METHOD("get_controller_name"), &ARVRController::get_controller_name);
  204. // passthroughs to information about our related joystick
  205. ClassDB::bind_method(D_METHOD("get_joystick_id"), &ARVRController::get_joystick_id);
  206. ClassDB::bind_method(D_METHOD("is_button_pressed", "button"), &ARVRController::is_button_pressed);
  207. ClassDB::bind_method(D_METHOD("get_joystick_axis", "axis"), &ARVRController::get_joystick_axis);
  208. ClassDB::bind_method(D_METHOD("get_is_active"), &ARVRController::get_is_active);
  209. ClassDB::bind_method(D_METHOD("get_hand"), &ARVRController::get_hand);
  210. ClassDB::bind_method(D_METHOD("get_rumble"), &ARVRController::get_rumble);
  211. ClassDB::bind_method(D_METHOD("set_rumble", "rumble"), &ARVRController::set_rumble);
  212. ADD_PROPERTY(PropertyInfo(Variant::REAL, "rumble", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_rumble", "get_rumble");
  213. ADD_SIGNAL(MethodInfo("button_pressed", PropertyInfo(Variant::INT, "button")));
  214. ADD_SIGNAL(MethodInfo("button_release", PropertyInfo(Variant::INT, "button")));
  215. };
  216. void ARVRController::set_controller_id(int p_controller_id) {
  217. // We don't check any bounds here, this controller may not yet be active and just be a place holder until it is.
  218. // Note that setting this to 0 means this node is not bound to a controller yet.
  219. controller_id = p_controller_id;
  220. update_configuration_warning();
  221. };
  222. int ARVRController::get_controller_id(void) const {
  223. return controller_id;
  224. };
  225. String ARVRController::get_controller_name(void) const {
  226. // get our ARVRServer
  227. ARVRServer *arvr_server = ARVRServer::get_singleton();
  228. ERR_FAIL_NULL_V(arvr_server, String());
  229. ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id);
  230. if (tracker == NULL) {
  231. return String("Not connected");
  232. };
  233. return tracker->get_name();
  234. };
  235. int ARVRController::get_joystick_id() const {
  236. // get our ARVRServer
  237. ARVRServer *arvr_server = ARVRServer::get_singleton();
  238. ERR_FAIL_NULL_V(arvr_server, 0);
  239. ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id);
  240. if (tracker == NULL) {
  241. return 0;
  242. };
  243. return tracker->get_joy_id();
  244. };
  245. int ARVRController::is_button_pressed(int p_button) const {
  246. int joy_id = get_joystick_id();
  247. if (joy_id == -1) {
  248. return false;
  249. };
  250. return Input::get_singleton()->is_joy_button_pressed(joy_id, p_button);
  251. };
  252. float ARVRController::get_joystick_axis(int p_axis) const {
  253. int joy_id = get_joystick_id();
  254. if (joy_id == -1) {
  255. return 0.0;
  256. };
  257. return Input::get_singleton()->get_joy_axis(joy_id, p_axis);
  258. };
  259. real_t ARVRController::get_rumble() const {
  260. // get our ARVRServer
  261. ARVRServer *arvr_server = ARVRServer::get_singleton();
  262. ERR_FAIL_NULL_V(arvr_server, 0.0);
  263. ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id);
  264. if (tracker == NULL) {
  265. return 0.0;
  266. };
  267. return tracker->get_rumble();
  268. };
  269. void ARVRController::set_rumble(real_t p_rumble) {
  270. // get our ARVRServer
  271. ARVRServer *arvr_server = ARVRServer::get_singleton();
  272. ERR_FAIL_NULL(arvr_server);
  273. ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id);
  274. if (tracker != NULL) {
  275. tracker->set_rumble(p_rumble);
  276. };
  277. };
  278. bool ARVRController::get_is_active() const {
  279. return is_active;
  280. };
  281. ARVRPositionalTracker::TrackerHand ARVRController::get_hand() const {
  282. // get our ARVRServer
  283. ARVRServer *arvr_server = ARVRServer::get_singleton();
  284. ERR_FAIL_NULL_V(arvr_server, ARVRPositionalTracker::TRACKER_HAND_UNKNOWN);
  285. ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id);
  286. if (tracker == NULL) {
  287. return ARVRPositionalTracker::TRACKER_HAND_UNKNOWN;
  288. };
  289. return tracker->get_hand();
  290. };
  291. String ARVRController::get_configuration_warning() const {
  292. if (!is_visible() || !is_inside_tree())
  293. return String();
  294. // must be child node of ARVROrigin!
  295. ARVROrigin *origin = Object::cast_to<ARVROrigin>(get_parent());
  296. if (origin == NULL) {
  297. return TTR("ARVRController must have an ARVROrigin node as its parent");
  298. };
  299. if (controller_id == 0) {
  300. return TTR("The controller id must not be 0 or this controller will not be bound to an actual controller");
  301. };
  302. return String();
  303. };
  304. ARVRController::ARVRController() {
  305. controller_id = 0;
  306. is_active = true;
  307. button_states = 0;
  308. };
  309. ARVRController::~ARVRController(){
  310. // nothing to do here yet for now..
  311. };
  312. ////////////////////////////////////////////////////////////////////////////////////////////////////
  313. void ARVRAnchor::_notification(int p_what) {
  314. switch (p_what) {
  315. case NOTIFICATION_ENTER_TREE: {
  316. set_process_internal(true);
  317. }; break;
  318. case NOTIFICATION_EXIT_TREE: {
  319. set_process_internal(false);
  320. }; break;
  321. case NOTIFICATION_INTERNAL_PROCESS: {
  322. // get our ARVRServer
  323. ARVRServer *arvr_server = ARVRServer::get_singleton();
  324. ERR_FAIL_NULL(arvr_server);
  325. // find the tracker for our anchor
  326. ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_ANCHOR, anchor_id);
  327. if (tracker == NULL) {
  328. // this anchor is currently not available
  329. is_active = false;
  330. } else {
  331. is_active = true;
  332. Transform transform;
  333. // we'll need our world_scale
  334. real_t world_scale = arvr_server->get_world_scale();
  335. // get our info from our tracker
  336. transform.basis = tracker->get_orientation();
  337. transform.origin = tracker->get_position(); // <-- already adjusted to world scale
  338. // our basis is scaled to the size of the plane the anchor is tracking
  339. // extract the size from our basis and reset the scale
  340. size = transform.basis.get_scale() * world_scale;
  341. transform.basis.orthonormalize();
  342. // apply our reference frame and set our transform
  343. set_transform(arvr_server->get_reference_frame() * transform);
  344. };
  345. }; break;
  346. default:
  347. break;
  348. };
  349. };
  350. void ARVRAnchor::_bind_methods() {
  351. ClassDB::bind_method(D_METHOD("set_anchor_id", "anchor_id"), &ARVRAnchor::set_anchor_id);
  352. ClassDB::bind_method(D_METHOD("get_anchor_id"), &ARVRAnchor::get_anchor_id);
  353. ADD_PROPERTY(PropertyInfo(Variant::INT, "anchor_id", PROPERTY_HINT_RANGE, "0,32,1"), "set_anchor_id", "get_anchor_id");
  354. ClassDB::bind_method(D_METHOD("get_anchor_name"), &ARVRAnchor::get_anchor_name);
  355. ClassDB::bind_method(D_METHOD("get_is_active"), &ARVRAnchor::get_is_active);
  356. ClassDB::bind_method(D_METHOD("get_size"), &ARVRAnchor::get_size);
  357. ClassDB::bind_method(D_METHOD("get_plane"), &ARVRAnchor::get_plane);
  358. };
  359. void ARVRAnchor::set_anchor_id(int p_anchor_id) {
  360. // We don't check any bounds here, this anchor may not yet be active and just be a place holder until it is.
  361. // Note that setting this to 0 means this node is not bound to an anchor yet.
  362. anchor_id = p_anchor_id;
  363. update_configuration_warning();
  364. };
  365. int ARVRAnchor::get_anchor_id(void) const {
  366. return anchor_id;
  367. };
  368. Vector3 ARVRAnchor::get_size() const {
  369. return size;
  370. };
  371. String ARVRAnchor::get_anchor_name(void) const {
  372. // get our ARVRServer
  373. ARVRServer *arvr_server = ARVRServer::get_singleton();
  374. ERR_FAIL_NULL_V(arvr_server, String());
  375. ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_ANCHOR, anchor_id);
  376. if (tracker == NULL) {
  377. return String("Not connected");
  378. };
  379. return tracker->get_name();
  380. };
  381. bool ARVRAnchor::get_is_active() const {
  382. return is_active;
  383. };
  384. String ARVRAnchor::get_configuration_warning() const {
  385. if (!is_visible() || !is_inside_tree())
  386. return String();
  387. // must be child node of ARVROrigin!
  388. ARVROrigin *origin = Object::cast_to<ARVROrigin>(get_parent());
  389. if (origin == NULL) {
  390. return TTR("ARVRAnchor must have an ARVROrigin node as its parent");
  391. };
  392. if (anchor_id == 0) {
  393. return TTR("The anchor id must not be 0 or this anchor will not be bound to an actual anchor");
  394. };
  395. return String();
  396. };
  397. Plane ARVRAnchor::get_plane() const {
  398. Vector3 location = get_translation();
  399. Basis orientation = get_transform().basis;
  400. Plane plane(location, orientation.get_axis(1).normalized());
  401. return plane;
  402. };
  403. ARVRAnchor::ARVRAnchor() {
  404. anchor_id = 0;
  405. is_active = true;
  406. };
  407. ARVRAnchor::~ARVRAnchor(){
  408. // nothing to do here yet for now..
  409. };
  410. ////////////////////////////////////////////////////////////////////////////////////////////////////
  411. String ARVROrigin::get_configuration_warning() const {
  412. if (!is_visible() || !is_inside_tree())
  413. return String();
  414. if (tracked_camera == NULL)
  415. return TTR("ARVROrigin requires an ARVRCamera child node");
  416. return String();
  417. };
  418. void ARVROrigin::_bind_methods() {
  419. ClassDB::bind_method(D_METHOD("set_world_scale", "world_scale"), &ARVROrigin::set_world_scale);
  420. ClassDB::bind_method(D_METHOD("get_world_scale"), &ARVROrigin::get_world_scale);
  421. ADD_PROPERTY(PropertyInfo(Variant::REAL, "world_scale"), "set_world_scale", "get_world_scale");
  422. };
  423. void ARVROrigin::set_tracked_camera(ARVRCamera *p_tracked_camera) {
  424. tracked_camera = p_tracked_camera;
  425. };
  426. void ARVROrigin::clear_tracked_camera_if(ARVRCamera *p_tracked_camera) {
  427. if (tracked_camera == p_tracked_camera) {
  428. tracked_camera = NULL;
  429. };
  430. };
  431. float ARVROrigin::get_world_scale() const {
  432. // get our ARVRServer
  433. ARVRServer *arvr_server = ARVRServer::get_singleton();
  434. ERR_FAIL_NULL_V(arvr_server, 1.0);
  435. return arvr_server->get_world_scale();
  436. };
  437. void ARVROrigin::set_world_scale(float p_world_scale) {
  438. // get our ARVRServer
  439. ARVRServer *arvr_server = ARVRServer::get_singleton();
  440. ERR_FAIL_NULL(arvr_server);
  441. arvr_server->set_world_scale(p_world_scale);
  442. };
  443. void ARVROrigin::_notification(int p_what) {
  444. switch (p_what) {
  445. case NOTIFICATION_ENTER_TREE: {
  446. set_process_internal(true);
  447. }; break;
  448. case NOTIFICATION_EXIT_TREE: {
  449. set_process_internal(false);
  450. }; break;
  451. case NOTIFICATION_INTERNAL_PROCESS: {
  452. // get our ARVRServer
  453. ARVRServer *arvr_server = ARVRServer::get_singleton();
  454. ERR_FAIL_NULL(arvr_server);
  455. // set our world origin to our node transform
  456. arvr_server->set_world_origin(get_global_transform());
  457. // check if we have a primary interface
  458. Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface();
  459. if (arvr_interface.is_valid() && tracked_camera != NULL) {
  460. // get our positioning transform for our headset
  461. Transform t = arvr_interface->get_transform_for_eye(ARVRInterface::EYE_MONO, Transform());
  462. // now apply this to our camera
  463. tracked_camera->set_transform(t);
  464. };
  465. }; break;
  466. default:
  467. break;
  468. };
  469. };
  470. ARVROrigin::ARVROrigin() {
  471. tracked_camera = NULL;
  472. };
  473. ARVROrigin::~ARVROrigin(){
  474. // nothing to do here yet for now..
  475. };