Node.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  1. #ifndef NODE_H_
  2. #define NODE_H_
  3. #include "Transform.h"
  4. #include "Camera.h"
  5. #include "Light.h"
  6. #include "Model.h"
  7. #include "Form.h"
  8. #include "ParticleEmitter.h"
  9. #include "PhysicsRigidBody.h"
  10. #include "PhysicsCollisionObject.h"
  11. #include "PhysicsCollisionShape.h"
  12. #include "BoundingBox.h"
  13. #include "AIAgent.h"
  14. namespace gameplay
  15. {
  16. class AudioSource;
  17. class Bundle;
  18. class Scene;
  19. class Form;
  20. /**
  21. * Defines a basic hierarchical structure of transformation spaces.
  22. */
  23. class Node : public Transform, public Ref
  24. {
  25. friend class Scene;
  26. friend class Bundle;
  27. friend class MeshSkin;
  28. public:
  29. /**
  30. * Defines the types of nodes.
  31. */
  32. enum Type
  33. {
  34. NODE = 1,
  35. JOINT = 2
  36. };
  37. /**
  38. * Creates a new node with the specified ID.
  39. *
  40. * @param id The ID for the new node.
  41. * @script{create}
  42. */
  43. static Node* create(const char* id = NULL);
  44. /**
  45. * Gets the identifier for the node.
  46. *
  47. * @return The node identifier.
  48. */
  49. const char* getId() const;
  50. /**
  51. * Sets the identifier for the node.
  52. *
  53. * @param id The identifier to set for the node.
  54. */
  55. void setId(const char* id);
  56. /**
  57. * Returns the type of the node.
  58. */
  59. virtual Node::Type getType() const;
  60. /**
  61. * Adds a child node.
  62. *
  63. * @param child The child to add.
  64. */
  65. virtual void addChild(Node* child);
  66. /**
  67. * Removes a child node.
  68. *
  69. * @param child The child to remove.
  70. */
  71. virtual void removeChild(Node* child);
  72. /**
  73. * Removes all child nodes.
  74. */
  75. virtual void removeAllChildren();
  76. /**
  77. * Returns the first child for this node.
  78. *
  79. * @return The first child.
  80. */
  81. Node* getFirstChild() const;
  82. /**
  83. * Returns the first sibling of this node.
  84. *
  85. * @return The first sibling.
  86. */
  87. Node* getNextSibling() const;
  88. /**
  89. * Returns the previous sibling to this node.
  90. *
  91. * @return The previous sibling.
  92. */
  93. Node* getPreviousSibling() const;
  94. /**
  95. * Returns the parent of this node.
  96. *
  97. * @return The parent.
  98. */
  99. Node* getParent() const;
  100. /**
  101. * Determines if a custom tag with the specified name is set.
  102. *
  103. * @param name Name of the tag to query.
  104. *
  105. * @return true if the tag is set, false otherwise.
  106. */
  107. bool hasTag(const char* name) const;
  108. /**
  109. * Returns the value of the custom tag with the given name.
  110. *
  111. * @param name Name of the tag to return.
  112. *
  113. * @return The value of the given tag, or NULL if the tag is not set.
  114. */
  115. const char* getTag(const char* name) const;
  116. /**
  117. * Sets a custom tag on this Node.
  118. *
  119. * Custom tags can be used for a variety of purposes within a game. For example,
  120. * a tag called "transparent" can be added to nodes, to indicate which nodes in
  121. * a scene are transparent. This tag can then be read during rendering to sort
  122. * transparent and opaque objects for correct drawing order. Another example
  123. * is using a "visible" tag to mark nodes as invisible to be skipped during
  124. * rendering.
  125. *
  126. * Setting a tag to NULL removes the tag from the Node.
  127. *
  128. * @param name Name of the tag to set.
  129. * @param value Optional value of the tag (empty string by default).
  130. */
  131. void setTag(const char* name, const char* value = "");
  132. /**
  133. * Returns the user pointer for this node.
  134. *
  135. * @return The user pointer for this node.
  136. * @see setUserPointer(void*)
  137. * @script{ignore}
  138. */
  139. void* getUserPointer() const;
  140. /**
  141. * Sets the user pointer for this node.
  142. *
  143. * The user pointer is initially NULL and can be set to anything.
  144. * This is normally used to store game-specific data, such as
  145. * game state for a particular node. For example, attributes
  146. * for a game character, such as hit points, stamina, etc can
  147. * be defined in a game structure and stored in this field.
  148. *
  149. * When a node is deleted, the (optional) cleanup callback
  150. * function passed to this function is called to allow the
  151. * user to free any memory associated with the user pointer.
  152. *
  153. * @param pointer User pointer.
  154. * @param cleanupCallback Optional callback that is called when the
  155. * Node is being destroyed (or when the user pointer changes),
  156. * to allow the user to cleanup any memory associated with the
  157. * user pointer.
  158. * @script{ignore}
  159. */
  160. void setUserPointer(void* pointer, void (*cleanupCallback)(void*) = NULL);
  161. /**
  162. * Returns the number of direct children of this item.
  163. *
  164. * @return The number of children.
  165. */
  166. unsigned int getChildCount() const;
  167. /**
  168. * Returns the first child node that matches the given ID.
  169. *
  170. * This method checks the specified ID against its immediate child nodes
  171. * but does not check the ID against itself.
  172. * If recursive is true, it also traverses the Node's hierarchy with a breadth first search.
  173. *
  174. * @param id The ID of the child to find.
  175. * @param recursive True to search recursively all the node's children, false for only direct children.
  176. * @param exactMatch true if only nodes whose ID exactly matches the specified ID are returned,
  177. * or false if nodes that start with the given ID are returned.
  178. *
  179. * @return The Node found or NULL if not found.
  180. */
  181. Node* findNode(const char* id, bool recursive = true, bool exactMatch = true) const;
  182. /**
  183. * Returns all child nodes that match the given ID.
  184. *
  185. * @param id The ID of the node to find.
  186. * @param nodes A vector of nodes to be populated with matches.
  187. * @param recursive true if a recursive search should be performed, false otherwise.
  188. * @param exactMatch true if only nodes whose ID exactly matches the specified ID are returned,
  189. * or false if nodes that start with the given ID are returned.
  190. *
  191. * @return The number of matches found.
  192. * @script{ignore}
  193. */
  194. unsigned int findNodes(const char* id, std::vector<Node*>& nodes, bool recursive = true, bool exactMatch = true) const;
  195. /**
  196. * Gets the scene.
  197. *
  198. * @return The scene.
  199. */
  200. Scene* getScene() const;
  201. /**
  202. * Gets the top level node in this node's parent hierarchy.
  203. */
  204. Node* getRootNode() const;
  205. /**
  206. * Gets the world matrix corresponding to this node.
  207. *
  208. * @return The world matrix of this node.
  209. */
  210. virtual const Matrix& getWorldMatrix() const;
  211. /**
  212. * Gets the world view matrix corresponding to this node.
  213. *
  214. * @return The world view matrix of this node.
  215. */
  216. const Matrix& getWorldViewMatrix() const;
  217. /**
  218. * Gets the inverse transpose world matrix corresponding to this node.
  219. *
  220. * This matrix is typically used to transform normal vectors into world space.
  221. *
  222. * @return The inverse world matrix of this node.
  223. */
  224. const Matrix& getInverseTransposeWorldMatrix() const;
  225. /**
  226. * Gets the inverse transpose world view matrix corresponding to this node.
  227. *
  228. * This matrix is typically used to transform normal vectors into view space.
  229. *
  230. * @return The inverse world view matrix of this node.
  231. */
  232. const Matrix& getInverseTransposeWorldViewMatrix() const;
  233. /**
  234. * Gets the view matrix corresponding to this node based
  235. * on the scene's active camera.
  236. *
  237. * @return The view matrix of this node.
  238. */
  239. const Matrix& getViewMatrix() const;
  240. /**
  241. * Gets the inverse view matrix corresponding to this node based
  242. * on the scene's active camera.
  243. *
  244. * @return The inverse view matrix of this node.
  245. */
  246. const Matrix& getInverseViewMatrix() const;
  247. /**
  248. * Gets the projection matrix corresponding to this node based
  249. * on the scene's active camera.
  250. *
  251. * @return The projection matrix of this node.
  252. */
  253. const Matrix& getProjectionMatrix() const;
  254. /**
  255. * Gets the view * projection matrix corresponding to this node based
  256. * on the scene's active camera.
  257. *
  258. * @return The view * projection matrix of this node.
  259. */
  260. const Matrix& getViewProjectionMatrix() const;
  261. /**
  262. * Gets the inverse view * projection matrix corresponding to this node based
  263. * on the scene's active camera.
  264. *
  265. * @return The inverse view * projection matrix of this node.
  266. */
  267. const Matrix& getInverseViewProjectionMatrix() const;
  268. /**
  269. * Gets the world * view * projection matrix corresponding to this node based
  270. * on the scene's active camera.
  271. *
  272. * @return The world * view * projection matrix of this node.
  273. */
  274. const Matrix& getWorldViewProjectionMatrix() const;
  275. /**
  276. * Gets the translation vector (or position) of this Node in world space.
  277. *
  278. * @return The world translation vector.
  279. */
  280. Vector3 getTranslationWorld() const;
  281. /**
  282. * Gets the translation vector (or position) of this Node in view space.
  283. *
  284. * @return The view space translation vector.
  285. */
  286. Vector3 getTranslationView() const;
  287. /**
  288. * Returns the forward vector of the Node in world space.
  289. *
  290. * @return The forward vector in world space.
  291. */
  292. Vector3 getForwardVectorWorld() const;
  293. /**
  294. * Returns the forward vector of the Node in view space.
  295. *
  296. * @return The forwward vector in view space.
  297. */
  298. Vector3 getForwardVectorView() const;
  299. /**
  300. * Returns the right vector of the Node in world space.
  301. *
  302. * @return The right vector in world space.
  303. */
  304. Vector3 getRightVectorWorld() const;
  305. /**
  306. * Returns the up vector of the Node in world space.
  307. *
  308. * @return The up vector in world space.
  309. */
  310. Vector3 getUpVectorWorld() const;
  311. /**
  312. * Returns the translation vector of the currently active camera for this node's scene.
  313. *
  314. * @return The translation vector of the scene's active camera.
  315. */
  316. Vector3 getActiveCameraTranslationWorld() const;
  317. /**
  318. * Returns the view-space translation vector of the currently active camera for this node's scene.
  319. *
  320. * @return The translation vector of the scene's active camera, in view-space.
  321. */
  322. Vector3 getActiveCameraTranslationView() const;
  323. /**
  324. * Gets the first animation in the node hierarchy with the specified ID.
  325. *
  326. * @param id The ID of the animation to get. Returns the first animation if ID is NULL.
  327. * @return The first animation with the specified ID.
  328. */
  329. Animation* getAnimation(const char* id = NULL) const;
  330. /**
  331. * Returns the pointer to this node's camera.
  332. *
  333. * @return The pointer to this node's camera or NULL.
  334. */
  335. Camera* getCamera() const;
  336. /**
  337. * Assigns a camera to this node.
  338. *
  339. * This will increase the reference count of the new camera and decrease
  340. * the reference count of the old camera.
  341. *
  342. * @param camera A pointer to a camera. May be NULL.
  343. */
  344. void setCamera(Camera* camera);
  345. /**
  346. * Returns the pointer to this node's light.
  347. *
  348. * @return The pointer to this node's light or NULL.
  349. */
  350. Light* getLight() const;
  351. /**
  352. * Assigns a light to this node.
  353. *
  354. * This will increase the reference count of the new light and decrease
  355. * the reference count of the old light.
  356. *
  357. * @param light The new light. May be NULL.
  358. */
  359. void setLight(Light* light);
  360. /**
  361. * Returns the pointer to this node's model.
  362. *
  363. * @return The pointer to this node's model or NULL.
  364. */
  365. Model* getModel() const;
  366. /**
  367. * Assigns a model to this node.
  368. *
  369. * This will increase the reference count of the new model and decrease
  370. * the reference count of the old model.
  371. *
  372. * @param model The new model. May be NULL.
  373. */
  374. void setModel(Model* model);
  375. /**
  376. * Returns the pointer to this node's form.
  377. *
  378. * @return The pointer to this node's form or NULL.
  379. */
  380. Form* getForm() const;
  381. /**
  382. * Assigns a form to this node.
  383. *
  384. * @param form The form pointer. May be NULL.
  385. */
  386. void setForm(Form* form);
  387. /**
  388. * Returns the pointer to this node's audio source.
  389. *
  390. * @return The pointer to this node's audio source or NULL.
  391. */
  392. AudioSource* getAudioSource() const;
  393. /**
  394. * Assigns an audio source to this node.
  395. *
  396. * This will increase the reference count of the new audio source and decrease
  397. * the reference count of the old audio source.
  398. *
  399. * @param audio The new audio source. May be NULL.
  400. */
  401. void setAudioSource(AudioSource* audio);
  402. /**
  403. * Returns the pointer to this node's particle emitter.
  404. *
  405. * @return The pointer to this node's particle emitter or NULL.
  406. */
  407. ParticleEmitter* getParticleEmitter() const;
  408. /**
  409. * Assigns a particle emitter to this node.
  410. *
  411. * This will increase the reference count of the new particle emitter and decrease
  412. * the reference count of the old particle emitter.
  413. *
  414. * @param emitter The new particle emitter. May be NULL.
  415. */
  416. void setParticleEmitter(ParticleEmitter* emitter);
  417. /**
  418. * Returns the pointer to this node's physics collision object.
  419. *
  420. * The type of the returned collision object can be queried using
  421. * the PhysicsCollisionObject::getType() method.
  422. *
  423. * @return The pointer to this node's physics collision object.
  424. */
  425. PhysicsCollisionObject* getCollisionObject() const;
  426. /**
  427. * Sets (or disables) the physics collision object for this node.
  428. *
  429. * The supported collision object types include rigid bodies, ghost objects,
  430. * characters, vehicles, and vehicle wheels.
  431. *
  432. * Rigid bodies are used to represent most physical objects in a game. The important
  433. * feature of rigid bodies is that they can be simulated by the physics system as other
  434. * rigid bodies or collision objects collide with them. To support this physics simulation,
  435. * rigid bodies require additional parameters, such as mass, friction and restitution to
  436. * define their physical features. These parameters can be passed into the
  437. * 'rigidBodyParameters' parameter.
  438. *
  439. * Vehicles consist of a rigid body with wheels. The rigid body parameters can be passed-in
  440. * via the 'rigidBodyParameters' parameter, and wheels can be added to the vehicle.
  441. *
  442. * Ghost objects are a simple type of collision object that are not simulated. By default
  443. * they pass through other objects in the scene without affecting them. Ghost objects do
  444. * receive collision events however, which makes them useful for representing non-simulated
  445. * entities in a game that still require collision events, such as volumetric triggers,
  446. * power-ups, etc.
  447. *
  448. * Characters are an extention of ghost objects which provide a number of additional features
  449. * for animating and moving characters within a game. Characters are represented as ghost
  450. * objects instead of rigid bodies to allow more direct control over character movement,
  451. * since attempting to model a physics character with a simulated rigid body usually results
  452. * in unresponse and unpredictable character movement. Unlike normal ghost objects,
  453. * characters to react to other characters and rigid bodies in the world. Characters react
  454. * to gravity and collide (and respond) with rigid bodies to allow them to walk on the ground,
  455. * slide along walls and walk up/down slopes and stairs.
  456. *
  457. * @param type The type of the collision object to set; to disable the physics
  458. * collision object, pass PhysicsCollisionObject::NONE.
  459. * @param shape Definition of a physics collision shape to be used for this collision object.
  460. * Use the static shape methods on the PhysicsCollisionShape class to specificy a shape
  461. * definition, such as PhysicsCollisionShape::box().
  462. * @param rigidBodyParameters If type is PhysicsCollisionObject::RIGID_BODY or
  463. * PhysicsCollisionObject::VEHICLE, this must point to a valid rigid body
  464. * parameters object containing information about the rigid body;
  465. * otherwise, this parmater may be NULL.
  466. */
  467. PhysicsCollisionObject* setCollisionObject(PhysicsCollisionObject::Type type, const PhysicsCollisionShape::Definition& shape = PhysicsCollisionShape::box(),
  468. PhysicsRigidBody::Parameters* rigidBodyParameters = NULL);
  469. /**
  470. * Sets the physics collision object for this node using the data from the Properties object defined at the specified URL,
  471. * where the URL is of the format "<file-path>.<extension>#<namespace-id>/<namespace-id>/.../<namespace-id>"
  472. * (and "#<namespace-id>/<namespace-id>/.../<namespace-id>" is optional).
  473. *
  474. * @param url The URL pointing to the Properties object defining the physics collision object.
  475. */
  476. PhysicsCollisionObject* setCollisionObject(const char* url);
  477. /**
  478. * Sets the physics collision object for this node from the given properties object.
  479. *
  480. * @param properties The properties object defining the collision object.
  481. */
  482. PhysicsCollisionObject* setCollisionObject(Properties* properties);
  483. /**
  484. * Returns the number of advertised descendants held in this node.
  485. *
  486. * Descendant nodes can advertise themselves to others using this
  487. * mechanism, such as how the wheels are bound to a physics vehicle
  488. * via their common ancestor.
  489. *
  490. * @return the number of advertised descendants held in this node.
  491. */
  492. unsigned int getNumAdvertisedDescendants() const;
  493. /**
  494. * Returns the advertised descendant at the specified index.
  495. *
  496. * Descendant nodes can advertise themselves to others using this
  497. * mechanism, such as how the wheels are bound to a physics vehicle
  498. * via their common ancestor.
  499. *
  500. * @param i the index to look-up.
  501. *
  502. * @return the advertised descendant at the specified index.
  503. */
  504. Node* getAdvertisedDescendant(unsigned int i) const;
  505. /**
  506. * Adds the specified node to the list of advertised descendants.
  507. *
  508. * Descendant nodes can advertise themselves to others using this
  509. * mechanism, such as how the wheels are bound to a physics vehicle
  510. * via their common ancestor.
  511. *
  512. * @param node the node reference to add.
  513. */
  514. void addAdvertisedDescendant(Node* node);
  515. /**
  516. * Returns the AI agent assigned to this node.
  517. *
  518. * @return The AI agent for this node.
  519. */
  520. AIAgent* getAgent() const;
  521. /**
  522. * Sets the AI agent for this node.
  523. *
  524. * @param agent The AI agent to set.
  525. */
  526. void setAgent(AIAgent* agent);
  527. /**
  528. * Returns the bounding sphere for the Node, in world space.
  529. *
  530. * The bounding sphere for a node represents the area, in world
  531. * space, that the node contains. This includes the space occupied
  532. * by any child nodes as well as the space occupied by any data
  533. * inside the node (such as models).
  534. *
  535. * Bounding spheres for nodes are rough approximations of the data
  536. * contained within a node and they are intended for visibility
  537. * testing or first-pass intersection testing only. They are not
  538. * appropriate for accurate collision detection since they most often
  539. * do not tightly contain a node's content.
  540. *
  541. * A node that does not occupy any space will return a bounding sphere
  542. * with a center point equal to the node translation and a radius of zero.
  543. *
  544. * @return The world-space bounding sphere for the node.
  545. */
  546. const BoundingSphere& getBoundingSphere() const;
  547. /**
  548. * Clones the node and all of its child nodes.
  549. *
  550. * @return A new node.
  551. * @script{create}
  552. */
  553. Node* clone() const;
  554. protected:
  555. /**
  556. * Constructor.
  557. */
  558. Node(const char* id);
  559. /**
  560. * Destructor.
  561. */
  562. virtual ~Node();
  563. /**
  564. * Clones a single node and its data but not its children.
  565. *
  566. * @param context The clone context.
  567. *
  568. * @return Pointer to the newly created node.
  569. */
  570. virtual Node* cloneSingleNode(NodeCloneContext &context) const;
  571. /**
  572. * Recursively clones this node and its children.
  573. *
  574. * @param context The clone context.
  575. *
  576. * @return The newly created node.
  577. */
  578. Node* cloneRecursive(NodeCloneContext &context) const;
  579. /**
  580. * Copies the data from this node into the given node.
  581. *
  582. * @param node The node to copy the data to.
  583. * @param context The clone context.
  584. */
  585. void cloneInto(Node* node, NodeCloneContext &context) const;
  586. /**
  587. * Removes this node from its parent.
  588. */
  589. void remove();
  590. /**
  591. * Called when this Node's transform changes.
  592. */
  593. void transformChanged();
  594. /**
  595. * Called when this Node's hierarchy changes.
  596. */
  597. void hierarchyChanged();
  598. /**
  599. * Marks the bounding volume of the node as dirty.
  600. */
  601. void setBoundsDirty();
  602. private:
  603. /**
  604. * Hidden copy constructor.
  605. */
  606. Node(const Node& copy);
  607. /**
  608. * Hidden copy assignment operator.
  609. */
  610. Node& operator=(const Node&);
  611. protected:
  612. /**
  613. * Defines a pointer and cleanup callback to custom user data that can be store in a Node.
  614. */
  615. struct UserData
  616. {
  617. /**
  618. * Constructor.
  619. */
  620. UserData() : pointer(NULL), cleanupCallback(NULL) {}
  621. /**
  622. * A pointer to custom user data.
  623. */
  624. void* pointer;
  625. /**
  626. * Cleanup callback.
  627. */
  628. void (*cleanupCallback)(void*);
  629. };
  630. /**
  631. * The Scene this node belongs to.
  632. */
  633. Scene* _scene;
  634. /**
  635. * The Node's ID.
  636. */
  637. std::string _id;
  638. /**
  639. * Pointer to the Node's first child.
  640. */
  641. Node* _firstChild;
  642. /**
  643. * Pointer to the Node's next child.
  644. */
  645. Node* _nextSibling;
  646. /**
  647. * Pointer to the Node's previous sibling.
  648. */
  649. Node* _prevSibling;
  650. /**
  651. * Pointer to the Node's parent.
  652. */
  653. Node* _parent;
  654. /**
  655. * The number of children belonging to the Node.
  656. */
  657. unsigned int _childCount;
  658. /**
  659. * List of custom tags for a node.
  660. */
  661. std::map<std::string, std::string>* _tags;
  662. /**
  663. * Pointer to the Camera attached to the Node.
  664. */
  665. Camera* _camera;
  666. /**
  667. * Pointer to the Light attached to the Node.
  668. */
  669. Light* _light;
  670. /**
  671. * Pointer to the Model attached to the Node.
  672. */
  673. Model* _model;
  674. /**
  675. * Pointer to the Form attached to the Node.
  676. */
  677. Form* _form;
  678. /**
  679. * Pointer to the AudioSource attached to the Node.
  680. */
  681. AudioSource* _audioSource;
  682. /**
  683. * Pointer to the ParticleEmitter attached to the Node.
  684. */
  685. ParticleEmitter* _particleEmitter;
  686. /**
  687. * Pointer to the PhysicsCollisionObject attached to the Node.
  688. */
  689. PhysicsCollisionObject* _collisionObject;
  690. /**
  691. * Pointer to the AI agent attached to the Node.
  692. */
  693. AIAgent* _agent;
  694. /**
  695. * World Matrix representation of the Node.
  696. */
  697. mutable Matrix _world;
  698. /**
  699. * Dirty bits flag for the Node.
  700. */
  701. mutable int _dirtyBits;
  702. /**
  703. * A flag indicating if the Node's hierarchy has changed.
  704. */
  705. bool _notifyHierarchyChanged;
  706. /**
  707. * The Bounding Sphere containing the Node.
  708. */
  709. mutable BoundingSphere _bounds;
  710. /**
  711. * Pointer to custom UserData and cleanup call back that can be stored in a Node.
  712. */
  713. UserData* _userData;
  714. /**
  715. * A linear collection of descendants who wish to advertise themselves, typically
  716. * to other descendants. This allows nodes of common ancestry to bond. One example
  717. * of this is a physics vehicle and its wheels, which are associated via their
  718. * lowest common ancestor.
  719. */
  720. std::vector<Node*> _advertisedDescendants;
  721. };
  722. /**
  723. * NodeCloneContext represents the context data that is kept when cloning a node.
  724. *
  725. * The NodeCloneContext is used to make sure objects don't get cloned twice.
  726. */
  727. class NodeCloneContext
  728. {
  729. public:
  730. /**
  731. * Constructor.
  732. */
  733. NodeCloneContext();
  734. /**
  735. * Destructor.
  736. */
  737. ~NodeCloneContext();
  738. /**
  739. * Finds the cloned animation of the given animation or NULL if this animation was not registered with this context.
  740. *
  741. * @param animation The animation to search for the cloned copy of.
  742. *
  743. * @return The cloned animation or NULL if not found.
  744. */
  745. Animation* findClonedAnimation(const Animation* animation);
  746. /**
  747. * Registers the cloned animation with this context so that it doesn't get cloned twice.
  748. *
  749. * @param original The pointer to the original animation.
  750. * @param clone The pointer to the cloned animation.
  751. */
  752. void registerClonedAnimation(const Animation* original, Animation* clone);
  753. /**
  754. * Finds the cloned node of the given node or NULL if this node was not registered with this context.
  755. *
  756. * @param node The node to search for the cloned copy of.
  757. *
  758. * @return The cloned node or NULL if not found.
  759. */
  760. Node* findClonedNode(const Node* node);
  761. /**
  762. * Registers the cloned node with this context so that it doens't get cloned twice.
  763. *
  764. * @param original The pointer to the original node.
  765. * @param clone The pointer to the cloned node.
  766. */
  767. void registerClonedNode(const Node* original, Node* clone);
  768. private:
  769. /**
  770. * Hidden copy constructor.
  771. */
  772. NodeCloneContext(const NodeCloneContext&);
  773. /**
  774. * Hidden copy assignment operator.
  775. */
  776. NodeCloneContext& operator=(const NodeCloneContext&);
  777. std::map<const Animation*, Animation*> _clonedAnimations;
  778. std::map<const Node*, Node*> _clonedNodes;
  779. };
  780. }
  781. #endif