1 | /**************************************************************************/ |
2 | /* xr_pose.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 "xr_pose.h" |
32 | |
33 | #include "servers/xr_server.h" |
34 | |
35 | void XRPose::_bind_methods() { |
36 | BIND_ENUM_CONSTANT(XR_TRACKING_CONFIDENCE_NONE); |
37 | BIND_ENUM_CONSTANT(XR_TRACKING_CONFIDENCE_LOW); |
38 | BIND_ENUM_CONSTANT(XR_TRACKING_CONFIDENCE_HIGH); |
39 | |
40 | ClassDB::bind_method(D_METHOD("set_has_tracking_data" , "has_tracking_data" ), &XRPose::set_has_tracking_data); |
41 | ClassDB::bind_method(D_METHOD("get_has_tracking_data" ), &XRPose::get_has_tracking_data); |
42 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "has_tracking_data" ), "set_has_tracking_data" , "get_has_tracking_data" ); |
43 | |
44 | ClassDB::bind_method(D_METHOD("set_name" , "name" ), &XRPose::set_name); |
45 | ClassDB::bind_method(D_METHOD("get_name" ), &XRPose::get_name); |
46 | ADD_PROPERTY(PropertyInfo(Variant::STRING, "name" ), "set_name" , "get_name" ); |
47 | |
48 | ClassDB::bind_method(D_METHOD("set_transform" , "transform" ), &XRPose::set_transform); |
49 | ClassDB::bind_method(D_METHOD("get_transform" ), &XRPose::get_transform); |
50 | ADD_PROPERTY(PropertyInfo(Variant::STRING, "transform" ), "set_transform" , "get_transform" ); |
51 | ClassDB::bind_method(D_METHOD("get_adjusted_transform" ), &XRPose::get_adjusted_transform); |
52 | |
53 | ClassDB::bind_method(D_METHOD("set_linear_velocity" , "velocity" ), &XRPose::set_linear_velocity); |
54 | ClassDB::bind_method(D_METHOD("get_linear_velocity" ), &XRPose::get_linear_velocity); |
55 | ADD_PROPERTY(PropertyInfo(Variant::STRING, "linear_velocity" ), "set_linear_velocity" , "get_linear_velocity" ); |
56 | |
57 | ClassDB::bind_method(D_METHOD("set_angular_velocity" , "velocity" ), &XRPose::set_angular_velocity); |
58 | ClassDB::bind_method(D_METHOD("get_angular_velocity" ), &XRPose::get_angular_velocity); |
59 | ADD_PROPERTY(PropertyInfo(Variant::STRING, "angular_velocity" ), "set_angular_velocity" , "get_angular_velocity" ); |
60 | |
61 | ClassDB::bind_method(D_METHOD("set_tracking_confidence" , "tracking_confidence" ), &XRPose::set_tracking_confidence); |
62 | ClassDB::bind_method(D_METHOD("get_tracking_confidence" ), &XRPose::get_tracking_confidence); |
63 | ADD_PROPERTY(PropertyInfo(Variant::INT, "tracking_confidence" ), "set_tracking_confidence" , "get_tracking_confidence" ); |
64 | } |
65 | |
66 | void XRPose::set_has_tracking_data(const bool p_has_tracking_data) { |
67 | has_tracking_data = p_has_tracking_data; |
68 | } |
69 | bool XRPose::get_has_tracking_data() const { |
70 | return has_tracking_data; |
71 | } |
72 | |
73 | void XRPose::set_name(const StringName &p_name) { |
74 | name = p_name; |
75 | } |
76 | |
77 | StringName XRPose::get_name() const { |
78 | return name; |
79 | } |
80 | |
81 | void XRPose::set_transform(const Transform3D p_transform) { |
82 | transform = p_transform; |
83 | } |
84 | |
85 | Transform3D XRPose::get_transform() const { |
86 | return transform; |
87 | } |
88 | |
89 | Transform3D XRPose::get_adjusted_transform() const { |
90 | Transform3D adjusted_transform = transform; |
91 | |
92 | XRServer *xr_server = XRServer::get_singleton(); |
93 | ERR_FAIL_NULL_V(xr_server, transform); |
94 | |
95 | // apply world scale |
96 | adjusted_transform.origin *= xr_server->get_world_scale(); |
97 | |
98 | // apply reference frame |
99 | adjusted_transform = xr_server->get_reference_frame() * adjusted_transform; |
100 | |
101 | return adjusted_transform; |
102 | } |
103 | |
104 | void XRPose::set_linear_velocity(const Vector3 p_velocity) { |
105 | linear_velocity = p_velocity; |
106 | } |
107 | |
108 | Vector3 XRPose::get_linear_velocity() const { |
109 | return linear_velocity; |
110 | } |
111 | |
112 | void XRPose::set_angular_velocity(const Vector3 p_velocity) { |
113 | angular_velocity = p_velocity; |
114 | } |
115 | |
116 | Vector3 XRPose::get_angular_velocity() const { |
117 | return angular_velocity; |
118 | } |
119 | |
120 | void XRPose::set_tracking_confidence(const XRPose::TrackingConfidence p_tracking_confidence) { |
121 | tracking_confidence = p_tracking_confidence; |
122 | } |
123 | |
124 | XRPose::TrackingConfidence XRPose::get_tracking_confidence() const { |
125 | return tracking_confidence; |
126 | } |
127 | |