xr_pose.cpp 5.6 KB

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