area.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*************************************************************************/
  2. /* area.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 AREA_H
  31. #define AREA_H
  32. #include "scene/3d/collision_object.h"
  33. #include "vset.h"
  34. class Area : public CollisionObject {
  35. OBJ_TYPE(Area, CollisionObject);
  36. public:
  37. enum SpaceOverride {
  38. SPACE_OVERRIDE_DISABLED,
  39. SPACE_OVERRIDE_COMBINE,
  40. SPACE_OVERRIDE_COMBINE_REPLACE,
  41. SPACE_OVERRIDE_REPLACE,
  42. SPACE_OVERRIDE_REPLACE_COMBINE
  43. };
  44. private:
  45. SpaceOverride space_override;
  46. Vector3 gravity_vec;
  47. real_t gravity;
  48. bool gravity_is_point;
  49. real_t gravity_distance_scale;
  50. real_t angular_damp;
  51. real_t linear_damp;
  52. uint32_t collision_mask;
  53. uint32_t layer_mask;
  54. int priority;
  55. bool monitoring;
  56. bool monitoring_stored;
  57. bool monitorable;
  58. bool locked;
  59. void _body_inout(int p_status, const RID &p_body, int p_instance, int p_body_shape, int p_area_shape);
  60. void _body_enter_tree(ObjectID p_id);
  61. void _body_exit_tree(ObjectID p_id);
  62. struct ShapePair {
  63. int body_shape;
  64. int area_shape;
  65. bool operator<(const ShapePair &p_sp) const {
  66. if (body_shape == p_sp.body_shape)
  67. return area_shape < p_sp.area_shape;
  68. else
  69. return body_shape < p_sp.body_shape;
  70. }
  71. ShapePair() {}
  72. ShapePair(int p_bs, int p_as) {
  73. body_shape = p_bs;
  74. area_shape = p_as;
  75. }
  76. };
  77. struct BodyState {
  78. int rc;
  79. bool in_tree;
  80. VSet<ShapePair> shapes;
  81. };
  82. Map<ObjectID, BodyState> body_map;
  83. void _area_inout(int p_status, const RID &p_area, int p_instance, int p_area_shape, int p_self_shape);
  84. void _area_enter_tree(ObjectID p_id);
  85. void _area_exit_tree(ObjectID p_id);
  86. struct AreaShapePair {
  87. int area_shape;
  88. int self_shape;
  89. bool operator<(const AreaShapePair &p_sp) const {
  90. if (area_shape == p_sp.area_shape)
  91. return self_shape < p_sp.self_shape;
  92. else
  93. return area_shape < p_sp.area_shape;
  94. }
  95. AreaShapePair() {}
  96. AreaShapePair(int p_bs, int p_as) {
  97. area_shape = p_bs;
  98. self_shape = p_as;
  99. }
  100. };
  101. struct AreaState {
  102. int rc;
  103. bool in_tree;
  104. VSet<AreaShapePair> shapes;
  105. };
  106. Map<ObjectID, AreaState> area_map;
  107. void _clear_monitoring();
  108. protected:
  109. void _notification(int p_what);
  110. static void _bind_methods();
  111. public:
  112. void set_space_override_mode(SpaceOverride p_mode);
  113. SpaceOverride get_space_override_mode() const;
  114. void set_gravity_is_point(bool p_enabled);
  115. bool is_gravity_a_point() const;
  116. void set_gravity_distance_scale(real_t p_scale);
  117. real_t get_gravity_distance_scale() const;
  118. void set_gravity_vector(const Vector3 &p_vec);
  119. Vector3 get_gravity_vector() const;
  120. void set_gravity(real_t p_gravity);
  121. real_t get_gravity() const;
  122. void set_angular_damp(real_t p_angular_damp);
  123. real_t get_angular_damp() const;
  124. void set_linear_damp(real_t p_linear_damp);
  125. real_t get_linear_damp() const;
  126. void set_priority(real_t p_priority);
  127. real_t get_priority() const;
  128. void set_enable_monitoring(bool p_enable);
  129. bool is_monitoring_enabled() const;
  130. void set_monitorable(bool p_enable);
  131. bool is_monitorable() const;
  132. void set_collision_mask(uint32_t p_mask);
  133. uint32_t get_collision_mask() const;
  134. void set_layer_mask(uint32_t p_mask);
  135. uint32_t get_layer_mask() const;
  136. void set_collision_mask_bit(int p_bit, bool p_value);
  137. bool get_collision_mask_bit(int p_bit) const;
  138. void set_layer_mask_bit(int p_bit, bool p_value);
  139. bool get_layer_mask_bit(int p_bit) const;
  140. Array get_overlapping_bodies() const;
  141. Array get_overlapping_areas() const; //function for script
  142. bool overlaps_area(Node *p_area) const;
  143. bool overlaps_body(Node *p_body) const;
  144. Area();
  145. ~Area();
  146. };
  147. VARIANT_ENUM_CAST(Area::SpaceOverride);
  148. #endif // AREA__H