Page 1 of 1

Questions on how to use the list and array in irrlicht

Posted: Tue Dec 23, 2008 10:52 pm
by Daystar
I would like to ask if anyone could help me with different examples of how to use the array and list functions in the irrlicht system?

Posted: Wed Dec 24, 2008 3:46 am
by vitek
Yes. What would you like to know?

Travis

Posted: Wed Dec 24, 2008 9:22 pm
by Daystar
I wanted to know if someone could give me some examples of using them.

Posted: Wed Dec 24, 2008 9:40 pm
by Ion Dune
From scene::ISceneNode for lists:

Code: Select all

00308                 virtual void addAnimator(ISceneNodeAnimator* animator)
00309                 {
00310                         if (animator)
00311                         {
00312                                 Animators.push_back(animator);
00313                                 animator->grab();
00314                         }
00315                 }

Code: Select all

00328                 virtual void removeAnimator(ISceneNodeAnimator* animator)
00329                 {
00330                         core::list<ISceneNodeAnimator*>::Iterator it = Animators.begin();
00331                         for (; it != Animators.end(); ++it)
00332                                 if ((*it) == animator)
00333                                 {
00334                                         (*it)->drop();
00335                                         Animators.erase(it);
00336                                         return;
00337                                 }
00338                 }
And an array example, courtesy of me :) :) :)

Code: Select all

core::array< f32 > floats ;
floats.push_back( 10.f ) ; // adds a float to the end
floats.push_back( 11.f ) ; // another to the end
floats.push_front( 9.f ) ; // adds a float to the front of the array
floats[1] = 100.f ; // changes the second value ( currently 10.f ) to 100.f
for ( u32 t = 0 ; t < floats.size() ; ++ t )
floats[t] += 1.0f ; // adds one to every member of the array

Posted: Thu Dec 25, 2008 12:04 am
by monchito
Here is one...

Code: Select all

list<ISceneNode*>NodeList;  // Create node list.

// create some cubes, fill the list     
void AddCubeNode(const s32 qty)
{
  ISceneNode* cube;
  
  for(s32 i = 0; i < qty; i++)
  {
    cube = smgr->addCubeSceneNode();
    // set random position
    cube->setPosition(vector3df( Random(), Random(), Random()));
    NodeList.push_front(cube);
  }
}

// test collision one node with the list
// select bool for yes/no  or ISceneNode* for who is colliding
bool CubeNodeCollision(ISceneNode* n)
{
  aabbox3df box = n->getTransformedBoundingBox();
  
  core::list<ISceneNode*>::Iterator it = NodeList.begin();
  for (; it != NodeList.end(); ++it)
  {    
     if(box.intersectsWithBox((*it)->getTransformedBoundingBox()))
        return true;    // return (*it);
  }
  return false;        // NULL;
}



Posted: Thu Dec 25, 2008 12:55 am
by Daystar
Thanks you guys these examples really helped!

Posted: Thu Dec 25, 2008 8:17 pm
by Katsankat
There is an array of struct SParticleImpact in the demo if I remember correctly.