spatial.h
1 /*************************************************************************/
2 /* spatial.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 SPATIAL_H
30 #define SPATIAL_H
31 
32 #include "scene/main/node.h"
33 #include "scene/main/scene_main_loop.h"
34 
39 class SpatialGizmo : public Reference {
40 
41  OBJ_TYPE(SpatialGizmo,Reference);
42 
43 
44 public:
45 
46  virtual void create()=0;
47  virtual void transform()=0;
48  virtual void clear()=0;
49  virtual void redraw()=0;
50  virtual void free()=0;
51 
52  SpatialGizmo();
53 };
54 
55 
56 class Spatial : public Node {
57 
58  OBJ_TYPE( Spatial, Node );
59  OBJ_CATEGORY("3D");
60 
61  enum TransformDirty {
62  DIRTY_NONE=0,
63  DIRTY_VECTORS=1,
64  DIRTY_LOCAL=2,
65  DIRTY_GLOBAL=4
66  };
67 
68  mutable SelfList<Node> xform_change;
69 
70  struct Data {
71 
72 
73 
74  mutable Transform global_transform;
75  mutable Transform local_transform;
76  mutable Vector3 rotation;
77  mutable Vector3 scale;
78 
79  mutable int dirty;
80 
81  Viewport *viewport;
82 
83 
84  bool toplevel_active;
85  bool toplevel;
86  bool inside_world;
87 
88  int children_lock;
89  Spatial *parent;
90  List<Spatial*> children;
92 
93  bool ignore_notification;
94  bool notify_local_transform;
95 
96  bool visible;
97 
98 #ifdef TOOLS_ENABLED
99  Ref<SpatialGizmo> gizmo;
100  bool gizmo_disabled;
101  bool gizmo_dirty;
102  Transform import_transform;
103 #endif
104 
105  } data;
106 #ifdef TOOLS_ENABLED
107 
108  void _update_gizmo();
109 #endif
110  void _notify_dirty();
111  void _propagate_transform_changed(Spatial *p_origin);
112 
113  // Deprecated, should be removed in a future version.
114  void _set_rotation_deg(const Vector3& p_euler_deg);
115  Vector3 _get_rotation_deg() const;
116 
117  void _propagate_visibility_changed();
118 
119 
120 protected:
121 
122  _FORCE_INLINE_ void set_ignore_transform_notification(bool p_ignore) { data.ignore_notification=p_ignore; }
123 
124  _FORCE_INLINE_ void _update_local_transform() const;
125 
126  void _notification(int p_what);
127  static void _bind_methods();
128 
129  void _set_visible_(bool p_visible);
130  bool _is_visible_() const;
131 public:
132 
133  enum {
134 
135  NOTIFICATION_TRANSFORM_CHANGED=SceneTree::NOTIFICATION_TRANSFORM_CHANGED,
136  NOTIFICATION_ENTER_WORLD=41,
137  NOTIFICATION_EXIT_WORLD=42,
138  NOTIFICATION_VISIBILITY_CHANGED=43,
139  NOTIFICATION_LOCAL_TRANSFORM_CHANGED=44,
140  };
141 
142  Spatial *get_parent_spatial() const;
143 
144 
145  Ref<World> get_world() const;
146 
147  void set_translation(const Vector3& p_translation);
148  void set_rotation(const Vector3& p_euler_rad);
149  void set_rotation_deg(const Vector3& p_euler_deg);
150  void set_scale(const Vector3& p_scale);
151 
152  Vector3 get_translation() const;
153  Vector3 get_rotation() const;
154  Vector3 get_rotation_deg() const;
155  Vector3 get_scale() const;
156 
157  void set_transform(const Transform& p_transform);
158  void set_global_transform(const Transform& p_transform);
159 
160  Transform get_transform() const;
161  Transform get_global_transform() const;
162 
163  void set_as_toplevel(bool p_enabled);
164  bool is_set_as_toplevel() const;
165 
166  void set_disable_gizmo(bool p_enabled);
167  void update_gizmo();
168  void set_gizmo(const Ref<SpatialGizmo>& p_gizmo);
169  Ref<SpatialGizmo> get_gizmo() const;
170 
171  _FORCE_INLINE_ bool is_inside_world() const { return data.inside_world; }
172 
173  Transform get_relative_transform(const Node *p_parent) const;
174 
175  void rotate(const Vector3& p_normal,float p_radians);
176  void rotate_x(float p_radians);
177  void rotate_y(float p_radians);
178  void rotate_z(float p_radians);
179  void translate(const Vector3& p_offset);
180  void scale(const Vector3& p_ratio);
181  void global_rotate(const Vector3& p_normal,float p_radians);
182  void global_translate(const Vector3& p_offset);
183 
184  void look_at(const Vector3& p_target, const Vector3& p_up_normal);
185  void look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal);
186 
187  void set_notify_local_transform(bool p_enable);
188  bool is_local_transform_notification_enabled() const;
189 
190  void orthonormalize();
191  void set_identity();
192 
193  void show();
194  void hide();
195  bool is_visible() const;
196  bool is_hidden() const;
197  void set_hidden(bool p_hidden);
198 
199 #ifdef TOOLS_ENABLED
200  void set_import_transform(const Transform& p_transform) ;
201  Transform get_import_transform() const;
202 #endif
203 
204  Spatial();
205  ~Spatial();
206 
207 };
208 
209 #endif
Definition: reference.h:78
Definition: viewport.h:75
Definition: node.h:42
Definition: reference.h:40
Definition: vector3.h:38
Definition: transform.h:38
Definition: spatial.h:56
Definition: spatial.h:39