Re. Creating an array of mesh nodes is it possible

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
DGENXP
Posts: 124
Joined: Tue Dec 27, 2005 2:49 am
Contact:

Re. Creating an array of mesh nodes is it possible

Post by DGENXP »

Hi I am trying to creat an array of scene nodes as in name[amt] but i cannot get this working

the reason i want this is because i am working on an aplication which will generate alot of these models

if there is any ideas i would like to know - I did see that somebody has done this on the forums but he has not released his code to look at

Cheers
Baal Cadar
Posts: 377
Joined: Fri Oct 28, 2005 10:28 am
Contact:

Post by Baal Cadar »

What exactly were you trying? (Code snippet) And what exactly was the error you were getting? (Exact compiler messages)
Also state your compilation environment and used Irrlicht version.

You might consider using irr::core::array or std::vector or some other container instead of C style arrays. They are *much* easier to use, dynamically growing and just as fast.
DGENXP
Posts: 124
Joined: Tue Dec 27, 2005 2:49 am
Contact:

Post by DGENXP »

Hi I hope this helps

when i try this it crashes before it even starts i have tried another method but this just places the object without a texture

I am using Dev C++ and IRR Version 0.12.0 with directX Support

Code: Select all

	IAnimatedMesh* mesh = smgr->getMesh("Objects/floor.x");
	IAnimatedMeshSceneNode* node[1] = {smgr->addAnimatedMeshSceneNode( mesh )};
	

	if (node[1])
	{
		node[1]->setMaterialFlag(EMF_LIGHTING, false);
		node[1]->setPosition(vector3df(128-256,0,78));
	//	node->setFrameLoop(0, 310);
		node[1]->setMaterialTexture( 0, driver->getTexture("Objects/Floor09.jpg") );
	}
I shall look forward to reading the solution
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

no need for the curly braces.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
DGENXP
Posts: 124
Joined: Tue Dec 27, 2005 2:49 am
Contact:

Post by DGENXP »

bitplane wrote:no need for the curly braces.
I have tried it without and it does not compile

it says invalid initializer
ElementoY
Posts: 15
Joined: Sun Feb 05, 2006 3:40 am
Location: Brazil
Contact:

Post by ElementoY »

Arrays in C++ start from index 0, not 1, so an array with size 1 would have only the index 0, so to access it you'll need to change all references to node[1] to node[0] .
Hope it helped! :)
ElementoY
Posts: 15
Joined: Sun Feb 05, 2006 3:40 am
Location: Brazil
Contact:

Post by ElementoY »

This would be the fixed-up code:

Code: Select all

	IAnimatedMesh* mesh = smgr->getMesh("Objects/floor.x");
	IAnimatedMeshSceneNode* node[1];
        node[0] = smgr->addAnimatedMeshSceneNode( mesh ) ; // no need for braces here
	

	if (node[0])
	{
		node[0]->setMaterialFlag(EMF_LIGHTING, false);
		node[0]->setPosition(vector3df(128-256,0,78));
	//	node[0]->setFrameLoop(0, 310);
		node[0]->setMaterialTexture( 0, driver->getTexture("Objects/Floor09.jpg") );
	}
Last edited by ElementoY on Wed Feb 08, 2006 11:49 pm, edited 1 time in total.
DGENXP
Posts: 124
Joined: Tue Dec 27, 2005 2:49 am
Contact:

Post by DGENXP »

It worked at the 0 point but when i tried to add more it crashes
ElementoY
Posts: 15
Joined: Sun Feb 05, 2006 3:40 am
Location: Brazil
Contact:

Post by ElementoY »

Try giving the array more elements, like in:
IAnimatedMeshSceneNode* node[x];
where x is the number of elements you want in the array.
DGENXP
Posts: 124
Joined: Tue Dec 27, 2005 2:49 am
Contact:

Post by DGENXP »

Hmm nope it still crashes
DGENXP
Posts: 124
Joined: Tue Dec 27, 2005 2:49 am
Contact:

Post by DGENXP »

Hmm nope it still crashes
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

d'oh! like Baal said, you should try using core::array instead because its much easier to use. I thought creating an array like x[3] = {a,b,c} makes constants, i dunno, anyway they're awkward and you cant 'redim' them.

Code: Select all

core::array<scene::ISceneNode*> aNodes;
aNodes.set_used(total);
aNodes[0] = smgr->addFooSceneNode();
...
aNodes[total-1] = smgr->addFooSceneNode();
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Baal Cadar
Posts: 377
Joined: Fri Oct 28, 2005 10:28 am
Contact:

Post by Baal Cadar »

Or using std::vector (would be similiar with irr::core::array)

Code: Select all

#include <vector>
using namespace std;

//...snip...
IAnimatedMesh* mesh = smgr->getMesh("Objects/floor.x");

vector<IAnimatedMeshSceneNode*> nodes;
// Creating five of them:
for (int i = 0; i < 5; ++i)
{
   nodes.push_back(smgr->addAnimatedMeshSceneNode(mesh));
}
   
// Initialise the created nodes
for (size_t i = 0; i < nodes.size(); ++i)
{
      nodes[i]->setMaterialFlag(EMF_LIGHTING, false);
      nodes[i]->setPosition(vector3df(128-256,0,78));
      nodes[i]->setMaterialTexture( 0, driver->getTexture("Objects/Floor09.jpg"));
}
Using C style arrays in this context is just inflexible and troublesome. Prefer full functional containers like STL containers or the ones Irrlicht provides.
ElementoY
Posts: 15
Joined: Sun Feb 05, 2006 3:40 am
Location: Brazil
Contact:

Post by ElementoY »

Baal Cadar wrote:Using C style arrays in this context is just inflexible and troublesome. Prefer full functional containers like STL containers or the ones Irrlicht provides.
True indeed! I forgot about Irrlicht's containers... :?
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

and... where is the array part?
Post Reply