summaryrefslogtreecommitdiffstats
path: root/modules/openxr/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'modules/openxr/extensions')
-rw-r--r--modules/openxr/extensions/openxr_fb_passthrough_extension_wrapper.cpp2
-rw-r--r--modules/openxr/extensions/openxr_hand_tracking_extension.cpp59
-rw-r--r--modules/openxr/extensions/openxr_hand_tracking_extension.h8
3 files changed, 68 insertions, 1 deletions
diff --git a/modules/openxr/extensions/openxr_fb_passthrough_extension_wrapper.cpp b/modules/openxr/extensions/openxr_fb_passthrough_extension_wrapper.cpp
index f730f2bd2c..3da0ffd9c7 100644
--- a/modules/openxr/extensions/openxr_fb_passthrough_extension_wrapper.cpp
+++ b/modules/openxr/extensions/openxr_fb_passthrough_extension_wrapper.cpp
@@ -71,7 +71,7 @@ Viewport *OpenXRFbPassthroughExtensionWrapper::get_main_viewport() {
return nullptr;
}
- auto *scene_tree = Object::cast_to<SceneTree>(main_loop);
+ SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop);
if (!scene_tree) {
print_error("Unable to retrieve scene tree");
return nullptr;
diff --git a/modules/openxr/extensions/openxr_hand_tracking_extension.cpp b/modules/openxr/extensions/openxr_hand_tracking_extension.cpp
index 65559afed0..c92b2b08d0 100644
--- a/modules/openxr/extensions/openxr_hand_tracking_extension.cpp
+++ b/modules/openxr/extensions/openxr_hand_tracking_extension.cpp
@@ -276,3 +276,62 @@ void OpenXRHandTrackingExtension::set_motion_range(uint32_t p_hand, XrHandJoints
ERR_FAIL_UNSIGNED_INDEX(p_hand, MAX_OPENXR_TRACKED_HANDS);
hand_trackers[p_hand].motion_range = p_motion_range;
}
+
+Quaternion OpenXRHandTrackingExtension::get_hand_joint_rotation(uint32_t p_hand, XrHandJointEXT p_joint) const {
+ ERR_FAIL_UNSIGNED_INDEX_V(p_hand, MAX_OPENXR_TRACKED_HANDS, Quaternion());
+ ERR_FAIL_UNSIGNED_INDEX_V(p_joint, XR_HAND_JOINT_COUNT_EXT, Quaternion());
+
+ if (!hand_trackers[p_hand].is_initialized) {
+ return Quaternion();
+ }
+
+ const XrHandJointLocationEXT &location = hand_trackers[p_hand].joint_locations[p_joint];
+ return Quaternion(location.pose.orientation.x, location.pose.orientation.y, location.pose.orientation.z, location.pose.orientation.w);
+}
+
+Vector3 OpenXRHandTrackingExtension::get_hand_joint_position(uint32_t p_hand, XrHandJointEXT p_joint) const {
+ ERR_FAIL_UNSIGNED_INDEX_V(p_hand, MAX_OPENXR_TRACKED_HANDS, Vector3());
+ ERR_FAIL_UNSIGNED_INDEX_V(p_joint, XR_HAND_JOINT_COUNT_EXT, Vector3());
+
+ if (!hand_trackers[p_hand].is_initialized) {
+ return Vector3();
+ }
+
+ const XrHandJointLocationEXT &location = hand_trackers[p_hand].joint_locations[p_joint];
+ return Vector3(location.pose.position.x, location.pose.position.y, location.pose.position.z);
+}
+
+float OpenXRHandTrackingExtension::get_hand_joint_radius(uint32_t p_hand, XrHandJointEXT p_joint) const {
+ ERR_FAIL_UNSIGNED_INDEX_V(p_hand, MAX_OPENXR_TRACKED_HANDS, 0.0);
+ ERR_FAIL_UNSIGNED_INDEX_V(p_joint, XR_HAND_JOINT_COUNT_EXT, 0.0);
+
+ if (!hand_trackers[p_hand].is_initialized) {
+ return 0.0;
+ }
+
+ return hand_trackers[p_hand].joint_locations[p_joint].radius;
+}
+
+Vector3 OpenXRHandTrackingExtension::get_hand_joint_linear_velocity(uint32_t p_hand, XrHandJointEXT p_joint) const {
+ ERR_FAIL_UNSIGNED_INDEX_V(p_hand, MAX_OPENXR_TRACKED_HANDS, Vector3());
+ ERR_FAIL_UNSIGNED_INDEX_V(p_joint, XR_HAND_JOINT_COUNT_EXT, Vector3());
+
+ if (!hand_trackers[p_hand].is_initialized) {
+ return Vector3();
+ }
+
+ const XrHandJointVelocityEXT &velocity = hand_trackers[p_hand].joint_velocities[p_joint];
+ return Vector3(velocity.linearVelocity.x, velocity.linearVelocity.y, velocity.linearVelocity.z);
+}
+
+Vector3 OpenXRHandTrackingExtension::get_hand_joint_angular_velocity(uint32_t p_hand, XrHandJointEXT p_joint) const {
+ ERR_FAIL_UNSIGNED_INDEX_V(p_hand, MAX_OPENXR_TRACKED_HANDS, Vector3());
+ ERR_FAIL_UNSIGNED_INDEX_V(p_joint, XR_HAND_JOINT_COUNT_EXT, Vector3());
+
+ if (!hand_trackers[p_hand].is_initialized) {
+ return Vector3();
+ }
+
+ const XrHandJointVelocityEXT &velocity = hand_trackers[p_hand].joint_velocities[p_joint];
+ return Vector3(velocity.angularVelocity.x, velocity.angularVelocity.y, velocity.angularVelocity.z);
+}
diff --git a/modules/openxr/extensions/openxr_hand_tracking_extension.h b/modules/openxr/extensions/openxr_hand_tracking_extension.h
index e86831e71b..99d315c525 100644
--- a/modules/openxr/extensions/openxr_hand_tracking_extension.h
+++ b/modules/openxr/extensions/openxr_hand_tracking_extension.h
@@ -32,6 +32,7 @@
#define OPENXR_HAND_TRACKING_EXTENSION_H
#include "../util.h"
+#include "core/math/quaternion.h"
#include "openxr_extension_wrapper.h"
#define MAX_OPENXR_TRACKED_HANDS 2
@@ -73,6 +74,13 @@ public:
XrHandJointsMotionRangeEXT get_motion_range(uint32_t p_hand) const;
void set_motion_range(uint32_t p_hand, XrHandJointsMotionRangeEXT p_motion_range);
+ Quaternion get_hand_joint_rotation(uint32_t p_hand, XrHandJointEXT p_joint) const;
+ Vector3 get_hand_joint_position(uint32_t p_hand, XrHandJointEXT p_joint) const;
+ float get_hand_joint_radius(uint32_t p_hand, XrHandJointEXT p_joint) const;
+
+ Vector3 get_hand_joint_linear_velocity(uint32_t p_hand, XrHandJointEXT p_joint) const;
+ Vector3 get_hand_joint_angular_velocity(uint32_t p_hand, XrHandJointEXT p_joint) const;
+
private:
static OpenXRHandTrackingExtension *singleton;