collision_object.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*************************************************************************/
  2. /* collision_object.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_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. bool area;
  37. RID rid;
  38. struct ShapeData {
  39. Object *owner;
  40. Transform xform;
  41. struct ShapeBase {
  42. Ref<Shape> shape;
  43. int index;
  44. };
  45. Vector<ShapeBase> shapes;
  46. bool disabled;
  47. ShapeData() {
  48. disabled = false;
  49. owner = NULL;
  50. }
  51. };
  52. int total_subshapes;
  53. Map<uint32_t, ShapeData> shapes;
  54. bool capture_input_on_drag;
  55. bool ray_pickable;
  56. void _update_pickable();
  57. protected:
  58. CollisionObject(RID p_rid, bool p_area);
  59. void _notification(int p_what);
  60. static void _bind_methods();
  61. friend class Viewport;
  62. virtual void _input_event(Node *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape);
  63. virtual void _mouse_enter();
  64. virtual void _mouse_exit();
  65. public:
  66. uint32_t create_shape_owner(Object *p_owner);
  67. void remove_shape_owner(uint32_t owner);
  68. void get_shape_owners(List<uint32_t> *r_owners);
  69. Array _get_shape_owners();
  70. void shape_owner_set_transform(uint32_t p_owner, const Transform &p_transform);
  71. Transform shape_owner_get_transform(uint32_t p_owner) const;
  72. Object *shape_owner_get_owner(uint32_t p_owner) const;
  73. void shape_owner_set_disabled(uint32_t p_owner, bool p_disabled);
  74. bool is_shape_owner_disabled(uint32_t p_owner) const;
  75. void shape_owner_add_shape(uint32_t p_owner, const Ref<Shape> &p_shape);
  76. int shape_owner_get_shape_count(uint32_t p_owner) const;
  77. Ref<Shape> shape_owner_get_shape(uint32_t p_owner, int p_shape) const;
  78. int shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const;
  79. void shape_owner_remove_shape(uint32_t p_owner, int p_shape);
  80. void shape_owner_clear_shapes(uint32_t p_owner);
  81. uint32_t shape_find_owner(int p_shape_index) const;
  82. void set_ray_pickable(bool p_ray_pickable);
  83. bool is_ray_pickable() const;
  84. void set_capture_input_on_drag(bool p_capture);
  85. bool get_capture_input_on_drag() const;
  86. _FORCE_INLINE_ RID get_rid() const { return rid; }
  87. virtual String get_configuration_warning() const;
  88. CollisionObject();
  89. ~CollisionObject();
  90. };
  91. #endif // COLLISION_OBJECT__H