]> git.lizzy.rs Git - irrlicht.git/blob - include/ISceneNode.h
Prepare for integration with Minetest
[irrlicht.git] / include / ISceneNode.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef __I_SCENE_NODE_H_INCLUDED__\r
6 #define __I_SCENE_NODE_H_INCLUDED__\r
7 \r
8 #include "IAttributeExchangingObject.h"\r
9 #include "ESceneNodeTypes.h"\r
10 #include "ECullingTypes.h"\r
11 #include "EDebugSceneTypes.h"\r
12 #include "ISceneNodeAnimator.h"\r
13 #include "ITriangleSelector.h"\r
14 #include "SMaterial.h"\r
15 #include "irrString.h"\r
16 #include "aabbox3d.h"\r
17 #include "matrix4.h"\r
18 #include "irrList.h"\r
19 #include "IAttributes.h"\r
20 \r
21 namespace irr\r
22 {\r
23 namespace scene\r
24 {\r
25         class ISceneManager;\r
26 \r
27         //! Typedef for list of scene nodes\r
28         typedef core::list<ISceneNode*> ISceneNodeList;\r
29         //! Typedef for list of scene node animators\r
30         typedef core::list<ISceneNodeAnimator*> ISceneNodeAnimatorList;\r
31 \r
32         //! Scene node interface.\r
33         /** A scene node is a node in the hierarchical scene graph. Every scene\r
34         node may have children, which are also scene nodes. Children move\r
35         relative to their parent's position. If the parent of a node is not\r
36         visible, its children won't be visible either. In this way, it is for\r
37         example easily possible to attach a light to a moving car, or to place\r
38         a walking character on a moving platform on a moving ship.\r
39         */\r
40         class ISceneNode : virtual public io::IAttributeExchangingObject\r
41         {\r
42         public:\r
43 \r
44                 //! Constructor\r
45                 ISceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id=-1,\r
46                                 const core::vector3df& position = core::vector3df(0,0,0),\r
47                                 const core::vector3df& rotation = core::vector3df(0,0,0),\r
48                                 const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f))\r
49                         : RelativeTranslation(position), RelativeRotation(rotation), RelativeScale(scale),\r
50                                 Parent(0), SceneManager(mgr), TriangleSelector(0), ID(id),\r
51                                 AutomaticCullingState(EAC_BOX), DebugDataVisible(EDS_OFF),\r
52                                 IsVisible(true), IsDebugObject(false)\r
53                 {\r
54                         if (parent)\r
55                                 parent->addChild(this);\r
56 \r
57                         updateAbsolutePosition();\r
58                 }\r
59 \r
60 \r
61                 //! Destructor\r
62                 virtual ~ISceneNode()\r
63                 {\r
64                         // delete all children\r
65                         removeAll();\r
66 \r
67                         // delete all animators\r
68                         ISceneNodeAnimatorList::Iterator ait = Animators.begin();\r
69                         for (; ait != Animators.end(); ++ait)\r
70                                 (*ait)->drop();\r
71 \r
72                         if (TriangleSelector)\r
73                                 TriangleSelector->drop();\r
74                 }\r
75 \r
76 \r
77                 //! This method is called just before the rendering process of the whole scene.\r
78                 /** Nodes may register themselves in the render pipeline during this call,\r
79                 precalculate the geometry which should be renderered, and prevent their\r
80                 children from being able to register themselves if they are clipped by simply\r
81                 not calling their OnRegisterSceneNode method.\r
82                 If you are implementing your own scene node, you should overwrite this method\r
83                 with an implementation code looking like this:\r
84                 \code\r
85                 if (IsVisible)\r
86                         SceneManager->registerNodeForRendering(this);\r
87 \r
88                 ISceneNode::OnRegisterSceneNode();\r
89                 \endcode\r
90                 */\r
91                 virtual void OnRegisterSceneNode()\r
92                 {\r
93                         if (IsVisible)\r
94                         {\r
95                                 ISceneNodeList::Iterator it = Children.begin();\r
96                                 for (; it != Children.end(); ++it)\r
97                                         (*it)->OnRegisterSceneNode();\r
98                         }\r
99                 }\r
100 \r
101 \r
102                 //! OnAnimate() is called just before rendering the whole scene.\r
103                 /** Nodes may calculate or store animations here, and may do other useful things,\r
104                 depending on what they are. Also, OnAnimate() should be called for all\r
105                 child scene nodes here. This method will be called once per frame, independent\r
106                 of whether the scene node is visible or not.\r
107                 \param timeMs Current time in milliseconds. */\r
108                 virtual void OnAnimate(u32 timeMs)\r
109                 {\r
110                         if (IsVisible)\r
111                         {\r
112                                 // animate this node with all animators\r
113 \r
114                                 ISceneNodeAnimatorList::Iterator ait = Animators.begin();\r
115                                 while (ait != Animators.end())\r
116                                         {\r
117                                         // continue to the next node before calling animateNode()\r
118                                         // so that the animator may remove itself from the scene\r
119                                         // node without the iterator becoming invalid\r
120                                         ISceneNodeAnimator* anim = *ait;\r
121                                         ++ait;\r
122                                         if ( anim->isEnabled() )\r
123                                         {\r
124                                                 anim->animateNode(this, timeMs);\r
125                                         }\r
126                                 }\r
127 \r
128                                 // update absolute position\r
129                                 updateAbsolutePosition();\r
130 \r
131                                 // perform the post render process on all children\r
132 \r
133                                 ISceneNodeList::Iterator it = Children.begin();\r
134                                 for (; it != Children.end(); ++it)\r
135                                         (*it)->OnAnimate(timeMs);\r
136                         }\r
137                 }\r
138 \r
139 \r
140                 //! Renders the node.\r
141                 virtual void render() = 0;\r
142 \r
143 \r
144                 //! Returns the name of the node.\r
145                 /** \return Name as character string. */\r
146                 virtual const c8* getName() const\r
147                 {\r
148                         return Name.c_str();\r
149                 }\r
150 \r
151 \r
152                 //! Sets the name of the node.\r
153                 /** \param name New name of the scene node. */\r
154                 virtual void setName(const c8* name)\r
155                 {\r
156                         Name = name;\r
157                 }\r
158 \r
159 \r
160                 //! Sets the name of the node.\r
161                 /** \param name New name of the scene node. */\r
162                 virtual void setName(const core::stringc& name)\r
163                 {\r
164                         Name = name;\r
165                 }\r
166 \r
167 \r
168                 //! Get the axis aligned, not transformed bounding box of this node.\r
169                 /** This means that if this node is an animated 3d character,\r
170                 moving in a room, the bounding box will always be around the\r
171                 origin. To get the box in real world coordinates, just\r
172                 transform it with the matrix you receive with\r
173                 getAbsoluteTransformation() or simply use\r
174                 getTransformedBoundingBox(), which does the same.\r
175                 \return The non-transformed bounding box. */\r
176                 virtual const core::aabbox3d<f32>& getBoundingBox() const = 0;\r
177 \r
178 \r
179                 //! Get the axis aligned, transformed and animated absolute bounding box of this node.\r
180                 /** Note: The result is still an axis-aligned bounding box, so it's size\r
181                 changes with rotation.\r
182                 \return The transformed bounding box. */\r
183                 virtual const core::aabbox3d<f32> getTransformedBoundingBox() const\r
184                 {\r
185                         core::aabbox3d<f32> box = getBoundingBox();\r
186                         AbsoluteTransformation.transformBoxEx(box);\r
187                         return box;\r
188                 }\r
189 \r
190                 //! Get a the 8 corners of the original bounding box transformed and\r
191                 //! animated by the absolute transformation.\r
192                 /** Note: The result is _not_ identical to getTransformedBoundingBox().getEdges(),\r
193                 but getting an aabbox3d of these edges would then be identical.\r
194                 \param edges Receives an array with the transformed edges */\r
195                 virtual void getTransformedBoundingBoxEdges(core::array< core::vector3d<f32> >& edges) const\r
196                 {\r
197                         edges.set_used(8);\r
198                         getBoundingBox().getEdges( edges.pointer() );\r
199                         for ( u32 i=0; i<8; ++i )\r
200                                 AbsoluteTransformation.transformVect( edges[i] );\r
201                 }\r
202 \r
203                 //! Get the absolute transformation of the node. Is recalculated every OnAnimate()-call.\r
204                 /** NOTE: For speed reasons the absolute transformation is not\r
205                 automatically recalculated on each change of the relative\r
206                 transformation or by a transformation change of an parent. Instead the\r
207                 update usually happens once per frame in OnAnimate. You can enforce\r
208                 an update with updateAbsolutePosition().\r
209                 \return The absolute transformation matrix. */\r
210                 virtual const core::matrix4& getAbsoluteTransformation() const\r
211                 {\r
212                         return AbsoluteTransformation;\r
213                 }\r
214 \r
215 \r
216                 //! Returns the relative transformation of the scene node.\r
217                 /** The relative transformation is stored internally as 3\r
218                 vectors: translation, rotation and scale. To get the relative\r
219                 transformation matrix, it is calculated from these values.\r
220                 \return The relative transformation matrix. */\r
221                 virtual core::matrix4 getRelativeTransformation() const\r
222                 {\r
223                         core::matrix4 mat;\r
224                         mat.setRotationDegrees(RelativeRotation);\r
225                         mat.setTranslation(RelativeTranslation);\r
226 \r
227                         if (RelativeScale != core::vector3df(1.f,1.f,1.f))\r
228                         {\r
229                                 core::matrix4 smat;\r
230                                 smat.setScale(RelativeScale);\r
231                                 mat *= smat;\r
232                         }\r
233 \r
234                         return mat;\r
235                 }\r
236 \r
237 \r
238                 //! Returns whether the node should be visible (if all of its parents are visible).\r
239                 /** This is only an option set by the user, but has nothing to\r
240                 do with geometry culling\r
241                 \return The requested visibility of the node, true means\r
242                 visible (if all parents are also visible). */\r
243                 virtual bool isVisible() const\r
244                 {\r
245                         return IsVisible;\r
246                 }\r
247 \r
248                 //! Check whether the node is truly visible, taking into accounts its parents' visibility\r
249                 /** \return true if the node and all its parents are visible,\r
250                 false if this or any parent node is invisible. */\r
251                 virtual bool isTrulyVisible() const\r
252                 {\r
253                         if(!IsVisible)\r
254                                 return false;\r
255 \r
256                         if(!Parent)\r
257                                 return true;\r
258 \r
259                         return Parent->isTrulyVisible();\r
260                 }\r
261 \r
262                 //! Sets if the node should be visible or not.\r
263                 /** All children of this node won't be visible either, when set\r
264                 to false. Invisible nodes are not valid candidates for selection by\r
265                 collision manager bounding box methods.\r
266                 \param isVisible If the node shall be visible. */\r
267                 virtual void setVisible(bool isVisible)\r
268                 {\r
269                         IsVisible = isVisible;\r
270                 }\r
271 \r
272 \r
273                 //! Get the id of the scene node.\r
274                 /** This id can be used to identify the node.\r
275                 \return The id. */\r
276                 virtual s32 getID() const\r
277                 {\r
278                         return ID;\r
279                 }\r
280 \r
281 \r
282                 //! Sets the id of the scene node.\r
283                 /** This id can be used to identify the node.\r
284                 \param id The new id. */\r
285                 virtual void setID(s32 id)\r
286                 {\r
287                         ID = id;\r
288                 }\r
289 \r
290 \r
291                 //! Adds a child to this scene node.\r
292                 /** If the scene node already has a parent it is first removed\r
293                 from the other parent.\r
294                 \param child A pointer to the new child. */\r
295                 virtual void addChild(ISceneNode* child)\r
296                 {\r
297                         if (child && (child != this))\r
298                         {\r
299                                 // Change scene manager?\r
300                                 if (SceneManager != child->SceneManager)\r
301                                         child->setSceneManager(SceneManager);\r
302 \r
303                                 child->grab();\r
304                                 child->remove(); // remove from old parent\r
305                                 Children.push_back(child);\r
306                                 child->Parent = this;\r
307                         }\r
308                 }\r
309 \r
310 \r
311                 //! Removes a child from this scene node.\r
312                 /** If found in the children list, the child pointer is also\r
313                 dropped and might be deleted if no other grab exists.\r
314                 \param child A pointer to the child which shall be removed.\r
315                 \return True if the child was removed, and false if not,\r
316                 e.g. because it couldn't be found in the children list. */\r
317                 virtual bool removeChild(ISceneNode* child)\r
318                 {\r
319                         ISceneNodeList::Iterator it = Children.begin();\r
320                         for (; it != Children.end(); ++it)\r
321                                 if ((*it) == child)\r
322                                 {\r
323                                         (*it)->Parent = 0;\r
324                                         (*it)->drop();\r
325                                         Children.erase(it);\r
326                                         return true;\r
327                                 }\r
328 \r
329                         return false;\r
330                 }\r
331 \r
332 \r
333                 //! Removes all children of this scene node\r
334                 /** The scene nodes found in the children list are also dropped\r
335                 and might be deleted if no other grab exists on them.\r
336                 */\r
337                 virtual void removeAll()\r
338                 {\r
339                         ISceneNodeList::Iterator it = Children.begin();\r
340                         for (; it != Children.end(); ++it)\r
341                         {\r
342                                 (*it)->Parent = 0;\r
343                                 (*it)->drop();\r
344                         }\r
345 \r
346                         Children.clear();\r
347                 }\r
348 \r
349 \r
350                 //! Removes this scene node from the scene\r
351                 /** If no other grab exists for this node, it will be deleted.\r
352                 */\r
353                 virtual void remove()\r
354                 {\r
355                         if (Parent)\r
356                                 Parent->removeChild(this);\r
357                 }\r
358 \r
359 \r
360                 //! Adds an animator which should animate this node.\r
361                 /** \param animator A pointer to the new animator. */\r
362                 virtual void addAnimator(ISceneNodeAnimator* animator)\r
363                 {\r
364                         if (animator)\r
365                         {\r
366                                 Animators.push_back(animator);\r
367                                 animator->grab();\r
368                         }\r
369                 }\r
370 \r
371 \r
372                 //! Get a list of all scene node animators.\r
373                 /** \return The list of animators attached to this node. */\r
374                 const core::list<ISceneNodeAnimator*>& getAnimators() const\r
375                 {\r
376                         return Animators;\r
377                 }\r
378 \r
379 \r
380                 //! Removes an animator from this scene node.\r
381                 /** If the animator is found, it is also dropped and might be\r
382                 deleted if not other grab exists for it.\r
383                 \param animator A pointer to the animator to be deleted. */\r
384                 virtual void removeAnimator(ISceneNodeAnimator* animator)\r
385                 {\r
386                         ISceneNodeAnimatorList::Iterator it = Animators.begin();\r
387                         for (; it != Animators.end(); ++it)\r
388                         {\r
389                                 if ((*it) == animator)\r
390                                 {\r
391                                         (*it)->drop();\r
392                                         Animators.erase(it);\r
393                                         return;\r
394                                 }\r
395                         }\r
396                 }\r
397 \r
398 \r
399                 //! Removes all animators from this scene node.\r
400                 /** The animators might also be deleted if no other grab exists\r
401                 for them. */\r
402                 virtual void removeAnimators()\r
403                 {\r
404                         ISceneNodeAnimatorList::Iterator it = Animators.begin();\r
405                         for (; it != Animators.end(); ++it)\r
406                                 (*it)->drop();\r
407 \r
408                         Animators.clear();\r
409                 }\r
410 \r
411 \r
412                 //! Returns the material based on the zero based index i.\r
413                 /** To get the amount of materials used by this scene node, use\r
414                 getMaterialCount(). This function is needed for inserting the\r
415                 node into the scene hierarchy at an optimal position for\r
416                 minimizing renderstate changes, but can also be used to\r
417                 directly modify the material of a scene node.\r
418                 \param num Zero based index. The maximal value is getMaterialCount() - 1.\r
419                 \return The material at that index. */\r
420                 virtual video::SMaterial& getMaterial(u32 num)\r
421                 {\r
422                         return video::IdentityMaterial;\r
423                 }\r
424 \r
425 \r
426                 //! Get amount of materials used by this scene node.\r
427                 /** \return Current amount of materials of this scene node. */\r
428                 virtual u32 getMaterialCount() const\r
429                 {\r
430                         return 0;\r
431                 }\r
432 \r
433 \r
434                 //! Sets all material flags at once to a new value.\r
435                 /** Useful, for example, if you want the whole mesh to be\r
436                 affected by light.\r
437                 \param flag Which flag of all materials to be set.\r
438                 \param newvalue New value of that flag. */\r
439                 void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)\r
440                 {\r
441                         for (u32 i=0; i<getMaterialCount(); ++i)\r
442                                 getMaterial(i).setFlag(flag, newvalue);\r
443                 }\r
444 \r
445 \r
446                 //! Sets the texture of the specified layer in all materials of this scene node to the new texture.\r
447                 /** \param textureLayer Layer of texture to be set. Must be a\r
448                 value smaller than MATERIAL_MAX_TEXTURES.\r
449                 \param texture New texture to be used. */\r
450                 void setMaterialTexture(u32 textureLayer, video::ITexture* texture)\r
451                 {\r
452                         if (textureLayer >= video::MATERIAL_MAX_TEXTURES)\r
453                                 return;\r
454 \r
455                         for (u32 i=0; i<getMaterialCount(); ++i)\r
456                                 getMaterial(i).setTexture(textureLayer, texture);\r
457                 }\r
458 \r
459 \r
460                 //! Sets the material type of all materials in this scene node to a new material type.\r
461                 /** \param newType New type of material to be set. */\r
462                 void setMaterialType(video::E_MATERIAL_TYPE newType)\r
463                 {\r
464                         for (u32 i=0; i<getMaterialCount(); ++i)\r
465                                 getMaterial(i).MaterialType = newType;\r
466                 }\r
467 \r
468 \r
469                 //! Gets the scale of the scene node relative to its parent.\r
470                 /** This is the scale of this node relative to its parent.\r
471                 If you want the absolute scale, use\r
472                 getAbsoluteTransformation().getScale()\r
473                 \return The scale of the scene node. */\r
474                 virtual const core::vector3df& getScale() const\r
475                 {\r
476                         return RelativeScale;\r
477                 }\r
478 \r
479 \r
480                 //! Sets the relative scale of the scene node.\r
481                 /** \param scale New scale of the node, relative to its parent. */\r
482                 virtual void setScale(const core::vector3df& scale)\r
483                 {\r
484                         RelativeScale = scale;\r
485                 }\r
486 \r
487 \r
488                 //! Gets the rotation of the node relative to its parent.\r
489                 /** Note that this is the relative rotation of the node.\r
490                 If you want the absolute rotation, use\r
491                 getAbsoluteTransformation().getRotation()\r
492                 \return Current relative rotation of the scene node. */\r
493                 virtual const core::vector3df& getRotation() const\r
494                 {\r
495                         return RelativeRotation;\r
496                 }\r
497 \r
498 \r
499                 //! Sets the rotation of the node relative to its parent.\r
500                 /** This only modifies the relative rotation of the node.\r
501                 \param rotation New rotation of the node in degrees. */\r
502                 virtual void setRotation(const core::vector3df& rotation)\r
503                 {\r
504                         RelativeRotation = rotation;\r
505                 }\r
506 \r
507 \r
508                 //! Gets the position of the node relative to its parent.\r
509                 /** Note that the position is relative to the parent. If you want\r
510                 the position in world coordinates, use getAbsolutePosition() instead.\r
511                 \return The current position of the node relative to the parent. */\r
512                 virtual const core::vector3df& getPosition() const\r
513                 {\r
514                         return RelativeTranslation;\r
515                 }\r
516 \r
517 \r
518                 //! Sets the position of the node relative to its parent.\r
519                 /** Note that the position is relative to the parent.\r
520                 \param newpos New relative position of the scene node. */\r
521                 virtual void setPosition(const core::vector3df& newpos)\r
522                 {\r
523                         RelativeTranslation = newpos;\r
524                 }\r
525 \r
526 \r
527                 //! Gets the absolute position of the node in world coordinates.\r
528                 /** If you want the position of the node relative to its parent,\r
529                 use getPosition() instead.\r
530                 NOTE: For speed reasons the absolute position is not\r
531                 automatically recalculated on each change of the relative\r
532                 position or by a position change of an parent. Instead the\r
533                 update usually happens once per frame in OnAnimate. You can enforce\r
534                 an update with updateAbsolutePosition().\r
535                 \return The current absolute position of the scene node (updated on last call of updateAbsolutePosition). */\r
536                 virtual core::vector3df getAbsolutePosition() const\r
537                 {\r
538                         return AbsoluteTransformation.getTranslation();\r
539                 }\r
540 \r
541 \r
542                 //! Set a culling style or disable culling completely.\r
543                 /** Box cullling (EAC_BOX) is set by default. Note that not\r
544                 all SceneNodes support culling and that some nodes always cull\r
545                 their geometry because it is their only reason for existence,\r
546                 for example the OctreeSceneNode.\r
547                 \param state The culling state to be used. Check E_CULLING_TYPE for possible values.*/\r
548                 void setAutomaticCulling( u32 state)\r
549                 {\r
550                         AutomaticCullingState = state;\r
551                 }\r
552 \r
553 \r
554                 //! Gets the automatic culling state.\r
555                 /** \return The automatic culling state. */\r
556                 u32 getAutomaticCulling() const\r
557                 {\r
558                         return AutomaticCullingState;\r
559                 }\r
560 \r
561 \r
562                 //! Sets if debug data like bounding boxes should be drawn.\r
563                 /** A bitwise OR of the types from @ref irr::scene::E_DEBUG_SCENE_TYPE.\r
564                 Please note that not all scene nodes support all debug data types.\r
565                 \param state The debug data visibility state to be used. */\r
566                 virtual void setDebugDataVisible(u32 state)\r
567                 {\r
568                         DebugDataVisible = state;\r
569                 }\r
570 \r
571                 //! Returns if debug data like bounding boxes are drawn.\r
572                 /** \return A bitwise OR of the debug data values from\r
573                 @ref irr::scene::E_DEBUG_SCENE_TYPE that are currently visible. */\r
574                 u32 isDebugDataVisible() const\r
575                 {\r
576                         return DebugDataVisible;\r
577                 }\r
578 \r
579 \r
580                 //! Sets if this scene node is a debug object.\r
581                 /** Debug objects have some special properties, for example they can be easily\r
582                 excluded from collision detection or from serialization, etc. */\r
583                 void setIsDebugObject(bool debugObject)\r
584                 {\r
585                         IsDebugObject = debugObject;\r
586                 }\r
587 \r
588 \r
589                 //! Returns if this scene node is a debug object.\r
590                 /** Debug objects have some special properties, for example they can be easily\r
591                 excluded from collision detection or from serialization, etc.\r
592                 \return If this node is a debug object, true is returned. */\r
593                 bool isDebugObject() const\r
594                 {\r
595                         return IsDebugObject;\r
596                 }\r
597 \r
598 \r
599                 //! Returns a const reference to the list of all children.\r
600                 /** \return The list of all children of this node. */\r
601                 const core::list<ISceneNode*>& getChildren() const\r
602                 {\r
603                         return Children;\r
604                 }\r
605 \r
606 \r
607                 //! Changes the parent of the scene node.\r
608                 /** \param newParent The new parent to be used. */\r
609                 virtual void setParent(ISceneNode* newParent)\r
610                 {\r
611                         grab();\r
612                         remove();\r
613 \r
614                         Parent = newParent;\r
615 \r
616                         if (Parent)\r
617                                 Parent->addChild(this);\r
618 \r
619                         drop();\r
620                 }\r
621 \r
622 \r
623                 //! Returns the triangle selector attached to this scene node.\r
624                 /** The Selector can be used by the engine for doing collision\r
625                 detection. You can create a TriangleSelector with\r
626                 ISceneManager::createTriangleSelector() or\r
627                 ISceneManager::createOctreeTriangleSelector and set it with\r
628                 ISceneNode::setTriangleSelector(). If a scene node got no triangle\r
629                 selector, but collision tests should be done with it, a triangle\r
630                 selector is created using the bounding box of the scene node.\r
631                 \return A pointer to the TriangleSelector or 0, if there\r
632                 is none. */\r
633                 virtual ITriangleSelector* getTriangleSelector() const\r
634                 {\r
635                         return TriangleSelector;\r
636                 }\r
637 \r
638 \r
639                 //! Sets the triangle selector of the scene node.\r
640                 /** The Selector can be used by the engine for doing collision\r
641                 detection. You can create a TriangleSelector with\r
642                 ISceneManager::createTriangleSelector() or\r
643                 ISceneManager::createOctreeTriangleSelector(). Some nodes may\r
644                 create their own selector by default, so it would be good to\r
645                 check if there is already a selector in this node by calling\r
646                 ISceneNode::getTriangleSelector().\r
647                 \param selector New triangle selector for this scene node. */\r
648                 virtual void setTriangleSelector(ITriangleSelector* selector)\r
649                 {\r
650                         if (TriangleSelector != selector)\r
651                         {\r
652                                 if (TriangleSelector)\r
653                                         TriangleSelector->drop();\r
654 \r
655                                 TriangleSelector = selector;\r
656                                 if (TriangleSelector)\r
657                                         TriangleSelector->grab();\r
658                         }\r
659                 }\r
660 \r
661 \r
662                 //! Updates the absolute position based on the relative and the parents position\r
663                 /** Note: This does not recursively update the parents absolute positions, so if you have a deeper\r
664                         hierarchy you might want to update the parents first.*/\r
665                 virtual void updateAbsolutePosition()\r
666                 {\r
667                         if (Parent)\r
668                         {\r
669                                 AbsoluteTransformation =\r
670                                         Parent->getAbsoluteTransformation() * getRelativeTransformation();\r
671                         }\r
672                         else\r
673                                 AbsoluteTransformation = getRelativeTransformation();\r
674                 }\r
675 \r
676 \r
677                 //! Returns the parent of this scene node\r
678                 /** \return A pointer to the parent. */\r
679                 scene::ISceneNode* getParent() const\r
680                 {\r
681                         return Parent;\r
682                 }\r
683 \r
684 \r
685                 //! Returns type of the scene node\r
686                 /** \return The type of this node. */\r
687                 virtual ESCENE_NODE_TYPE getType() const\r
688                 {\r
689                         return ESNT_UNKNOWN;\r
690                 }\r
691 \r
692 \r
693                 //! Writes attributes of the scene node.\r
694                 /** Implement this to expose the attributes of your scene node\r
695                 for scripting languages, editors, debuggers or xml\r
696                 serialization purposes.\r
697                 \param out The attribute container to write into.\r
698                 \param options Additional options which might influence the\r
699                 serialization. */\r
700                 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const _IRR_OVERRIDE_\r
701                 {\r
702                         if (!out)\r
703                                 return;\r
704                         out->addString("Name", Name.c_str());\r
705                         out->addInt("Id", ID );\r
706 \r
707                         out->addVector3d("Position", getPosition() );\r
708                         out->addVector3d("Rotation", getRotation() );\r
709                         out->addVector3d("Scale", getScale() );\r
710 \r
711                         out->addBool("Visible", IsVisible );\r
712                         out->addInt("AutomaticCulling", AutomaticCullingState);\r
713                         out->addInt("DebugDataVisible", DebugDataVisible );\r
714                         out->addBool("IsDebugObject", IsDebugObject );\r
715                 }\r
716 \r
717 \r
718                 //! Reads attributes of the scene node.\r
719                 /** Implement this to set the attributes of your scene node for\r
720                 scripting languages, editors, debuggers or xml deserialization\r
721                 purposes.\r
722                 \param in The attribute container to read from.\r
723                 \param options Additional options which might influence the\r
724                 deserialization. */\r
725                 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) _IRR_OVERRIDE_\r
726                 {\r
727                         if (!in)\r
728                                 return;\r
729                         Name = in->getAttributeAsString("Name", Name);\r
730                         ID = in->getAttributeAsInt("Id", ID);\r
731 \r
732                         setPosition(in->getAttributeAsVector3d("Position", RelativeTranslation));\r
733                         setRotation(in->getAttributeAsVector3d("Rotation", RelativeRotation));\r
734                         setScale(in->getAttributeAsVector3d("Scale", RelativeScale));\r
735 \r
736                         IsVisible = in->getAttributeAsBool("Visible", IsVisible);\r
737                         if (in->existsAttribute("AutomaticCulling"))\r
738                         {\r
739                                 s32 tmpState = in->getAttributeAsEnumeration("AutomaticCulling",\r
740                                                 scene::AutomaticCullingNames);\r
741                                 if (tmpState != -1)\r
742                                         AutomaticCullingState = (u32)tmpState;\r
743                                 else\r
744                                         AutomaticCullingState = in->getAttributeAsInt("AutomaticCulling");\r
745                         }\r
746 \r
747                         DebugDataVisible = in->getAttributeAsInt("DebugDataVisible", DebugDataVisible);\r
748                         IsDebugObject = in->getAttributeAsBool("IsDebugObject", IsDebugObject);\r
749 \r
750                         updateAbsolutePosition();\r
751                 }\r
752 \r
753                 //! Creates a clone of this scene node and its children.\r
754                 /** \param newParent An optional new parent.\r
755                 \param newManager An optional new scene manager.\r
756                 \return The newly created clone of this node. */\r
757                 virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0)\r
758                 {\r
759                         return 0; // to be implemented by derived classes\r
760                 }\r
761 \r
762                 //! Retrieve the scene manager for this node.\r
763                 /** \return The node's scene manager. */\r
764                 virtual ISceneManager* getSceneManager(void) const { return SceneManager; }\r
765 \r
766         protected:\r
767 \r
768                 //! A clone function for the ISceneNode members.\r
769                 /** This method can be used by clone() implementations of\r
770                 derived classes\r
771                 \param toCopyFrom The node from which the values are copied\r
772                 \param newManager The new scene manager. */\r
773                 void cloneMembers(ISceneNode* toCopyFrom, ISceneManager* newManager)\r
774                 {\r
775                         Name = toCopyFrom->Name;\r
776                         AbsoluteTransformation = toCopyFrom->AbsoluteTransformation;\r
777                         RelativeTranslation = toCopyFrom->RelativeTranslation;\r
778                         RelativeRotation = toCopyFrom->RelativeRotation;\r
779                         RelativeScale = toCopyFrom->RelativeScale;\r
780                         ID = toCopyFrom->ID;\r
781                         setTriangleSelector(toCopyFrom->TriangleSelector);\r
782                         AutomaticCullingState = toCopyFrom->AutomaticCullingState;\r
783                         DebugDataVisible = toCopyFrom->DebugDataVisible;\r
784                         IsVisible = toCopyFrom->IsVisible;\r
785                         IsDebugObject = toCopyFrom->IsDebugObject;\r
786 \r
787                         if (newManager)\r
788                                 SceneManager = newManager;\r
789                         else\r
790                                 SceneManager = toCopyFrom->SceneManager;\r
791 \r
792                         // clone children\r
793 \r
794                         ISceneNodeList::Iterator it = toCopyFrom->Children.begin();\r
795                         for (; it != toCopyFrom->Children.end(); ++it)\r
796                                 (*it)->clone(this, newManager);\r
797 \r
798                         // clone animators\r
799 \r
800                         ISceneNodeAnimatorList::Iterator ait = toCopyFrom->Animators.begin();\r
801                         for (; ait != toCopyFrom->Animators.end(); ++ait)\r
802                         {\r
803                                 ISceneNodeAnimator* anim = (*ait)->createClone(this, SceneManager);\r
804                                 if (anim)\r
805                                 {\r
806                                         addAnimator(anim);\r
807                                         anim->drop();\r
808                                 }\r
809                         }\r
810                 }\r
811 \r
812                 //! Sets the new scene manager for this node and all children.\r
813                 //! Called by addChild when moving nodes between scene managers\r
814                 void setSceneManager(ISceneManager* newManager)\r
815                 {\r
816                         SceneManager = newManager;\r
817 \r
818                         ISceneNodeList::Iterator it = Children.begin();\r
819                         for (; it != Children.end(); ++it)\r
820                                 (*it)->setSceneManager(newManager);\r
821                 }\r
822 \r
823                 //! Name of the scene node.\r
824                 core::stringc Name;\r
825 \r
826                 //! Absolute transformation of the node.\r
827                 core::matrix4 AbsoluteTransformation;\r
828 \r
829                 //! Relative translation of the scene node.\r
830                 core::vector3df RelativeTranslation;\r
831 \r
832                 //! Relative rotation of the scene node.\r
833                 core::vector3df RelativeRotation;\r
834 \r
835                 //! Relative scale of the scene node.\r
836                 core::vector3df RelativeScale;\r
837 \r
838                 //! Pointer to the parent\r
839                 ISceneNode* Parent;\r
840 \r
841                 //! List of all children of this node\r
842                 core::list<ISceneNode*> Children;\r
843 \r
844                 //! List of all animator nodes\r
845                 core::list<ISceneNodeAnimator*> Animators;\r
846 \r
847                 //! Pointer to the scene manager\r
848                 ISceneManager* SceneManager;\r
849 \r
850                 //! Pointer to the triangle selector\r
851                 ITriangleSelector* TriangleSelector;\r
852 \r
853                 //! ID of the node.\r
854                 s32 ID;\r
855 \r
856                 //! Automatic culling state\r
857                 u32 AutomaticCullingState;\r
858 \r
859                 //! Flag if debug data should be drawn, such as Bounding Boxes.\r
860                 u32 DebugDataVisible;\r
861 \r
862                 //! Is the node visible?\r
863                 bool IsVisible;\r
864 \r
865                 //! Is debug object?\r
866                 bool IsDebugObject;\r
867         };\r
868 \r
869 \r
870 } // end namespace scene\r
871 } // end namespace irr\r
872 \r
873 #endif\r
874 \r