$#include "AnimationController.h" $#include "AnimatedModel.h" $#include "Camera.h" $#include "CollisionShape.h" $#include "Constraint.h" $#include "DebugRenderer.h" $#include "DecalSet.h" $#include "Drawable.h" $#include "Light.h" $#include "Navigable.h" $#include "NavigationMesh.h" $#include "NetworkPriority.h" $#include "Node.h" $#include "Octree.h" $#include "OffMeshConnection.h" $#include "PhysicsWorld.h" $#include "RigidBody.h" $#include "SmoothedTransform.h" $#include "SoundListener.h" $#include "SoundSource.h" $#include "StaticModel.h" $#include "Terrain.h" $#include "Zone.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: /// Construct. Node(Context* context); /// Destruct. Any child nodes are detached. virtual ~Node(); /// 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); tolua_outside void NodeRemoveComponent @ RemoveComponent(const char* 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); /// Template version of creating a component. // template T* CreateComponent(CreateMode mode = REPLICATED, unsigned id = 0); AnimationController* CreateComponent @ CreateAnimationController(); AnimatedModel* CreateComponent @ CreateAnimatedModel(); Camera* CreateComponent @ CreateCamera(); CollisionShape* CreateComponent @ CreateCollisionShape(); Constraint* CreateComponent @ CreateConstraint(); DebugRenderer* CreateComponent @ CreateDebugRenderer(); DecalSet* CreateComponent @ CreateDecalSet(); Drawable* CreateComponent @ CreateDrawable(); Light* CreateComponent @ CreateLight(); Navigable* CreateComponent @ CreateNavigable(); NavigationMesh* CreateComponent @ CreateNavigationMesh(); NetworkPriority* CreateComponent @ CreateNetworkPriority(); Octree* CreateComponent @ CreateOctree(); OffMeshConnection* CreateComponent @ CreateOffMeshConnection(); PhysicsWorld* CreateComponent @ CreatePhysicsWorld(); RigidBody* CreateComponent @ CreateRigidBody(); SmoothedTransform* CreateComponent @ CreateSmoothedTransform(); SoundListener* CreateComponent @ CreateSoundListener(); SoundSource* CreateComponent @ CreateSoundSource(); StaticModel* CreateComponent @ CreateStaticModel(); Terrain* CreateComponent @ CreateTerrain(); Zone* CreateComponent @ CreateZone(); AnimationController* CreateComponent @ CreateAnimationController(CreateMode mode); AnimatedModel* CreateComponent @ CreateAnimatedModel(CreateMode mode); Camera* CreateComponent @ CreateCamera(CreateMode mode); CollisionShape* CreateComponent @ CreateCollisionShape(CreateMode mode); Constraint* CreateComponent @ CreateConstraint(CreateMode mode); DebugRenderer* CreateComponent @ CreateDebugRenderer(CreateMode mode); DecalSet* CreateComponent @ CreateDecalSet(CreateMode mode); Drawable* CreateComponent @ CreateDrawable(CreateMode mode); Light* CreateComponent @ CreateLight(CreateMode mode); Navigable* CreateComponent @ CreateNavigable(CreateMode mode); NavigationMesh* CreateComponent @ CreateNavigationMesh(CreateMode mode); NetworkPriority* CreateComponent @ CreateNetworkPriority(CreateMode mode); Octree* CreateComponent @ CreateOctree(CreateMode mode); OffMeshConnection* CreateComponent @ CreateOffMeshConnection(CreateMode mode); PhysicsWorld* CreateComponent @ CreatePhysicsWorld(CreateMode mode); RigidBody* CreateComponent @ CreateRigidBody(CreateMode mode); SmoothedTransform* CreateComponent @ CreateSmoothedTransform(CreateMode mode); SoundListener* CreateComponent @ CreateSoundListener(CreateMode mode); SoundSource* CreateComponent @ CreateSoundSource(CreateMode mode); StaticModel* CreateComponent @ CreateStaticModel(CreateMode mode); Terrain* CreateComponent @ CreateTerrain(CreateMode mode); Zone* CreateComponent @ CreateZone(CreateMode mode); AnimationController* CreateComponent @ CreateAnimationController(CreateMode mode, unsigned id); AnimatedModel* CreateComponent @ CreateAnimatedModel(CreateMode mode, unsigned id); Camera* CreateComponent @ CreateCamera(CreateMode mode, unsigned id); CollisionShape* CreateComponent @ CreateCollisionShape(CreateMode mode, unsigned id); Constraint* CreateComponent @ CreateConstraint(CreateMode mode, unsigned id); DebugRenderer* CreateComponent @ CreateDebugRenderer(CreateMode mode, unsigned id); DecalSet* CreateComponent @ CreateDecalSet(CreateMode mode, unsigned id); Drawable* CreateComponent @ CreateDrawable(CreateMode mode, unsigned id); Light* CreateComponent @ CreateLight(CreateMode mode, unsigned id); Navigable* CreateComponent @ CreateNavigable(CreateMode mode, unsigned id); NavigationMesh* CreateComponent @ CreateNavigationMesh(CreateMode mode, unsigned id); NetworkPriority* CreateComponent @ CreateNetworkPriority(CreateMode mode, unsigned id); Octree* CreateComponent @ CreateOctree(CreateMode mode, unsigned id); OffMeshConnection* CreateComponent @ CreateOffMeshConnection(CreateMode mode, unsigned id); PhysicsWorld* CreateComponent @ CreatePhysicsWorld(CreateMode mode, unsigned id); RigidBody* CreateComponent @ CreateRigidBody(CreateMode mode, unsigned id); SmoothedTransform* CreateComponent @ CreateSmoothedTransform(CreateMode mode, unsigned id); SoundListener* CreateComponent @ CreateSoundListener(CreateMode mode, unsigned id); SoundSource* CreateComponent @ CreateSoundSource(CreateMode mode, unsigned id); StaticModel* CreateComponent @ CreateStaticModel(CreateMode mode, unsigned id); Terrain* CreateComponent @ CreateTerrain(CreateMode mode, unsigned id); Zone* CreateComponent @ CreateZone(CreateMode mode, unsigned id); /// Template version of getting or creating a component. // template T* GetOrCreateComponent(CreateMode mode = REPLICATED, unsigned id = 0); /// Return ID. unsigned GetID() const { return id_; } /// Return name. const String& GetName() const { return name_; } /// Return name hash. StringHash GetNameHash() const { return nameHash_; } /// Return parent scene node. Node* GetParent() const { return parent_; } /// Return scene. Scene* GetScene() const { return scene_; } /// Return whether is enabled. Disables nodes effectively disable all their components. bool IsEnabled() const { return enabled_; } /// Return owner connection in networking. Connection* GetOwner() const { return owner_; } /// Return position relative to parent node. const Vector3& GetPosition() const { return position_; } /// Return rotation relative to parent node. const Quaternion& GetRotation() const { return rotation_; } /// Return direction relative to parent node. Identity rotation equals positive Z. Vector3 GetDirection() const { return rotation_ * Vector3::FORWARD; } /// Return scale relative to parent node. const Vector3& GetScale() const { return scale_; } /// Return transform matrix relative to parent node. Matrix3x4 GetTransform() const { return Matrix3x4(position_, rotation_, scale_); } /// Return position in world space. Vector3 GetWorldPosition() const { if (dirty_) UpdateWorldTransform(); return worldTransform_.Translation(); } /// Return rotation in world space. Quaternion GetWorldRotation() const { if (dirty_) UpdateWorldTransform(); return worldRotation_; } /// Return direction in world space. Vector3 GetWorldDirection() const { if (dirty_) UpdateWorldTransform(); return worldRotation_ * Vector3::FORWARD; } /// Return scale in world space. Vector3 GetWorldScale() const { if (dirty_) UpdateWorldTransform(); return worldTransform_.Scale(); } /// Return transform matrix in world space. const Matrix3x4& GetWorldTransform() const { if (dirty_) UpdateWorldTransform(); return worldTransform_; } /// 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 dirty_; } /// 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 components_.Size(); } /// 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; tolua_outside bool NodeHasComponent @ HasComponent(const char* type) const; /// Template version of returning a component by type. // template T* GetComponent() const; AnimationController* GetComponent @ GetAnimationController() const; AnimatedModel* GetComponent @ GetAnimatedModel() const; Camera* GetComponent @ GetCamera() const; CollisionShape* GetComponent @ GetCollisionShape() const; Constraint* GetComponent @ GetConstraint() const; DebugRenderer* GetComponent @ GetDebugRenderer() const; DecalSet* GetComponent @ GetDecalSet() const; Drawable* GetComponent @ GetDrawable() const; Light* GetComponent @ GetLight() const; Navigable* GetComponent @ GetNavigable() const; NavigationMesh* GetComponent @ GetNavigationMesh() const; NetworkPriority* GetComponent @ GetNetworkPriority() const; Octree* GetComponent @ GetOctree() const; OffMeshConnection* GetComponent @ GetOffMeshConnection() const; PhysicsWorld* GetComponent @ GetPhysicsWorld() const; RigidBody* GetComponent @ GetRigidBody() const; SmoothedTransform* GetComponent @ GetSmoothedTransform() const; SoundListener* GetComponent @ GetSoundListener() const; SoundSource* GetComponent @ GetSoundSource() const; StaticModel* GetComponent @ GetStaticModel() const; Terrain* GetComponent @ GetTerrain() const; Zone* GetComponent @ GetZone() const; }; ${ void NodeRemoveComponent(Node* node, const char* type) { return node->RemoveComponent(ShortStringHash(type)); } bool NodeHasComponent(const Node* node, const char* type) { return node->HasComponent(ShortStringHash(type)); } $}