Clone node ?

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.
yellowdude42
Posts: 10
Joined: Sat Jun 19, 2010 6:55 pm

Clone node ?

Post by yellowdude42 »

Hi everybody,

how i can clone a node and give a name to it ?

Because i have one mesh, i want a create many node to duplique it and for each one do what i want.

For example :

-the first jump and second move left and the other walk etc etc etc..

its possible with irrlicht ?

With irr::scene::ISceneNode::cloneMembers(ISceneNode *toCopyFrom, ISceneManager *newManager)?

I really don't know how to do that :S
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

well u just answered ur question.

secondNode = firstNode->clone();

thats all :D
Image
Image
yellowdude42
Posts: 10
Joined: Sat Jun 19, 2010 6:55 pm

Post by yellowdude42 »

Cool :)

but i have this :

Code: Select all

	scene::IAnimatedMesh* mesh = smgr->getMesh("../../media/faerie.md2");
	scene::IAnimatedMeshSceneNode* modelNode = smgr->addAnimatedMeshSceneNode(mesh);
	scene::IAnimatedMeshSceneNode* toto = modelNode->clone();
and he show me error :
error: invalid conversion from `irr::scene::ISceneNode*' to irr::scene::IAnimatedMeshSceneNode*'
Virion
Competition winner
Posts: 2149
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

do this

Code: Select all

scene::ISceneNode* toto = modelNode->clone();
yellowdude42
Posts: 10
Joined: Sat Jun 19, 2010 6:55 pm

Post by yellowdude42 »

yeah thx a lot :) its work but i have a last question :D

I have this :

Code: Select all

   scene::IAnimatedMesh* mesh = smgr->getMesh("../../media/faerie.md2");
   scene::IAnimatedMeshSceneNode* modelNode = smgr->addAnimatedMeshSceneNode(mesh);
   scene::ISceneNode* toto = modelNode->clone();
But i want to give a name for each node where duplicate with coordonate.

For example :

Code: Select all

x = 5;
y = 9;

name = "my_new_node";
name = "my_new_node_x_y";

scene::IAnimatedMesh* mesh = smgr->getMesh("../../media/faerie.md2");
scene::IAnimatedMeshSceneNode* modelNode = smgr->addAnimatedMeshSceneNode(mesh);
scene::ISceneNode* name = modelNode->clone();
does it work ? or how i can do this ? please :s
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

yellowdude42 wrote:

Code: Select all

x = 5;
y = 9;

name = "my_new_node";
name = "my_new_node_x_y";

scene::IAnimatedMesh* mesh = smgr->getMesh("../../media/faerie.md2");
scene::IAnimatedMeshSceneNode* modelNode = smgr->addAnimatedMeshSceneNode(mesh);
scene::ISceneNode* name = modelNode->clone();
does it work ? or how i can do this ? please :s
no, this won't work !!! :lol:
but how about using an 2 dimensional array, maybe like this:

Code: Select all

scene::ISceneNode* name[10][10];

x = 5;
y = 9;

scene::IAnimatedMesh* mesh = smgr->getMesh("../../media/faerie.md2");
scene::IAnimatedMeshSceneNode* modelNode = smgr->addAnimatedMeshSceneNode(mesh);
name[x][y] = modelNode->clone();
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
yellowdude42
Posts: 10
Joined: Sat Jun 19, 2010 6:55 pm

Post by yellowdude42 »

Oh cool good idea :)

But if i do function like that :

Code: Select all


ISceneNode *clone_node(int x, int y)
{
scene::ISceneNode* name[10][10];

scene::IAnimatedMesh* mesh = smgr->getMesh("../../media/faerie.md2");
scene::IAnimatedMeshSceneNode* modelNode = smgr->addAnimatedMeshSceneNode(mesh);
name[x][y] = modelNode->clone();

return (name[x][y]);
}

How i could use any name[x][y] when i want ?

Save in struct or its in the scene manager ? :S i really dunno :(
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

well, this function is bad, because the array is only temporaly (local) created and deleted when leaving the function !!! :shock:

there are several ways to solve this:

1st make the array global, so you can access it from anywhere...

2nd another approach would be to set the name of the node(s) and get them later by their names...

Code: Select all

ISceneNode *clone_node(int x, int y)
{
stringc name = "name";
name += x;
name += ",";
name += y;

scene::IAnimatedMesh* mesh = smgr->getMesh("../../media/faerie.md2");
scene::IAnimatedMeshSceneNode* modelNode = smgr->addAnimatedMeshSceneNode(mesh);
scene::ISceneNode* node = modelNode->clone();
node->setName(name);

return (node);
} 
later you can use this to get the node:

Code: Select all

stringc name = "name";
name += x;
name += ",";
name += y;
scene::ISceneNode* node = smgr->getSceneNodeFromName(name);
but I realy wonder why you do it this way, you're creating 2 scene nodes every time this function is called and using only the cloned one !?!?! :shock:
you can use the created one directly and forget about the cloned one:

Code: Select all

ISceneNode *clone_node(int x, int y)
{
stringc name = "name";
name += x;
name += ",";
name += y;

scene::IAnimatedMesh* mesh = smgr->getMesh("../../media/faerie.md2");
scene::IAnimatedMeshSceneNode* modelNode = smgr->addAnimatedMeshSceneNode(mesh);
modelNode->setName(name);

return (modelNode);
} 
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
yellowdude42
Posts: 10
Joined: Sat Jun 19, 2010 6:55 pm

Post by yellowdude42 »

hmm, in fact i have a map.

[][][][][][][][][]
[][][][][][][][][]
[][][][][][][][][]
[][][][][][][][][]
[][][][][][][][][]
[][][][][][][][][]

In each [] i have 7 ressources generate randomly.

So i don't want to getMesh all time.. :O

That why i need to clone it and when a player get one, my server game send me (for example) in case x y the ressource GOLD appear, or disappear.

so i need to save any node and iuse it when i want..

But i don't know how to create ressource, do clone and saving (i don't know where) and use to setVisible(false) or true.. :s
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

yellowdude42 wrote:So i don't want to getMesh all time.. :O
why not ???
you're using it now all the time in this function !!! :lol:
and let's say you call this function 100 times (map of 10x10 entries) you now get 200 nodes !!!
100 created (with addAnimatedMeshSceneNode) and 100 cloned nodes !!! :roll:
Last edited by Acki on Sun Jun 20, 2010 4:35 pm, edited 1 time in total.
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
yellowdude42
Posts: 10
Joined: Sat Jun 19, 2010 6:55 pm

Post by yellowdude42 »

because it get many memory :P and lag :/
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

yellowdude42 wrote:because it get many memory :P and lag :/
no, it doesn't, the mesh will be loaded only one time !!! :roll:
the way you do it now is a waste of memory (see my previous reply I edited) !!! :roll:
Acki wrote:and let's say you call this function 100 times (map of 10x10 entries) you now get 200 nodes !!!
100 created (with addAnimatedMeshSceneNode) and 100 cloned nodes !!! :roll:
I guess you should start with something much easier and get some C/C++ books or tutorials !!! :lol:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
yellowdude42
Posts: 10
Joined: Sat Jun 19, 2010 6:55 pm

Post by yellowdude42 »

Yes but its for a school project :P
And the deadline is this night xD lol ^^
ACE247
Posts: 704
Joined: Tue Mar 16, 2010 12:31 am

Post by ACE247 »

I wonder how much time you had and when you 'actually' started? :D
The day before? :wink: :D
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

yellowdude42 wrote:That why i need to clone it and when a player get one, my server game send me (for example) in case x y the ressource GOLD appear, or disappear.
you don't know nothing about such basics and got a school project for a server/client project !?!?! :shock:
what a crappy teacher you got there !?!?! :lol:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply