Node.pkg 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. $#include "Node.h"
  2. /// Component and child node creation mode for networking.
  3. enum CreateMode
  4. {
  5. REPLICATED = 0,
  6. LOCAL = 1
  7. };
  8. /// %Scene node that may contain components and child nodes.
  9. class Node
  10. {
  11. public:
  12. /// Set name.
  13. void SetName(const String& name);
  14. /// Set position relative to parent node.
  15. void SetPosition(const Vector3& position);
  16. /// Set rotation relative to parent node.
  17. void SetRotation(const Quaternion& rotation);
  18. /// Set direction relative to parent node. Positive Z equals identity.
  19. void SetDirection(const Vector3& direction);
  20. /// Set uniform scale relative to parent node.
  21. void SetScale(float scale);
  22. /// Set scale relative to parent node.
  23. void SetScale(const Vector3& scale);
  24. /// Set transform relative to parent node.
  25. void SetTransform(const Vector3& position, const Quaternion& rotation);
  26. /// Set transform relative to parent node.
  27. void SetTransform(const Vector3& position, const Quaternion& rotation, float scale);
  28. /// Set transform relative to parent node.
  29. void SetTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale);
  30. /// Set position relative to world space.
  31. void SetWorldPosition(const Vector3& position);
  32. /// Set rotation relative to world space.
  33. void SetWorldRotation(const Quaternion& rotation);
  34. /// Set direction relative to world space.
  35. void SetWorldDirection(const Vector3& direction);
  36. /// Set uniform scale relative to world space.
  37. void SetWorldScale(float scale);
  38. /// Set scale relative to world space.
  39. void SetWorldScale(const Vector3& scale);
  40. /// Set transform relative to world space.
  41. void SetWorldTransform(const Vector3& position, const Quaternion& rotation);
  42. /// Set transform relative to world space.
  43. void SetWorldTransform(const Vector3& position, const Quaternion& rotation, float scale);
  44. /// Set transform relative to world space.
  45. void SetWorldTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale);
  46. /// Move the scene node.
  47. void Translate(const Vector3& delta);
  48. /// Move the scene node relative to its rotation.
  49. void TranslateRelative(const Vector3& delta);
  50. /// Rotate the scene node.
  51. void Rotate(const Quaternion& delta, bool fixedAxis = false);
  52. /// Rotate around the X axis.
  53. void Pitch(float angle, bool fixedAxis = false);
  54. /// Rotate around the Y axis.
  55. void Yaw(float angle, bool fixedAxis = false);
  56. /// Rotate around the Z axis.
  57. void Roll(float angle, bool fixedAxis = false);
  58. /// Look at a target world position.
  59. void LookAt(const Vector3& target, const Vector3& upAxis = Vector3::UP);
  60. /// Modify scale uniformly.
  61. void Scale(float scale);
  62. /// Modify scale.
  63. void Scale(const Vector3& scale);
  64. /// Set enabled/disabled state without recursion. Components in a disabled node become effectively disabled regardless of their own enable/disable state.
  65. void SetEnabled(bool enable);
  66. /// Set enabled/disabled state with optional recursion.
  67. void SetEnabled(bool enable, bool recursive);
  68. /// Set owner connection for networking.
  69. void SetOwner(Connection* owner);
  70. /// Mark node and child nodes to need world transform recalculation. Notify listener components.
  71. void MarkDirty();
  72. /// Create a child scene node (with specified ID if provided).
  73. Node* CreateChild(const String& name = String::EMPTY, CreateMode mode = REPLICATED, unsigned id = 0);
  74. /// Add a child scene node.
  75. void AddChild(Node* node);
  76. /// Remove a child scene node.
  77. void RemoveChild(Node* node);
  78. /// Remove all child scene nodes.
  79. void RemoveAllChildren();
  80. /// Create a component to this node (with specified ID if provided).
  81. Component* CreateComponent(ShortStringHash type, CreateMode mode = REPLICATED, unsigned id = 0);
  82. /// Create a component to this node if it does not exist already.
  83. Component* GetOrCreateComponent(ShortStringHash type, CreateMode mode = REPLICATED, unsigned id = 0);
  84. /// Remove a component from this node.
  85. void RemoveComponent(Component* component);
  86. /// Remove the first component of specific type from this node.
  87. void RemoveComponent(ShortStringHash type);
  88. /// Remove all components from this node.
  89. void RemoveAllComponents();
  90. /// Clone scene node, components and child nodes. Return the clone.
  91. Node* Clone(CreateMode mode = REPLICATED);
  92. /// Remove from the parent node. If no other shared pointer references exist, causes immediate deletion.
  93. void Remove();
  94. /// Set parent scene node. Retains the world transform.
  95. void SetParent(Node* parent);
  96. /// Set a user variable.
  97. void SetVar(ShortStringHash key, const Variant& value);
  98. /// Add listener component that is notified of node being dirtied. Can either be in the same node or another.
  99. void AddListener(Component* component);
  100. /// Remove listener component.
  101. void RemoveListener(Component* component);
  102. /// Return ID.
  103. unsigned GetID() const;
  104. /// Return name.
  105. const String& GetName() const;
  106. /// Return name hash.
  107. StringHash GetNameHash() const;
  108. /// Return parent scene node.
  109. Node* GetParent() const;
  110. /// Return scene.
  111. Scene* GetScene() const;
  112. /// Return whether is enabled. Disables nodes effectively disable all their components.
  113. bool IsEnabled() const;
  114. /// Return owner connection in networking.
  115. Connection* GetOwner() const;
  116. /// Return position relative to parent node.
  117. const Vector3& GetPosition() const;
  118. /// Return rotation relative to parent node.
  119. const Quaternion& GetRotation() const;
  120. /// Return direction relative to parent node. Identity rotation equals positive Z.
  121. Vector3 GetDirection() const;
  122. /// Return scale relative to parent node.
  123. const Vector3& GetScale() const;
  124. /// Return transform matrix relative to parent node.
  125. Matrix3x4 GetTransform() const;
  126. /// Return position in world space.
  127. Vector3 GetWorldPosition() const;
  128. /// Return rotation in world space.
  129. Quaternion GetWorldRotation() const;
  130. /// Return direction in world space.
  131. Vector3 GetWorldDirection() const;
  132. /// Return scale in world space.
  133. Vector3 GetWorldScale() const;
  134. /// Return transform matrix in world space.
  135. const Matrix3x4& GetWorldTransform() const;
  136. /// Convert a local space position to world space.
  137. Vector3 LocalToWorld(const Vector3& position) const;
  138. /// Convert a local space position or rotation to world space.
  139. Vector3 LocalToWorld(const Vector4& vector) const;
  140. /// Convert a world space position to local space.
  141. Vector3 WorldToLocal(const Vector3& position) const;
  142. /// Convert a world space position or rotation to local space.
  143. Vector3 WorldToLocal(const Vector4& vector) const;
  144. /// Return whether transform has changed and world transform needs recalculation.
  145. bool IsDirty() const;
  146. /// Return number of child scene nodes.
  147. unsigned GetNumChildren(bool recursive = false) const;
  148. /// Return child scene node by index.
  149. Node* GetChild(unsigned index) const;
  150. /// Return child scene node by name.
  151. Node* GetChild(const String& name, bool recursive = false) const;
  152. /// Return child scene node by name.
  153. Node* GetChild(const char* name, bool recursive = false) const;
  154. /// Return child scene node by name hash.
  155. Node* GetChild(StringHash nameHash, bool recursive = false) const;
  156. /// Return number of components.
  157. unsigned GetNumComponents() const;
  158. /// Return number of non-local components.
  159. unsigned GetNumNetworkComponents() const;
  160. /// Return component by type. If there are several, returns the first.
  161. Component* GetComponent(ShortStringHash type) const;
  162. /// Return whether has a specific component.
  163. bool HasComponent(ShortStringHash type) const;
  164. };