Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members | Tutorials
ISceneNode.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2010 Nikolaus Gebhardt
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
4 
5 #ifndef __I_SCENE_NODE_H_INCLUDED__
6 #define __I_SCENE_NODE_H_INCLUDED__
7 
9 #include "ESceneNodeTypes.h"
10 #include "ECullingTypes.h"
11 #include "EDebugSceneTypes.h"
12 #include "ISceneNodeAnimator.h"
13 #include "ITriangleSelector.h"
14 #include "SMaterial.h"
15 #include "irrString.h"
16 #include "aabbox3d.h"
17 #include "matrix4.h"
18 #include "irrList.h"
19 #include "IAttributes.h"
20 
21 namespace irr
22 {
23 namespace scene
24 {
26 
31 
33 
41  {
42  public:
43 
45  ISceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id=-1,
46  const core::vector3df& position = core::vector3df(0,0,0),
47  const core::vector3df& rotation = core::vector3df(0,0,0),
48  const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f))
49  : RelativeTranslation(position), RelativeRotation(rotation), RelativeScale(scale),
50  Parent(0), SceneManager(mgr), TriangleSelector(0), ID(id),
52  IsVisible(true), IsDebugObject(false)
53  {
54  if (parent)
55  parent->addChild(this);
56 
58  }
59 
60 
62  virtual ~ISceneNode()
63  {
64  // delete all children
65  removeAll();
66 
67  // delete all animators
68  ISceneNodeAnimatorList::Iterator ait = Animators.begin();
69  for (; ait != Animators.end(); ++ait)
70  (*ait)->drop();
71 
72  if (TriangleSelector)
74  }
75 
76 
78 
91  virtual void OnRegisterSceneNode()
92  {
93  if (IsVisible)
94  {
95  ISceneNodeList::Iterator it = Children.begin();
96  for (; it != Children.end(); ++it)
97  (*it)->OnRegisterSceneNode();
98  }
99  }
100 
101 
103 
108  virtual void OnAnimate(u32 timeMs)
109  {
110  if (IsVisible)
111  {
112  // animate this node with all animators
113 
114  ISceneNodeAnimatorList::Iterator ait = Animators.begin();
115  while (ait != Animators.end())
116  {
117  // continue to the next node before calling animateNode()
118  // so that the animator may remove itself from the scene
119  // node without the iterator becoming invalid
120  ISceneNodeAnimator* anim = *ait;
121  ++ait;
122  anim->animateNode(this, timeMs);
123  }
124 
125  // update absolute position
127 
128  // perform the post render process on all children
129 
130  ISceneNodeList::Iterator it = Children.begin();
131  for (; it != Children.end(); ++it)
132  (*it)->OnAnimate(timeMs);
133  }
134  }
135 
136 
138  virtual void render() = 0;
139 
140 
142 
143  virtual const c8* getName() const
144  {
145  return Name.c_str();
146  }
147 
148 
150 
151  virtual void setName(const c8* name)
152  {
153  Name = name;
154  }
155 
156 
158 
159  virtual void setName(const core::stringc& name)
160  {
161  Name = name;
162  }
163 
164 
166 
173  virtual const core::aabbox3d<f32>& getBoundingBox() const = 0;
174 
175 
177 
179  {
182  return box;
183  }
184 
185 
189  {
190  return AbsoluteTransformation;
191  }
192 
193 
195 
200  {
201  core::matrix4 mat;
204 
205  if (RelativeScale != core::vector3df(1.f,1.f,1.f))
206  {
207  core::matrix4 smat;
208  smat.setScale(RelativeScale);
209  mat *= smat;
210  }
211 
212  return mat;
213  }
214 
215 
217 
221  virtual bool isVisible() const
222  {
224  return IsVisible;
225  }
226 
228 
230  virtual bool isTrulyVisible() const
231  {
233  if(!IsVisible)
234  return false;
235 
236  if(!Parent)
237  return true;
238 
239  return Parent->isTrulyVisible();
240  }
241 
243 
247  virtual void setVisible(bool isVisible)
248  {
250  }
251 
252 
254 
256  virtual s32 getID() const
257  {
258  return ID;
259  }
260 
261 
263 
265  virtual void setID(s32 id)
266  {
267  ID = id;
268  }
269 
270 
272 
275  virtual void addChild(ISceneNode* child)
276  {
277  if (child && (child != this))
278  {
279  // Change scene manager?
280  if (SceneManager != child->SceneManager)
282 
283  child->grab();
284  child->remove(); // remove from old parent
285  Children.push_back(child);
286  child->Parent = this;
287  }
288  }
289 
290 
292 
297  virtual bool removeChild(ISceneNode* child)
298  {
299  ISceneNodeList::Iterator it = Children.begin();
300  for (; it != Children.end(); ++it)
301  if ((*it) == child)
302  {
303  (*it)->Parent = 0;
304  (*it)->drop();
305  Children.erase(it);
306  return true;
307  }
308 
310  return false;
311  }
312 
313 
315 
318  virtual void removeAll()
319  {
320  ISceneNodeList::Iterator it = Children.begin();
321  for (; it != Children.end(); ++it)
322  {
323  (*it)->Parent = 0;
324  (*it)->drop();
325  }
326 
327  Children.clear();
328  }
329 
330 
332 
334  virtual void remove()
335  {
336  if (Parent)
337  Parent->removeChild(this);
338  }
339 
340 
342 
343  virtual void addAnimator(ISceneNodeAnimator* animator)
344  {
345  if (animator)
346  {
347  Animators.push_back(animator);
348  animator->grab();
349  }
350  }
351 
352 
354 
356  {
357  return Animators;
358  }
359 
360 
362 
365  virtual void removeAnimator(ISceneNodeAnimator* animator)
366  {
367  ISceneNodeAnimatorList::Iterator it = Animators.begin();
368  for (; it != Animators.end(); ++it)
369  {
370  if ((*it) == animator)
371  {
372  (*it)->drop();
373  Animators.erase(it);
374  return;
375  }
376  }
377  }
378 
379 
381 
383  virtual void removeAnimators()
384  {
385  ISceneNodeAnimatorList::Iterator it = Animators.begin();
386  for (; it != Animators.end(); ++it)
387  (*it)->drop();
388 
389  Animators.clear();
390  }
391 
392 
394 
402  {
404  }
405 
406 
408 
409  virtual u32 getMaterialCount() const
410  {
411  return 0;
412  }
413 
414 
416 
420  void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
421  {
422  for (u32 i=0; i<getMaterialCount(); ++i)
423  getMaterial(i).setFlag(flag, newvalue);
424  }
425 
426 
428 
431  void setMaterialTexture(u32 textureLayer, video::ITexture* texture)
432  {
433  if (textureLayer >= video::MATERIAL_MAX_TEXTURES)
434  return;
435 
436  for (u32 i=0; i<getMaterialCount(); ++i)
437  getMaterial(i).setTexture(textureLayer, texture);
438  }
439 
440 
442 
444  {
445  for (u32 i=0; i<getMaterialCount(); ++i)
446  getMaterial(i).MaterialType = newType;
447  }
448 
449 
451 
455  virtual const core::vector3df& getScale() const
456  {
457  return RelativeScale;
458  }
459 
460 
462 
463  virtual void setScale(const core::vector3df& scale)
464  {
465  RelativeScale = scale;
466  }
467 
468 
470 
474  virtual const core::vector3df& getRotation() const
475  {
476  return RelativeRotation;
477  }
478 
479 
481 
483  virtual void setRotation(const core::vector3df& rotation)
484  {
485  RelativeRotation = rotation;
486  }
487 
488 
490 
493  virtual const core::vector3df& getPosition() const
494  {
495  return RelativeTranslation;
496  }
497 
498 
500 
502  virtual void setPosition(const core::vector3df& newpos)
503  {
504  RelativeTranslation = newpos;
505  }
506 
507 
509 
513  {
515  }
516 
517 
519 
525  {
526  AutomaticCullingState = state;
527  }
528 
529 
531 
533  {
535  return AutomaticCullingState;
536  }
537 
538 
540 
543  virtual void setDebugDataVisible(s32 state)
544  {
545  DebugDataVisible = state;
546  }
547 
549 
552  {
553  return DebugDataVisible;
554  }
555 
556 
558 
560  void setIsDebugObject(bool debugObject)
561  {
562  IsDebugObject = debugObject;
563  }
564 
565 
567 
570  bool isDebugObject() const
571  {
573  return IsDebugObject;
574  }
575 
576 
578 
580  {
581  return Children;
582  }
583 
584 
586 
587  virtual void setParent(ISceneNode* newParent)
588  {
589  grab();
590  remove();
591 
592  Parent = newParent;
593 
594  if (Parent)
595  Parent->addChild(this);
596 
597  drop();
598  }
599 
600 
602 
612  {
613  return TriangleSelector;
614  }
615 
616 
618 
626  virtual void setTriangleSelector(ITriangleSelector* selector)
627  {
628  if (TriangleSelector != selector)
629  {
630  if (TriangleSelector)
632 
633  TriangleSelector = selector;
634  if (TriangleSelector)
636  }
637  }
638 
639 
641 
643  virtual void updateAbsolutePosition()
644  {
645  if (Parent)
646  {
649  }
650  else
652  }
653 
654 
656 
658  {
659  return Parent;
660  }
661 
662 
664 
665  virtual ESCENE_NODE_TYPE getType() const
666  {
667  return ESNT_UNKNOWN;
668  }
669 
670 
672 
679  {
680  if (!out)
681  return;
682  out->addString ("Name", Name.c_str());
683  out->addInt ("Id", ID );
684 
685  out->addVector3d("Position", getPosition() );
686  out->addVector3d("Rotation", getRotation() );
687  out->addVector3d("Scale", getScale() );
688 
689  out->addBool ("Visible", IsVisible );
690  out->addEnum ("AutomaticCulling", AutomaticCullingState, AutomaticCullingNames);
691  out->addInt ("DebugDataVisible", DebugDataVisible );
692  out->addBool ("IsDebugObject", IsDebugObject );
693  }
694 
695 
697 
704  {
705  if (!in)
706  return;
707  Name = in->getAttributeAsString("Name");
708  ID = in->getAttributeAsInt("Id");
709 
710  setPosition(in->getAttributeAsVector3d("Position"));
711  setRotation(in->getAttributeAsVector3d("Rotation"));
712  setScale(in->getAttributeAsVector3d("Scale"));
713 
714  IsVisible = in->getAttributeAsBool("Visible");
717 
718  DebugDataVisible = in->getAttributeAsInt("DebugDataVisible");
719  IsDebugObject = in->getAttributeAsBool("IsDebugObject");
720 
722  }
723 
725 
728  virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0)
729  {
730  return 0; // to be implemented by derived classes
731  }
732 
734 
735  virtual ISceneManager* getSceneManager(void) const { return SceneManager; }
736 
737  protected:
738 
740 
744  void cloneMembers(ISceneNode* toCopyFrom, ISceneManager* newManager)
745  {
746  Name = toCopyFrom->Name;
749  RelativeRotation = toCopyFrom->RelativeRotation;
750  RelativeScale = toCopyFrom->RelativeScale;
751  ID = toCopyFrom->ID;
754  DebugDataVisible = toCopyFrom->DebugDataVisible;
755  IsVisible = toCopyFrom->IsVisible;
756  IsDebugObject = toCopyFrom->IsDebugObject;
757 
758  if (newManager)
759  SceneManager = newManager;
760  else
761  SceneManager = toCopyFrom->SceneManager;
762 
763  // clone children
764 
765  ISceneNodeList::Iterator it = toCopyFrom->Children.begin();
766  for (; it != toCopyFrom->Children.end(); ++it)
767  (*it)->clone(this, newManager);
768 
769  // clone animators
770 
771  ISceneNodeAnimatorList::Iterator ait = toCopyFrom->Animators.begin();
772  for (; ait != toCopyFrom->Animators.end(); ++ait)
773  {
774  ISceneNodeAnimator* anim = (*ait)->createClone(this, SceneManager);
775  if (anim)
776  {
777  addAnimator(anim);
778  anim->drop();
779  }
780  }
781  }
782 
785  void setSceneManager(ISceneManager* newManager)
786  {
787  SceneManager = newManager;
788 
789  ISceneNodeList::Iterator it = Children.begin();
790  for (; it != Children.end(); ++it)
791  (*it)->setSceneManager(newManager);
792  }
793 
796 
799 
802 
805 
808 
811 
814 
817 
820 
823 
826 
829 
832 
834  bool IsVisible;
835 
838  };
839 
840 
841 } // end namespace scene
842 } // end namespace irr
843 
844 #endif
845 

The Irrlicht Engine
The Irrlicht Engine Documentation © 2003-2010 by Nikolaus Gebhardt. Generated on Tue Jun 5 2012 17:57:13 by Doxygen (1.8.1)