| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- $#include "Node.h"
- /// Component and child node creation mode for networking.
- enum CreateMode
- {
- REPLICATED = 0,
- LOCAL = 1
- };
- /// %Scene node that may contain components and child nodes.
- class Node
- {
- public:
- /// Set name.
- void SetName(const String& name);
- /// Set position relative to parent node.
- void SetPosition(const Vector3& position);
- /// Set rotation relative to parent node.
- void SetRotation(const Quaternion& rotation);
- /// Set direction relative to parent node. Positive Z equals identity.
- void SetDirection(const Vector3& direction);
- /// Set uniform scale relative to parent node.
- void SetScale(float scale);
- /// Set scale relative to parent node.
- void SetScale(const Vector3& scale);
- /// Set transform relative to parent node.
- void SetTransform(const Vector3& position, const Quaternion& rotation);
- /// Set transform relative to parent node.
- void SetTransform(const Vector3& position, const Quaternion& rotation, float scale);
- /// Set transform relative to parent node.
- void SetTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale);
- /// Set position relative to world space.
- void SetWorldPosition(const Vector3& position);
- /// Set rotation relative to world space.
- void SetWorldRotation(const Quaternion& rotation);
- /// Set direction relative to world space.
- void SetWorldDirection(const Vector3& direction);
- /// Set uniform scale relative to world space.
- void SetWorldScale(float scale);
- /// Set scale relative to world space.
- void SetWorldScale(const Vector3& scale);
- /// Set transform relative to world space.
- void SetWorldTransform(const Vector3& position, const Quaternion& rotation);
- /// Set transform relative to world space.
- void SetWorldTransform(const Vector3& position, const Quaternion& rotation, float scale);
- /// Set transform relative to world space.
- void SetWorldTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale);
- /// Move the scene node.
- void Translate(const Vector3& delta);
- /// Move the scene node relative to its rotation.
- void TranslateRelative(const Vector3& delta);
- /// Rotate the scene node.
- void Rotate(const Quaternion& delta, bool fixedAxis = false);
- /// Rotate around the X axis.
- void Pitch(float angle, bool fixedAxis = false);
- /// Rotate around the Y axis.
- void Yaw(float angle, bool fixedAxis = false);
- /// Rotate around the Z axis.
- void Roll(float angle, bool fixedAxis = false);
- /// Look at a target world position.
- void LookAt(const Vector3& target, const Vector3& upAxis = Vector3::UP);
- /// Modify scale uniformly.
- void Scale(float scale);
- /// Modify scale.
- void Scale(const Vector3& scale);
- /// Set enabled/disabled state without recursion. Components in a disabled node become effectively disabled regardless of their own enable/disable state.
- void SetEnabled(bool enable);
- /// Set enabled/disabled state with optional recursion.
- void SetEnabled(bool enable, bool recursive);
- /// Set owner connection for networking.
- void SetOwner(Connection* owner);
- /// Mark node and child nodes to need world transform recalculation. Notify listener components.
- void MarkDirty();
- /// Create a child scene node (with specified ID if provided).
- Node* CreateChild(const String& name = String::EMPTY, CreateMode mode = REPLICATED, unsigned id = 0);
- /// Add a child scene node.
- void AddChild(Node* node);
- /// Remove a child scene node.
- void RemoveChild(Node* node);
- /// Remove all child scene nodes.
- void RemoveAllChildren();
- /// Create a component to this node (with specified ID if provided).
- Component* CreateComponent(ShortStringHash type, CreateMode mode = REPLICATED, unsigned id = 0);
- /// Create a component to this node if it does not exist already.
- Component* GetOrCreateComponent(ShortStringHash type, CreateMode mode = REPLICATED, unsigned id = 0);
- /// Remove a component from this node.
- void RemoveComponent(Component* component);
- /// Remove the first component of specific type from this node.
- void RemoveComponent(ShortStringHash type);
- /// Remove all components from this node.
- void RemoveAllComponents();
- /// Clone scene node, components and child nodes. Return the clone.
- Node* Clone(CreateMode mode = REPLICATED);
- /// Remove from the parent node. If no other shared pointer references exist, causes immediate deletion.
- void Remove();
- /// Set parent scene node. Retains the world transform.
- void SetParent(Node* parent);
- /// Set a user variable.
- void SetVar(ShortStringHash key, const Variant& value);
- /// Add listener component that is notified of node being dirtied. Can either be in the same node or another.
- void AddListener(Component* component);
- /// Remove listener component.
- void RemoveListener(Component* component);
-
- /// Return ID.
- unsigned GetID() const;
- /// Return name.
- const String& GetName() const;
- /// Return name hash.
- StringHash GetNameHash() const;
- /// Return parent scene node.
- Node* GetParent() const;
- /// Return scene.
- Scene* GetScene() const;
- /// Return whether is enabled. Disables nodes effectively disable all their components.
- bool IsEnabled() const;
- /// Return owner connection in networking.
- Connection* GetOwner() const;
- /// Return position relative to parent node.
- const Vector3& GetPosition() const;
- /// Return rotation relative to parent node.
- const Quaternion& GetRotation() const;
- /// Return direction relative to parent node. Identity rotation equals positive Z.
- Vector3 GetDirection() const;
- /// Return scale relative to parent node.
- const Vector3& GetScale() const;
- /// Return transform matrix relative to parent node.
- Matrix3x4 GetTransform() const;
- /// Return position in world space.
- Vector3 GetWorldPosition() const;
- /// Return rotation in world space.
- Quaternion GetWorldRotation() const;
- /// Return direction in world space.
- Vector3 GetWorldDirection() const;
-
- /// Return scale in world space.
- Vector3 GetWorldScale() const;
- /// Return transform matrix in world space.
- const Matrix3x4& GetWorldTransform() const;
- /// Convert a local space position to world space.
- Vector3 LocalToWorld(const Vector3& position) const;
- /// Convert a local space position or rotation to world space.
- Vector3 LocalToWorld(const Vector4& vector) const;
- /// Convert a world space position to local space.
- Vector3 WorldToLocal(const Vector3& position) const;
- /// Convert a world space position or rotation to local space.
- Vector3 WorldToLocal(const Vector4& vector) const;
- /// Return whether transform has changed and world transform needs recalculation.
- bool IsDirty() const;
- /// Return number of child scene nodes.
- unsigned GetNumChildren(bool recursive = false) const;
- /// Return child scene node by index.
- Node* GetChild(unsigned index) const;
- /// Return child scene node by name.
- Node* GetChild(const String& name, bool recursive = false) const;
- /// Return child scene node by name.
- Node* GetChild(const char* name, bool recursive = false) const;
- /// Return child scene node by name hash.
- Node* GetChild(StringHash nameHash, bool recursive = false) const;
- /// Return number of components.
- unsigned GetNumComponents() const;
- /// Return number of non-local components.
- unsigned GetNumNetworkComponents() const;
- /// Return component by type. If there are several, returns the first.
- Component* GetComponent(ShortStringHash type) const;
- /// Return whether has a specific component.
- bool HasComponent(ShortStringHash type) const;
-
- };
|