ray_shape_3d.cpp 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*************************************************************************/
  2. /* ray_shape_3d.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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 "ray_shape_3d.h"
  31. #include "servers/physics_server_3d.h"
  32. Vector<Vector3> RayShape3D::get_debug_mesh_lines() const {
  33. Vector<Vector3> points;
  34. points.push_back(Vector3());
  35. points.push_back(Vector3(0, 0, get_length()));
  36. return points;
  37. }
  38. real_t RayShape3D::get_enclosing_radius() const {
  39. return length;
  40. }
  41. void RayShape3D::_update_shape() {
  42. Dictionary d;
  43. d["length"] = length;
  44. d["slips_on_slope"] = slips_on_slope;
  45. PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), d);
  46. Shape3D::_update_shape();
  47. }
  48. void RayShape3D::set_length(float p_length) {
  49. length = p_length;
  50. _update_shape();
  51. notify_change_to_owners();
  52. }
  53. float RayShape3D::get_length() const {
  54. return length;
  55. }
  56. void RayShape3D::set_slips_on_slope(bool p_active) {
  57. slips_on_slope = p_active;
  58. _update_shape();
  59. notify_change_to_owners();
  60. }
  61. bool RayShape3D::get_slips_on_slope() const {
  62. return slips_on_slope;
  63. }
  64. void RayShape3D::_bind_methods() {
  65. ClassDB::bind_method(D_METHOD("set_length", "length"), &RayShape3D::set_length);
  66. ClassDB::bind_method(D_METHOD("get_length"), &RayShape3D::get_length);
  67. ClassDB::bind_method(D_METHOD("set_slips_on_slope", "active"), &RayShape3D::set_slips_on_slope);
  68. ClassDB::bind_method(D_METHOD("get_slips_on_slope"), &RayShape3D::get_slips_on_slope);
  69. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "length", PROPERTY_HINT_RANGE, "0,4096,0.001"), "set_length", "get_length");
  70. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "slips_on_slope"), "set_slips_on_slope", "get_slips_on_slope");
  71. }
  72. RayShape3D::RayShape3D() :
  73. Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_RAY)) {
  74. /* Code copied from setters to prevent the use of uninitialized variables */
  75. _update_shape();
  76. notify_change_to_owners();
  77. }