collision_object.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*************************************************************************/
  2. /* collision_object.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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. OBJ_TYPE(CollisionObject, Spatial);
  36. bool area;
  37. RID rid;
  38. struct ShapeData {
  39. Transform xform;
  40. Ref<Shape> shape;
  41. bool trigger;
  42. ShapeData() {
  43. trigger = false;
  44. }
  45. };
  46. bool capture_input_on_drag;
  47. bool ray_pickable;
  48. Vector<ShapeData> shapes;
  49. void _update_pickable();
  50. void _update_shapes();
  51. friend class CollisionShape;
  52. friend class CollisionPolygon;
  53. void _update_shapes_from_children();
  54. protected:
  55. CollisionObject(RID p_rid, bool p_area);
  56. void _notification(int p_what);
  57. bool _set(const StringName &p_name, const Variant &p_value);
  58. bool _get(const StringName &p_name, Variant &r_ret) const;
  59. void _get_property_list(List<PropertyInfo> *p_list) const;
  60. static void _bind_methods();
  61. friend class Viewport;
  62. virtual void _input_event(Node *p_camera, const 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. void add_shape(const Ref<Shape> &p_shape, const Transform &p_transform = Transform());
  67. int get_shape_count() const;
  68. void set_shape(int p_shape_idx, const Ref<Shape> &p_shape);
  69. void set_shape_transform(int p_shape_idx, const Transform &p_transform);
  70. Ref<Shape> get_shape(int p_shape_idx) const;
  71. Transform get_shape_transform(int p_shape_idx) const;
  72. void remove_shape(int p_shape_idx);
  73. void clear_shapes();
  74. void set_shape_as_trigger(int p_shape_idx, bool p_trigger);
  75. bool is_shape_set_as_trigger(int p_shape_idx) const;
  76. void set_ray_pickable(bool p_ray_pickable);
  77. bool is_ray_pickable() const;
  78. void set_capture_input_on_drag(bool p_capture);
  79. bool get_capture_input_on_drag() const;
  80. _FORCE_INLINE_ RID get_rid() const { return rid; }
  81. CollisionObject();
  82. ~CollisionObject();
  83. };
  84. #endif // COLLISION_OBJECT__H