Automatic node creation

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Netan MalDoran
Posts: 5
Joined: Sat Aug 08, 2015 6:18 am

Automatic node creation

Post by Netan MalDoran »

So for a game that I am creating, I have an array in the engine that defines all of the entities' existances (Or lack of) and their positions. I want to be able to have irrlicht automatically generate these as nodes, but the number is not static.
This is something that I am trying to do:
while(loop){
IAnimatedMeshSceneNode* ship[loop] = smgr->addAnimatedMeshSceneNode( mesh );
loop++;
}
Where the node variable (ship[loop]) is an array so that you can incrementally generate the world. I have tried using an array but it gave me errors, any ideas?
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Automatic node creation

Post by Seven »

you could use a list<ISceneNode*> which will grow dynamically

list<ISceneNode*> myList;

while(loop)
{
IAnimatedMeshSceneNode* ship = smgr->addAnimatedMeshSceneNode( mesh );
myList.push_back(ship);

// some way of breaking the loop here
}
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Automatic node creation

Post by CuteAlien »

irr::core::array or std::vector will also grow dynamically. And you should usually prefer one of those to using lists (arrays are way more cache-friendly which is so important that it tends to beat any advantages lists have theoretically).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Netan MalDoran
Posts: 5
Joined: Sat Aug 08, 2015 6:18 am

Re: Automatic node creation

Post by Netan MalDoran »

So, I've tried to use an array:
IAnimatedMesh* mesh = smgr->getMesh("C:\\Games\\Solaria\\graphics\\shipa.stl");
core::array<IAnimatedMeshSceneNode*> entity = smgr->addAnimatedMeshSceneNode( mesh );
entity[1]->setPosition(core::vector3df(0,0,0));
entity[1]->setMaterialTexture(0, driver->getTexture("C:\\Games\\Solaria\\graphics\\wall.bmp"));
entity[1]->setMaterialFlag(video::EMF_LIGHTING, false);
But it comes up with errors for line 2: invalid conversion from 'irr::scene::IAnimatedMeshSceneNode*' to 'irr::u32 {aka unsigned int}' [-fpermissive]
If I remove the ' = smgr->addAnimatedMeshSceneNode( mesh )' part, then the program opens then immediately crashes, is there syntax that I'm missing? Or am I just doing this wrong entirely?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Automatic node creation

Post by CuteAlien »

You're doing this wrong entirely ;-)
addAnimatedMeshSceneNode does not return a core::array<IAnimatedMeshSceneNode*> but a IAnimatedMeshSceneNode*. In c++ you always have to assign results to variables of the same type or to a derived type. But you can't assign a pointer to an array or stuff like that.
The way dynamic arrays like core::array or std::vector work is that you still have to tell it to create memory. The typical way is that you push_back the new element. So like that:

Code: Select all

 
core::array<IAnimatedMeshSceneNode*> nodes;
nodes.push_back(smgr->addAnimatedMeshSceneNode( mesh ) );
 
The next part is that arrays in c/c++ always start with 0. So your first element is nodes[0] not nodes[1] (or entity[0] but I think that's a bad variable name to use for nodes as entity has it's own meaning).

And some quick hints about paths. Don't work with absolute paths. For a start you can use relative paths which are already an improvement. Even better is to have a function to build your paths which starts with some flexible base-path which you can set at program start. Also use forward slashes instead of backslashes - it's less likely to mess that up accidentally and it's one step closer to writing applications that run cross-platform.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply