1 | /**************************************************************************/ |
2 | /* xr_positional_tracker.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 | #ifndef XR_POSITIONAL_TRACKER_H |
32 | #define XR_POSITIONAL_TRACKER_H |
33 | |
34 | #include "core/os/thread_safe.h" |
35 | #include "scene/resources/mesh.h" |
36 | #include "servers/xr/xr_pose.h" |
37 | #include "servers/xr_server.h" |
38 | |
39 | /** |
40 | The positional tracker object as an object that represents the position and orientation of a tracked object like a controller or headset. |
41 | An AR/VR Interface will registered the trackers it manages with our AR/VR server and update its position and orientation. |
42 | This is where potentially additional AR/VR interfaces may be active as there are AR/VR SDKs that solely deal with positional tracking. |
43 | */ |
44 | |
45 | class XRPositionalTracker : public RefCounted { |
46 | GDCLASS(XRPositionalTracker, RefCounted); |
47 | _THREAD_SAFE_CLASS_ |
48 | |
49 | public: |
50 | enum TrackerHand { |
51 | TRACKER_HAND_UNKNOWN, /* unknown or not applicable */ |
52 | TRACKER_HAND_LEFT, /* controller is the left hand controller */ |
53 | TRACKER_HAND_RIGHT /* controller is the right hand controller */ |
54 | }; |
55 | |
56 | private: |
57 | XRServer::TrackerType type; // type of tracker |
58 | StringName name; // (unique) name of the tracker |
59 | String description; // description of the tracker |
60 | String profile; // this is interface dependent, for OpenXR this will be the interaction profile bound for to the tracker |
61 | TrackerHand hand; // if known, the hand this tracker is held in |
62 | |
63 | HashMap<StringName, Ref<XRPose>> poses; |
64 | HashMap<StringName, Variant> inputs; |
65 | |
66 | protected: |
67 | static void _bind_methods(); |
68 | |
69 | public: |
70 | void set_tracker_type(XRServer::TrackerType p_type); |
71 | XRServer::TrackerType get_tracker_type() const; |
72 | void set_tracker_name(const StringName &p_name); |
73 | StringName get_tracker_name() const; |
74 | void set_tracker_desc(const String &p_desc); |
75 | String get_tracker_desc() const; |
76 | void set_tracker_profile(const String &p_profile); |
77 | String get_tracker_profile() const; |
78 | XRPositionalTracker::TrackerHand get_tracker_hand() const; |
79 | void set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand); |
80 | |
81 | bool has_pose(const StringName &p_action_name) const; |
82 | Ref<XRPose> get_pose(const StringName &p_action_name) const; |
83 | void invalidate_pose(const StringName &p_action_name); |
84 | void set_pose(const StringName &p_action_name, const Transform3D &p_transform, const Vector3 &p_linear_velocity, const Vector3 &p_angular_velocity, const XRPose::TrackingConfidence p_tracking_confidence = XRPose::XR_TRACKING_CONFIDENCE_HIGH); |
85 | |
86 | Variant get_input(const StringName &p_action_name) const; |
87 | void set_input(const StringName &p_action_name, const Variant &p_value); |
88 | |
89 | XRPositionalTracker(); |
90 | ~XRPositionalTracker() {} |
91 | }; |
92 | |
93 | VARIANT_ENUM_CAST(XRPositionalTracker::TrackerHand); |
94 | |
95 | #endif // XR_POSITIONAL_TRACKER_H |
96 | |