Node.h 4.0 KB

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