collision_object_2d.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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. protected:
  58. CollisionObject2D(RID p_rid, bool p_area);
  59. void _notification(int p_what);
  60. static void _bind_methods();
  61. void _update_pickable();
  62. friend class Viewport;
  63. void _input_event(Node *p_viewport, const Ref<InputEvent> &p_input_event, int p_shape);
  64. void _mouse_enter();
  65. void _mouse_exit();
  66. public:
  67. uint32_t create_shape_owner(Object *p_owner);
  68. void remove_shape_owner(uint32_t owner);
  69. void get_shape_owners(List<uint32_t> *r_owners);
  70. Array _get_shape_owners();
  71. void shape_owner_set_transform(uint32_t p_owner, const Transform2D &p_transform);
  72. Transform2D shape_owner_get_transform(uint32_t p_owner) const;
  73. Object *shape_owner_get_owner(uint32_t p_owner) const;
  74. void shape_owner_set_disabled(uint32_t p_owner, bool p_disabled);
  75. bool is_shape_owner_disabled(uint32_t p_owner) const;
  76. void shape_owner_set_one_way_collision(uint32_t p_owner, bool p_enable);
  77. bool is_shape_owner_one_way_collision_enabled(uint32_t p_owner) const;
  78. void shape_owner_add_shape(uint32_t p_owner, const Ref<Shape2D> &p_shape);
  79. int shape_owner_get_shape_count(uint32_t p_owner) const;
  80. Ref<Shape2D> shape_owner_get_shape(uint32_t p_owner, int p_shape) const;
  81. int shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const;
  82. void shape_owner_remove_shape(uint32_t p_owner, int p_shape);
  83. void shape_owner_clear_shapes(uint32_t p_owner);
  84. uint32_t shape_find_owner(int p_shape_index) const;
  85. void set_pickable(bool p_enabled);
  86. bool is_pickable() const;
  87. _FORCE_INLINE_ RID get_rid() const { return rid; }
  88. CollisionObject2D();
  89. ~CollisionObject2D();
  90. };
  91. #endif // COLLISION_OBJECT_2D_H