Node.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #ifndef NODE_H_
  2. #define NODE_H_
  3. #include <list>
  4. #include "Object.h"
  5. #include "CameraInstance.h"
  6. #include "LightInstance.h"
  7. #include "Model.h"
  8. namespace gameplay
  9. {
  10. class Node : public Object
  11. {
  12. public:
  13. /**
  14. * Constructor.
  15. */
  16. Node(void);
  17. /**
  18. * Destructor.
  19. */
  20. virtual ~Node(void);
  21. virtual unsigned int getTypeId(void) const;
  22. virtual const char* getElementName(void) const;
  23. virtual void writeBinary(FILE* file);
  24. virtual void writeText(FILE* file);
  25. /**
  26. * Adds a child node.
  27. *
  28. * If the ownChild is true. The child is deleted when this
  29. * node is deleted.
  30. *
  31. * @param child The child to add.
  32. */
  33. void addChild(Node* child);
  34. /**
  35. * Removes a child node.
  36. *
  37. * If no longer referenced it destroys the node.
  38. * To avoid destroy on changing hierarchy, ensure you add first before removing.
  39. *
  40. * @param child The child to remove.
  41. */
  42. void removeChild(Node* child);
  43. /**
  44. * Removes all the child node.
  45. */
  46. void removeChildren();
  47. /**
  48. * Determines if this node has child nodes.
  49. *
  50. * @return true if it has 1 or more children; false if otherwise.
  51. */
  52. bool hasChildren() const;
  53. /**
  54. * Get the number of children for this node.
  55. *
  56. * @return The number of child nodes for this node.
  57. */
  58. unsigned int getChildCount() const;
  59. /**
  60. * Gets the next sibling node.
  61. *
  62. * @return The next sibling node.
  63. */
  64. Node* getNextSibling() const;
  65. /**
  66. * Gets the previous sibling node.
  67. *
  68. * @return The previous sibling node.
  69. */
  70. Node* getPreviousSibling() const;
  71. /**
  72. * Gets the first child node.
  73. *
  74. * @return The first child node.
  75. */
  76. Node* getFirstChild() const;
  77. /**
  78. * Gets the last child node.
  79. *
  80. * @return The last child node.
  81. */
  82. Node* getLastChild() const;
  83. /**
  84. * Gets the parent node.
  85. *
  86. * @return The parent node.
  87. */
  88. Node* getParent() const;
  89. /**
  90. * Returns the Camera for this node.
  91. *
  92. * @return The camera for this node or NULL if no camera is set.
  93. */
  94. Camera* getCamera() const;
  95. /**
  96. * Returns the Light for this node.
  97. *
  98. * @return The light for this node or NULL if no light is set.
  99. */
  100. Light* getLight() const;
  101. /**
  102. * Returns the Model of this node.
  103. *
  104. * @return The model for this node or NULL if no model is set.
  105. */
  106. Model* getModel() const;
  107. /**
  108. * Sets the transform for this node.
  109. */
  110. void setTransformMatrix(float matrix[]);
  111. void setCameraInstance(CameraInstance* cameraInstance);
  112. void setLightInstance(LightInstance* lightInstance);
  113. void setModel(Model* model);
  114. /**
  115. * Sets if this node is a joint node.
  116. */
  117. void setIsJoint(bool value);
  118. /**
  119. * Returns true if this is a joint node.
  120. */
  121. bool isJoint();
  122. Node* getFirstCameraNode() const;
  123. /**
  124. * Returns true if this node has a camera.
  125. */
  126. bool hasCamera() const;
  127. /**
  128. * Returns true if this node has a light.
  129. */
  130. bool hasLight() const;
  131. private:
  132. float _transform[16];
  133. int _childCount;
  134. Node* _nextSibling;
  135. Node* _previousSibling;
  136. Node* _firstChild;
  137. Node* _lastChild;
  138. Node* _parent;
  139. CameraInstance* _camera;
  140. LightInstance* _light;
  141. Model* _model;
  142. bool _joint;
  143. };
  144. }
  145. #endif