world_boundary_shape_3d.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**************************************************************************/
  2. /* world_boundary_shape_3d.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 "world_boundary_shape_3d.h"
  31. #include "servers/physics_server_3d.h"
  32. Vector<Vector3> WorldBoundaryShape3D::get_debug_mesh_lines() const {
  33. Plane p = get_plane();
  34. Vector3 n1 = p.get_any_perpendicular_normal();
  35. Vector3 n2 = p.normal.cross(n1).normalized();
  36. Vector3 pface[4] = {
  37. p.normal * p.d + n1 * 10.0 + n2 * 10.0,
  38. p.normal * p.d + n1 * 10.0 + n2 * -10.0,
  39. p.normal * p.d + n1 * -10.0 + n2 * -10.0,
  40. p.normal * p.d + n1 * -10.0 + n2 * 10.0,
  41. };
  42. Vector<Vector3> points = {
  43. pface[0],
  44. pface[1],
  45. pface[1],
  46. pface[2],
  47. pface[2],
  48. pface[3],
  49. pface[3],
  50. pface[0],
  51. p.normal * p.d,
  52. p.normal * p.d + p.normal * 3
  53. };
  54. return points;
  55. }
  56. void WorldBoundaryShape3D::_update_shape() {
  57. PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), plane);
  58. Shape3D::_update_shape();
  59. }
  60. void WorldBoundaryShape3D::set_plane(const Plane &p_plane) {
  61. plane = p_plane;
  62. _update_shape();
  63. emit_changed();
  64. }
  65. const Plane &WorldBoundaryShape3D::get_plane() const {
  66. return plane;
  67. }
  68. void WorldBoundaryShape3D::_bind_methods() {
  69. ClassDB::bind_method(D_METHOD("set_plane", "plane"), &WorldBoundaryShape3D::set_plane);
  70. ClassDB::bind_method(D_METHOD("get_plane"), &WorldBoundaryShape3D::get_plane);
  71. ADD_PROPERTY(PropertyInfo(Variant::PLANE, "plane", PROPERTY_HINT_NONE, "suffix:m"), "set_plane", "get_plane");
  72. }
  73. WorldBoundaryShape3D::WorldBoundaryShape3D() :
  74. Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_WORLD_BOUNDARY)) {
  75. set_plane(Plane(0, 1, 0, 0));
  76. }