collision_object.h
1 /*************************************************************************/
2 /* collision_object.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 COLLISION_OBJECT_H
30 #define COLLISION_OBJECT_H
31 
32 #include "scene/3d/spatial.h"
33 #include "scene/resources/shape.h"
34 
35 class CollisionObject : public Spatial {
36 
37  OBJ_TYPE( CollisionObject, Spatial );
38 
39  bool area;
40  RID rid;
41 
42  struct ShapeData {
43  Transform xform;
44  Ref<Shape> shape;
45  bool trigger;
46 
47  ShapeData() {
48  trigger=false;
49  }
50 
51  };
52 
53  bool capture_input_on_drag;
54  bool ray_pickable;
55  Vector<ShapeData> shapes;
56 
57  void _update_pickable();
58  void _update_shapes();
59 
60 friend class CollisionShape;
61 friend class CollisionPolygon;
62  void _update_shapes_from_children();
63 protected:
64 
65  CollisionObject(RID p_rid, bool p_area);
66 
67  void _notification(int p_what);
68  bool _set(const StringName& p_name, const Variant& p_value);
69  bool _get(const StringName& p_name,Variant &r_ret) const;
70  void _get_property_list( List<PropertyInfo> *p_list) const;
71  static void _bind_methods();
72 friend class Viewport;
73  virtual void _input_event(Node* p_camera,const InputEvent& p_input_event,const Vector3& p_pos, const Vector3& p_normal, int p_shape);
74  virtual void _mouse_enter();
75  virtual void _mouse_exit();
76 
77 public:
78 
79 
80  void add_shape(const Ref<Shape>& p_shape, const Transform& p_transform=Transform());
81  int get_shape_count() const;
82  void set_shape(int p_shape_idx, const Ref<Shape>& p_shape);
83  void set_shape_transform(int p_shape_idx, const Transform& p_transform);
84  Ref<Shape> get_shape(int p_shape_idx) const;
85  Transform get_shape_transform(int p_shape_idx) const;
86  void remove_shape(int p_shape_idx);
87  void clear_shapes();
88  void set_shape_as_trigger(int p_shape_idx, bool p_trigger);
89  bool is_shape_set_as_trigger(int p_shape_idx) const;
90 
91  void set_ray_pickable(bool p_ray_pickable);
92  bool is_ray_pickable() const;
93 
94  void set_capture_input_on_drag(bool p_capture);
95  bool get_capture_input_on_drag() const;
96 
97 
98  _FORCE_INLINE_ RID get_rid() const { return rid; }
99 
100  CollisionObject();
101  ~CollisionObject();
102 };
103 
104 #endif // COLLISION_OBJECT__H
Definition: viewport.h:75
Definition: variant.h:74
Definition: node.h:42
Definition: string_db.h:48
Definition: vector3.h:38
Definition: transform.h:38
Definition: input_event.h:263
Definition: rid.h:47
Definition: body_shape.h:35
Definition: collision_object.h:35
Definition: collision_polygon.h:9
Definition: spatial.h:56