spatial.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*************************************************************************/
  2. /* spatial.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 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. #include "scene/main/node.h"
  32. #include "scene/main/scene_main_loop.h"
  33. /**
  34. @author Juan Linietsky <[email protected]>
  35. */
  36. class SpatialGizmo : public Reference {
  37. OBJ_TYPE(SpatialGizmo,Reference);
  38. public:
  39. virtual void create()=0;
  40. virtual void transform()=0;
  41. virtual void redraw()=0;
  42. virtual void free()=0;
  43. SpatialGizmo();
  44. };
  45. class Spatial : public Node {
  46. OBJ_TYPE( Spatial, Node );
  47. OBJ_CATEGORY("3D");
  48. enum TransformDirty {
  49. DIRTY_NONE=0,
  50. DIRTY_VECTORS=1,
  51. DIRTY_LOCAL=2,
  52. DIRTY_GLOBAL=4
  53. };
  54. mutable SelfList<Node> xform_change;
  55. struct Data {
  56. mutable Transform global_transform;
  57. mutable Transform local_transform;
  58. mutable Vector3 rotation;
  59. mutable Vector3 scale;
  60. mutable int dirty;
  61. Viewport *viewport;
  62. bool toplevel_active;
  63. bool toplevel;
  64. bool inside_world;
  65. int children_lock;
  66. Spatial *parent;
  67. List<Spatial*> children;
  68. List<Spatial*>::Element *C;
  69. bool ignore_notification;
  70. bool visible;
  71. #ifdef TOOLS_ENABLED
  72. Ref<SpatialGizmo> gizmo;
  73. bool gizmo_disabled;
  74. bool gizmo_dirty;
  75. Transform import_transform;
  76. #endif
  77. } data;
  78. #ifdef TOOLS_ENABLED
  79. void _update_gizmo();
  80. #endif
  81. void _notify_dirty();
  82. void _propagate_transform_changed(Spatial *p_origin);
  83. void _set_rotation_deg(const Vector3& p_deg);
  84. Vector3 _get_rotation_deg() const;
  85. void _propagate_visibility_changed();
  86. protected:
  87. _FORCE_INLINE_ void set_ignore_transform_notification(bool p_ignore) { data.ignore_notification=p_ignore; }
  88. _FORCE_INLINE_ void _update_local_transform() const;
  89. void _notification(int p_what);
  90. static void _bind_methods();
  91. void _set_visible_(bool p_visible);
  92. bool _is_visible_() const;
  93. public:
  94. enum {
  95. NOTIFICATION_TRANSFORM_CHANGED=SceneMainLoop::NOTIFICATION_TRANSFORM_CHANGED,
  96. NOTIFICATION_ENTER_WORLD=41,
  97. NOTIFICATION_EXIT_WORLD=42,
  98. NOTIFICATION_VISIBILITY_CHANGED=43,
  99. };
  100. Spatial *get_parent_spatial() const;
  101. Ref<World> get_world() const;
  102. void set_translation(const Vector3& p_translation);
  103. void set_rotation(const Vector3& p_euler);
  104. void set_scale(const Vector3& p_scale);
  105. Vector3 get_translation() const;
  106. Vector3 get_rotation() const;
  107. Vector3 get_scale() const;
  108. void set_transform(const Transform& p_transform);
  109. void set_global_transform(const Transform& p_transform);
  110. Transform get_transform() const;
  111. Transform get_global_transform() const;
  112. void set_as_toplevel(bool p_enabled);
  113. bool is_set_as_toplevel() const;
  114. void set_disable_gizmo(bool p_enabled);
  115. void update_gizmo();
  116. void set_gizmo(const Ref<SpatialGizmo>& p_gizmo);
  117. Ref<SpatialGizmo> get_gizmo() const;
  118. _FORCE_INLINE_ bool is_inside_world() const { return data.inside_world; }
  119. Transform get_relative_transform(const Node *p_parent) const;
  120. void show();
  121. void hide();
  122. bool is_visible() const;
  123. bool is_hidden() const;
  124. #ifdef TOOLS_ENABLED
  125. void set_import_transform(const Transform& p_transform) ;
  126. Transform get_import_transform() const;
  127. #endif
  128. Spatial();
  129. ~Spatial();
  130. };
  131. #endif