2023-01-05 12:25:55 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* openxr_hand_tracking_extension.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2022-04-17 02:58:09 +00:00
|
|
|
|
|
|
|
#ifndef OPENXR_HAND_TRACKING_EXTENSION_H
|
|
|
|
#define OPENXR_HAND_TRACKING_EXTENSION_H
|
|
|
|
|
|
|
|
#include "../util.h"
|
2023-06-13 14:56:21 +00:00
|
|
|
#include "openxr_extension_wrapper.h"
|
2022-04-17 02:58:09 +00:00
|
|
|
|
|
|
|
#define MAX_OPENXR_TRACKED_HANDS 2
|
|
|
|
|
|
|
|
class OpenXRHandTrackingExtension : public OpenXRExtensionWrapper {
|
|
|
|
public:
|
|
|
|
struct HandTracker {
|
2022-11-01 14:29:38 +00:00
|
|
|
bool is_initialized = false;
|
2022-04-17 02:58:09 +00:00
|
|
|
XrHandJointsMotionRangeEXT motion_range = XR_HAND_JOINTS_MOTION_RANGE_UNOBSTRUCTED_EXT;
|
|
|
|
|
|
|
|
XrHandTrackerEXT hand_tracker = XR_NULL_HANDLE;
|
|
|
|
XrHandJointLocationEXT joint_locations[XR_HAND_JOINT_COUNT_EXT];
|
|
|
|
XrHandJointVelocityEXT joint_velocities[XR_HAND_JOINT_COUNT_EXT];
|
|
|
|
|
|
|
|
XrHandTrackingAimStateFB aimState;
|
|
|
|
XrHandJointVelocitiesEXT velocities;
|
|
|
|
XrHandJointLocationsEXT locations;
|
|
|
|
};
|
|
|
|
|
|
|
|
static OpenXRHandTrackingExtension *get_singleton();
|
|
|
|
|
2022-12-29 05:34:25 +00:00
|
|
|
OpenXRHandTrackingExtension();
|
2022-04-17 02:58:09 +00:00
|
|
|
virtual ~OpenXRHandTrackingExtension() override;
|
|
|
|
|
2022-12-29 05:34:25 +00:00
|
|
|
virtual HashMap<String, bool *> get_requested_extensions() override;
|
|
|
|
|
2022-04-17 02:58:09 +00:00
|
|
|
virtual void on_instance_created(const XrInstance p_instance) override;
|
|
|
|
virtual void on_instance_destroyed() override;
|
|
|
|
virtual void on_session_destroyed() override;
|
|
|
|
|
|
|
|
virtual void *set_system_properties_and_get_next_pointer(void *p_next_pointer) override;
|
|
|
|
virtual void on_state_ready() override;
|
|
|
|
virtual void on_process() override;
|
|
|
|
virtual void on_state_stopping() override;
|
|
|
|
|
|
|
|
bool get_active();
|
|
|
|
const HandTracker *get_hand_tracker(uint32_t p_hand) const;
|
|
|
|
|
|
|
|
XrHandJointsMotionRangeEXT get_motion_range(uint32_t p_hand) const;
|
|
|
|
void set_motion_range(uint32_t p_hand, XrHandJointsMotionRangeEXT p_motion_range);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static OpenXRHandTrackingExtension *singleton;
|
|
|
|
|
|
|
|
// state
|
|
|
|
XrSystemHandTrackingPropertiesEXT handTrackingSystemProperties;
|
|
|
|
HandTracker hand_trackers[MAX_OPENXR_TRACKED_HANDS]; // Fixed for left and right hand
|
|
|
|
|
|
|
|
// related extensions
|
|
|
|
bool hand_tracking_ext = false;
|
|
|
|
bool hand_motion_range_ext = false;
|
|
|
|
bool hand_tracking_aim_state_ext = false;
|
|
|
|
|
|
|
|
// functions
|
|
|
|
void cleanup_hand_tracking();
|
|
|
|
|
|
|
|
// OpenXR API call wrappers
|
|
|
|
EXT_PROTO_XRRESULT_FUNC3(xrCreateHandTrackerEXT, (XrSession), p_session, (const XrHandTrackerCreateInfoEXT *), p_createInfo, (XrHandTrackerEXT *), p_handTracker)
|
|
|
|
EXT_PROTO_XRRESULT_FUNC1(xrDestroyHandTrackerEXT, (XrHandTrackerEXT), p_handTracker)
|
|
|
|
EXT_PROTO_XRRESULT_FUNC3(xrLocateHandJointsEXT, (XrHandTrackerEXT), p_handTracker, (const XrHandJointsLocateInfoEXT *), p_locateInfo, (XrHandJointLocationsEXT *), p_locations)
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // OPENXR_HAND_TRACKING_EXTENSION_H
|