collision_object.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /**************************************************************************/
  2. /* collision_object.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. #ifndef COLLISION_OBJECT_H
  31. #define COLLISION_OBJECT_H
  32. #include "scene/3d/spatial.h"
  33. #include "scene/resources/shape.h"
  34. class CollisionObject : public Spatial {
  35. GDCLASS(CollisionObject, Spatial);
  36. uint32_t collision_layer = 1;
  37. uint32_t collision_mask = 1;
  38. bool area;
  39. RID rid;
  40. struct ShapeData {
  41. ObjectID owner_id;
  42. Transform xform;
  43. struct ShapeBase {
  44. RID debug_shape;
  45. Ref<Shape> shape;
  46. int index;
  47. };
  48. Vector<ShapeBase> shapes;
  49. bool disabled;
  50. ShapeData() {
  51. disabled = false;
  52. owner_id = 0;
  53. }
  54. };
  55. int total_subshapes;
  56. Map<uint32_t, ShapeData> shapes;
  57. bool only_update_transform_changes = false; //this is used for sync physics in KinematicBody
  58. bool capture_input_on_drag;
  59. bool ray_pickable;
  60. Set<uint32_t> debug_shapes_to_update;
  61. int debug_shapes_count = 0;
  62. Transform debug_shape_old_transform;
  63. void _update_pickable();
  64. bool _are_collision_shapes_visible();
  65. void _update_shape_data(uint32_t p_owner);
  66. void _shape_changed(const Ref<Shape> &p_shape);
  67. void _update_debug_shapes();
  68. void _clear_debug_shapes();
  69. protected:
  70. CollisionObject(RID p_rid, bool p_area);
  71. void _notification(int p_what);
  72. static void _bind_methods();
  73. friend class Viewport;
  74. virtual void _input_event(Node *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape);
  75. virtual void _mouse_enter();
  76. virtual void _mouse_exit();
  77. void set_only_update_transform_changes(bool p_enable);
  78. void _on_transform_changed();
  79. public:
  80. void set_collision_layer(uint32_t p_layer);
  81. uint32_t get_collision_layer() const;
  82. void set_collision_mask(uint32_t p_mask);
  83. uint32_t get_collision_mask() const;
  84. void set_collision_layer_bit(int p_bit, bool p_value);
  85. bool get_collision_layer_bit(int p_bit) const;
  86. void set_collision_mask_bit(int p_bit, bool p_value);
  87. bool get_collision_mask_bit(int p_bit) const;
  88. uint32_t create_shape_owner(Object *p_owner);
  89. void remove_shape_owner(uint32_t owner);
  90. void get_shape_owners(List<uint32_t> *r_owners);
  91. Array _get_shape_owners();
  92. void shape_owner_set_transform(uint32_t p_owner, const Transform &p_transform);
  93. Transform shape_owner_get_transform(uint32_t p_owner) const;
  94. Object *shape_owner_get_owner(uint32_t p_owner) const;
  95. void shape_owner_set_disabled(uint32_t p_owner, bool p_disabled);
  96. bool is_shape_owner_disabled(uint32_t p_owner) const;
  97. void shape_owner_add_shape(uint32_t p_owner, const Ref<Shape> &p_shape);
  98. int shape_owner_get_shape_count(uint32_t p_owner) const;
  99. Ref<Shape> shape_owner_get_shape(uint32_t p_owner, int p_shape) const;
  100. int shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const;
  101. void shape_owner_remove_shape(uint32_t p_owner, int p_shape);
  102. void shape_owner_clear_shapes(uint32_t p_owner);
  103. uint32_t shape_find_owner(int p_shape_index) const;
  104. void set_ray_pickable(bool p_ray_pickable);
  105. bool is_ray_pickable() const;
  106. void set_capture_input_on_drag(bool p_capture);
  107. bool get_capture_input_on_drag() const;
  108. _FORCE_INLINE_ RID get_rid() const { return rid; }
  109. virtual String get_configuration_warning() const;
  110. CollisionObject();
  111. ~CollisionObject();
  112. };
  113. #endif // COLLISION_OBJECT_H