collision_object_2d.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*************************************************************************/
  2. /* collision_object_2d.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. #ifndef COLLISION_OBJECT_2D_H
  31. #define COLLISION_OBJECT_2D_H
  32. #include "scene/2d/node_2d.h"
  33. #include "scene/resources/shape_2d.h"
  34. class CollisionObject2D : public Node2D {
  35. GDCLASS(CollisionObject2D, Node2D)
  36. bool area;
  37. RID rid;
  38. bool pickable;
  39. struct ShapeData {
  40. Object *owner;
  41. Transform2D xform;
  42. struct Shape {
  43. Ref<Shape2D> shape;
  44. int index;
  45. };
  46. Vector<Shape> shapes;
  47. bool disabled;
  48. bool one_way_collision;
  49. ShapeData() {
  50. disabled = false;
  51. one_way_collision = false;
  52. owner = NULL;
  53. }
  54. };
  55. int total_subshapes;
  56. Map<uint32_t, ShapeData> shapes;
  57. Transform2D last_transform;
  58. bool only_update_transform_changes; //this is used for sync physics in KinematicBody
  59. protected:
  60. CollisionObject2D(RID p_rid, bool p_area);
  61. void _notification(int p_what);
  62. static void _bind_methods();
  63. void _update_pickable();
  64. friend class Viewport;
  65. void _input_event(Node *p_viewport, const Ref<InputEvent> &p_input_event, int p_shape);
  66. void _mouse_enter();
  67. void _mouse_exit();
  68. void set_only_update_transform_changes(bool p_enable);
  69. public:
  70. uint32_t create_shape_owner(Object *p_owner);
  71. void remove_shape_owner(uint32_t owner);
  72. void get_shape_owners(List<uint32_t> *r_owners);
  73. Array _get_shape_owners();
  74. void shape_owner_set_transform(uint32_t p_owner, const Transform2D &p_transform);
  75. Transform2D shape_owner_get_transform(uint32_t p_owner) const;
  76. Object *shape_owner_get_owner(uint32_t p_owner) const;
  77. void shape_owner_set_disabled(uint32_t p_owner, bool p_disabled);
  78. bool is_shape_owner_disabled(uint32_t p_owner) const;
  79. void shape_owner_set_one_way_collision(uint32_t p_owner, bool p_enable);
  80. bool is_shape_owner_one_way_collision_enabled(uint32_t p_owner) const;
  81. void shape_owner_add_shape(uint32_t p_owner, const Ref<Shape2D> &p_shape);
  82. int shape_owner_get_shape_count(uint32_t p_owner) const;
  83. Ref<Shape2D> shape_owner_get_shape(uint32_t p_owner, int p_shape) const;
  84. int shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const;
  85. void shape_owner_remove_shape(uint32_t p_owner, int p_shape);
  86. void shape_owner_clear_shapes(uint32_t p_owner);
  87. uint32_t shape_find_owner(int p_shape_index) const;
  88. void set_pickable(bool p_enabled);
  89. bool is_pickable() const;
  90. String get_configuration_warning() const;
  91. _FORCE_INLINE_ RID get_rid() const { return rid; }
  92. CollisionObject2D();
  93. ~CollisionObject2D();
  94. };
  95. #endif // COLLISION_OBJECT_2D_H