Questions on how to use the list and array in irrlicht
Questions on how to use the list and array in irrlicht
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?
DayStar
From scene::ISceneNode for lists:
And an array example, courtesy of me
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 }
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
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;
}