|
| 1 | +/**************************************************************************/ |
| 2 | +/* visionos_controller_tracking.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 | +#ifdef VISIONOS_ENABLED |
| 34 | + |
| 35 | +#include "visionos_definitions.h" |
| 36 | + |
| 37 | +#ifdef __OBJC__ |
| 38 | +#define Key GodotKey |
| 39 | +#import <CoreHaptics/CoreHaptics.h> |
| 40 | +#import <GameController/GameController.h> |
| 41 | +#undef Key |
| 42 | +#else // __OBJC__ |
| 43 | +typedef struct GCController *GCController_t; |
| 44 | +typedef struct CHHapticEngine *CHHapticEngine_t; |
| 45 | +#endif // __OBJC__ |
| 46 | + |
| 47 | +class VisionOSXRInterface; |
| 48 | + |
| 49 | +// Controller tracking using ARKit and GCController |
| 50 | +struct VisionOSControllerTracking { |
| 51 | + bool enabled = false; |
| 52 | + VisionOSAuthorizationStatus authorization = VisionOSAuthorizationStatus::NOT_DETERMINED; |
| 53 | + |
| 54 | + bool active() const { return enabled && authorization == VisionOSAuthorizationStatus::ALLOWED; } |
| 55 | + |
| 56 | + // ARKit state |
| 57 | + ar_accessory_tracking_provider_t accessory_tracking_provider = nullptr; |
| 58 | + ar_accessories_t accessories = nullptr; |
| 59 | + ar_accessory_anchor_t left_controller_anchor = nullptr; |
| 60 | + ar_accessory_anchor_t right_controller_anchor = nullptr; |
| 61 | + |
| 62 | + // Controller state |
| 63 | + Ref<XRControllerTracker> left_controller_tracker; |
| 64 | + Ref<XRControllerTracker> right_controller_tracker; |
| 65 | + GCController *left_gc_controller = nullptr; |
| 66 | + GCController *right_gc_controller = nullptr; |
| 67 | + CHHapticEngine *left_haptic_engine = nullptr; |
| 68 | + CHHapticEngine *right_haptic_engine = nullptr; |
| 69 | + |
| 70 | + // Notification observers |
| 71 | + id controller_observer = nullptr; |
| 72 | + id controller_disconnect_observer = nullptr; |
| 73 | + |
| 74 | + void initialize(XRServer *p_xr_server, VisionOSXRInterface *p_xr_interface); |
| 75 | + void uninitialize(XRServer *p_xr_server); |
| 76 | + |
| 77 | + void init_for_controller(GCController *p_controller); |
| 78 | + void setup_controller_notifications(); |
| 79 | + void cleanup_controller_notifications(); |
| 80 | + void handle_controller_disconnect(GCController *p_controller); |
| 81 | + void update_accessories_list(); |
| 82 | + void update_controller_trackers_from_arkit(CFTimeInterval p_trackable_anchor_time); |
| 83 | + void update_controller_from_anchor(Ref<XRControllerTracker> p_controller_tracker, ar_accessory_anchor_t p_controller_anchor, GCController *p_gc_controller); |
| 84 | + |
| 85 | + // Called directly from the same function on the XRInterface |
| 86 | + void trigger_haptic_pulse(const String &p_action_name, const StringName &p_tracker_name, double p_frequency, double p_amplitude, double p_duration_sec, double p_delay_sec); |
| 87 | + |
| 88 | + VisionOSXRInterface *xr_interface = nullptr; // assigned on initialization |
| 89 | +}; |
| 90 | + |
| 91 | +#endif // VISIONOS_ENABLED |
0 commit comments