area.h
1 /*************************************************************************/
2 /* area.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef AREA_H
30 #define AREA_H
31 
32 #include "scene/3d/collision_object.h"
33 #include "vset.h"
34 
35 class Area : public CollisionObject {
36 
37  OBJ_TYPE( Area, CollisionObject );
38 public:
39 
40  enum SpaceOverride {
41  SPACE_OVERRIDE_DISABLED,
42  SPACE_OVERRIDE_COMBINE,
43  SPACE_OVERRIDE_COMBINE_REPLACE,
44  SPACE_OVERRIDE_REPLACE,
45  SPACE_OVERRIDE_REPLACE_COMBINE
46  };
47 private:
48 
49 
50  SpaceOverride space_override;
51  Vector3 gravity_vec;
52  real_t gravity;
53  bool gravity_is_point;
54  real_t gravity_distance_scale;
55  real_t angular_damp;
56  real_t linear_damp;
57  int priority;
58  bool monitoring;
59  bool monitorable;
60  bool locked;
61 
62 
63  void _body_inout(int p_status,const RID& p_body, int p_instance, int p_body_shape,int p_area_shape);
64 
65  void _body_enter_tree(ObjectID p_id);
66  void _body_exit_tree(ObjectID p_id);
67 
68  struct ShapePair {
69 
70  int body_shape;
71  int area_shape;
72  bool operator<(const ShapePair& p_sp) const {
73  if (body_shape==p_sp.body_shape)
74  return area_shape < p_sp.area_shape;
75  else
76  return body_shape < p_sp.body_shape;
77  }
78 
79  ShapePair() {}
80  ShapePair(int p_bs, int p_as) { body_shape=p_bs; area_shape=p_as; }
81  };
82 
83  struct BodyState {
84 
85  int rc;
86  bool in_tree;
87  VSet<ShapePair> shapes;
88  };
89 
90  Map<ObjectID,BodyState> body_map;
91 
92 
93  void _area_inout(int p_status,const RID& p_area, int p_instance, int p_area_shape,int p_self_shape);
94 
95  void _area_enter_tree(ObjectID p_id);
96  void _area_exit_tree(ObjectID p_id);
97 
98  struct AreaShapePair {
99 
100  int area_shape;
101  int self_shape;
102  bool operator<(const AreaShapePair& p_sp) const {
103  if (area_shape==p_sp.area_shape)
104  return self_shape < p_sp.self_shape;
105  else
106  return area_shape < p_sp.area_shape;
107  }
108 
109  AreaShapePair() {}
110  AreaShapePair(int p_bs, int p_as) { area_shape=p_bs; self_shape=p_as; }
111  };
112 
113  struct AreaState {
114 
115  int rc;
116  bool in_tree;
117  VSet<AreaShapePair> shapes;
118  };
119 
120  Map<ObjectID,AreaState> area_map;
121  void _clear_monitoring();
122 
123 
124 protected:
125 
126  void _notification(int p_what);
127  static void _bind_methods();
128 public:
129 
130  void set_space_override_mode(SpaceOverride p_mode);
131  SpaceOverride get_space_override_mode() const;
132 
133  void set_gravity_is_point(bool p_enabled);
134  bool is_gravity_a_point() const;
135 
136  void set_gravity_distance_scale(real_t p_scale);
137  real_t get_gravity_distance_scale() const;
138 
139  void set_gravity_vector(const Vector3& p_vec);
140  Vector3 get_gravity_vector() const;
141 
142  void set_gravity(real_t p_gravity);
143  real_t get_gravity() const;
144 
145  void set_angular_damp(real_t p_angular_damp);
146  real_t get_angular_damp() const;
147 
148  void set_linear_damp(real_t p_linear_damp);
149  real_t get_linear_damp() const;
150 
151  void set_priority(real_t p_priority);
152  real_t get_priority() const;
153 
154  void set_enable_monitoring(bool p_enable);
155  bool is_monitoring_enabled() const;
156 
157  void set_monitorable(bool p_enable);
158  bool is_monitorable() const;
159 
160  Array get_overlapping_bodies() const;
161  Array get_overlapping_areas() const; //function for script
162 
163  bool overlaps_area(Node* p_area) const;
164  bool overlaps_body(Node* p_body) const;
165 
166 
167  Area();
168  ~Area();
169 };
170 
171 VARIANT_ENUM_CAST(Area::SpaceOverride);
172 
173 #endif // AREA__H
Definition: array.h:38
Definition: node.h:42
Definition: vector3.h:38
Definition: rid.h:47
Definition: area.h:35
Definition: collision_object.h:35