|
| 1 | +/**************************************************************************/ |
| 2 | +/* openxr_android_hit_result.cpp */ |
| 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 | +#include "classes/openxr_android_hit_result.h" |
| 32 | + |
| 33 | +#include <godot_cpp/variant/utility_functions.hpp> |
| 34 | + |
| 35 | +#include "extensions/openxr_android_trackables_extension.h" |
| 36 | + |
| 37 | +using namespace godot; |
| 38 | + |
| 39 | +OpenXRAndroidHitResult::OpenXRAndroidHitResult() {} |
| 40 | +OpenXRAndroidHitResult::~OpenXRAndroidHitResult() {} |
| 41 | + |
| 42 | +bool OpenXRAndroidHitResult::set_hit_result(const XrRaycastHitResultANDROID &p_hit_result) { |
| 43 | + switch ((int)p_hit_result.type) { |
| 44 | + case XR_TRACKABLE_TYPE_PLANE_ANDROID: { |
| 45 | + OpenXRAndroidTrackablesExtension *wrapper = OpenXRAndroidTrackablesExtension::get_singleton(); |
| 46 | + if (wrapper == nullptr) { |
| 47 | + UtilityFunctions::printerr("OpenXR: expected non-null OpenXRAndroidTrackablesExtension; returning null plane trackable"); |
| 48 | + trackable = Ref<OpenXRAndroidTracker>(); |
| 49 | + } else { |
| 50 | + // NOTE: don't bothing updating the tracker (if it already exists) since perhaps this |
| 51 | + // tracker's data is ultimately ignored by the caller. Like any other OpenXRAndroidTracker, |
| 52 | + // calling a getter function will ensure latest state if it's stale. |
| 53 | + trackable = wrapper->get_or_create_tracker_and_update(p_hit_result.trackable, XR_TRACKABLE_TYPE_PLANE_ANDROID, false); |
| 54 | + } |
| 55 | + break; |
| 56 | + } |
| 57 | + |
| 58 | + case XR_TRACKABLE_TYPE_DEPTH_ANDROID: |
| 59 | + // DEPTH hit results should not return a trackable |
| 60 | + if (p_hit_result.trackable != XR_NULL_TRACKABLE_ANDROID) { |
| 61 | + UtilityFunctions::print_verbose("OpenXR: unexpected trackable received for DEPTH hit result"); |
| 62 | + } |
| 63 | + |
| 64 | + trackable = Ref<OpenXRAndroidTracker>(); |
| 65 | + break; |
| 66 | + |
| 67 | + case XR_TRACKABLE_TYPE_NOT_VALID_ANDROID: |
| 68 | + case XR_TRACKABLE_TYPE_OBJECT_ANDROID: |
| 69 | + case XR_TRACKABLE_TYPE_MAX_ENUM_ANDROID: |
| 70 | + default: |
| 71 | + UtilityFunctions::printerr("OpenXR: unsupported hit trackable type: ", p_hit_result.type); |
| 72 | + return false; |
| 73 | + } |
| 74 | + |
| 75 | + pose.origin.x = p_hit_result.pose.position.x; |
| 76 | + pose.origin.y = p_hit_result.pose.position.y; |
| 77 | + pose.origin.z = p_hit_result.pose.position.z; |
| 78 | + pose.basis = Basis{ Quaternion{ p_hit_result.pose.orientation.x, p_hit_result.pose.orientation.y, p_hit_result.pose.orientation.z, p_hit_result.pose.orientation.w } }; |
| 79 | + |
| 80 | + return true; |
| 81 | +} |
| 82 | + |
| 83 | +Ref<OpenXRAndroidTracker> OpenXRAndroidHitResult::get_tracker() const { |
| 84 | + return trackable; |
| 85 | +} |
| 86 | + |
| 87 | +const Transform3D &OpenXRAndroidHitResult::get_pose() const { |
| 88 | + return pose; |
| 89 | +} |
| 90 | + |
| 91 | +void OpenXRAndroidHitResult::_bind_methods() { |
| 92 | + ClassDB::bind_method(D_METHOD("get_tracker"), &OpenXRAndroidHitResult::get_tracker); |
| 93 | + ClassDB::bind_method(D_METHOD("get_pose"), &OpenXRAndroidHitResult::get_pose); |
| 94 | +} |
0 commit comments