|
| 1 | +/**************************************************************************/ |
| 2 | +/* openxr_android_mouse_interaction_extension.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 "openxr_android_mouse_interaction_extension.h" |
| 32 | + |
| 33 | +#include "../action_map/openxr_interaction_profile_metadata.h" |
| 34 | +#include "core/config/project_settings.h" |
| 35 | + |
| 36 | +#include <openxr/openxr.h> |
| 37 | + |
| 38 | +OpenXRAndroidMouseInteractionExtension *OpenXRAndroidMouseInteractionExtension::singleton = nullptr; |
| 39 | + |
| 40 | +OpenXRAndroidMouseInteractionExtension *OpenXRAndroidMouseInteractionExtension::get_singleton() { |
| 41 | + return singleton; |
| 42 | +} |
| 43 | + |
| 44 | +OpenXRAndroidMouseInteractionExtension::OpenXRAndroidMouseInteractionExtension() { |
| 45 | + singleton = this; |
| 46 | +} |
| 47 | + |
| 48 | +OpenXRAndroidMouseInteractionExtension::~OpenXRAndroidMouseInteractionExtension() { |
| 49 | + singleton = nullptr; |
| 50 | +} |
| 51 | + |
| 52 | +HashMap<String, bool *> OpenXRAndroidMouseInteractionExtension::get_requested_extensions(XrVersion p_version) { |
| 53 | + HashMap<String, bool *> request_extensions; |
| 54 | + |
| 55 | + // Only enable this extension when requested. |
| 56 | + // We still register our meta data or the action map editor will fail. |
| 57 | + if (GLOBAL_GET("xr/openxr/extensions/androidxr/mouse_interaction_profile")) { |
| 58 | + request_extensions["XR_ANDROID_mouse_interaction"] = &available; |
| 59 | + } |
| 60 | + |
| 61 | + return request_extensions; |
| 62 | +} |
| 63 | + |
| 64 | +bool OpenXRAndroidMouseInteractionExtension::is_available() { |
| 65 | + return available; |
| 66 | +} |
| 67 | + |
| 68 | +void OpenXRAndroidMouseInteractionExtension::on_register_metadata() { |
| 69 | + OpenXRInteractionProfileMetadata *openxr_metadata = OpenXRInteractionProfileMetadata::get_singleton(); |
| 70 | + ERR_FAIL_NULL(openxr_metadata); |
| 71 | + |
| 72 | + // Mouse interaction profile. |
| 73 | + const String profile_path = "/interaction_profiles/android/mouse_interaction_android"; |
| 74 | + const String user_path = "/user/mouse"; |
| 75 | + openxr_metadata->register_interaction_profile("Android mouse interaction", profile_path, "XR_ANDROID_mouse_interaction"); |
| 76 | + |
| 77 | + openxr_metadata->register_io_path(profile_path, "Aim pose", user_path, user_path + "/input/aim/pose", "", OpenXRAction::OPENXR_ACTION_POSE); |
| 78 | + |
| 79 | + openxr_metadata->register_io_path(profile_path, "Select click", user_path, user_path + "/input/select/click", "", OpenXRAction::OPENXR_ACTION_BOOL); |
| 80 | + openxr_metadata->register_io_path(profile_path, "Secondary click", user_path, user_path + "/input/secondary_android/click", "", OpenXRAction::OPENXR_ACTION_BOOL); |
| 81 | + openxr_metadata->register_io_path(profile_path, "Tertiary click", user_path, user_path + "/input/tertiary_android/click", "", OpenXRAction::OPENXR_ACTION_BOOL); |
| 82 | + |
| 83 | + // openxr_metadata->register_io_path(profile_path, "Scroll", user_path, user_path + "/input/scroll_android/value", "", OpenXRAction::OPENXR_ACTION_FLOAT); |
| 84 | + openxr_metadata->register_io_path(profile_path, "Scroll", user_path, user_path + "/input/scroll_android", "", OpenXRAction::OPENXR_ACTION_VECTOR2); |
| 85 | +} |
0 commit comments