how to copy a scenenode?

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.
pat-rizio
Posts: 20
Joined: Thu Jan 05, 2006 10:59 am

how to copy a scenenode?

Post by pat-rizio »

Hi everybody,
I'm new to irrlicht, so please forgive me if I'm asking a stupid question... :oops:

How can I copy a scenenode?
I mean... If I have 2 scenenodes

Code: Select all

scene::ISceneNode* Origin;
scene::ISceneNode* Dest;
how can I obtain a copy of Origin scenenode to Dest one?

If I type:

Code: Select all

Dest = Origin
equal operator doesn't seem to work properly.
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

Learn C pointer before making 3D apps :)
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
pat-rizio
Posts: 20
Joined: Thu Jan 05, 2006 10:59 am

Post by pat-rizio »

ok I know that equal operator can't work, thank you very much for your useful answer...

I wish to know if exists a method to equal 2 scenenode, or if I have to "equal" each scenenode's property using set and get method...
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

And this one does not work too ?

*Dest = *Origin;
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
Guest

Post by Guest »

And then:
*Dest - *Origin = 0;
=> all poop
needforhint
Posts: 322
Joined: Tue Aug 30, 2005 10:34 am
Location: slovakia

Post by needforhint »

dest= smgr->addMeshSceneNode(originMesh); or whatever
what is this thing...
pat-rizio
Posts: 20
Joined: Thu Jan 05, 2006 10:59 am

Post by pat-rizio »

And this one does not work too ?

*Dest = *Origin;
no it doesn't work. Memory exception given.
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

Yes, it does. But you need to know what you are doing with.

Code: Select all

irr::scene::ISceneNode * origin = new CCameraSceneNode(0,smgr,1);
irr::scene::ISceneNode * dest = new CCameraSceneNode(0,smgr,2);
*dest = *origin;
This code copy the ISceneNode's members of origin to dest.

@Guest : there is no default operator-. Unless you make the class non copyable, you can copy two instances of the same class.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
pat-rizio
Posts: 20
Joined: Thu Jan 05, 2006 10:59 am

Post by pat-rizio »

Ok I try to explain better what I have to realize:

I have to create an articulated human hand model and i have to move each part of it (each finger bone I mean).

I've created the model I need importing a 3ds model. In particular I've imported each finger bone of the hand and then I've created the hand's tree.

Here I create each finger bone:

Code: Select all

	
scene::ISceneManager* smgr;
scene::ISceneNode* V2Grp01;
scene::ISceneNode* rotating_node;
[cut]
	s16 CreateHand()
	{
		//Check if model directory is right terminated
[cut]
		
//Building Hand Model step by step
		//ROOT
			V2Grp01 = smgr->addEmptySceneNode();
			V2Grp01->setName(L"V2Grp01");
			V2Grp01->setVisible(this->startVisible);
			scene::ISceneNode* dad_GROUND01 = smgr->addEmptySceneNode();
			dad_GROUND01->setName(L"dad_GROUND01");
			scene::ISceneNode* GROUND01 = smgr->addEmptySceneNode();
			GROUND01->setName(L"GROUND01");
			dad_Palm01 = smgr->addEmptySceneNode();
			dad_Palm01->setName(L"dad_Palm01");
			dad_Palm01->setMaterialTexture(1,driver->getTexture("t351sml.jpg"));
			scene::ISceneNode* Palm01 = smgr->addEmptySceneNode();
			Palm01->setName(L"Palm01");
		//PALM
			scene::ISceneNode* dad_Palm02 = smgr->addEmptySceneNode();
			dad_Palm02->setName(L"dad_Palm02");
			scene::ISceneNode* VIFS16 = smgr->addOctTreeSceneNode( smgr->getMesh((ModelDir + "VIFS16.3ds").c_str())->getMesh(0,255));
			VIFS16->setName(L"VIFS16");
		//PINKY
...
...
in particular dad_Palm01 is the palm's node.

then I link each other to create hand's tree:

Code: Select all

		//Build Hand Scene Tree
		{
			V2Grp01->addChild(dad_GROUND01);
			dad_GROUND01->addChild(GROUND01);
			GROUND01->addChild(dad_Palm01);
			dad_Palm01->addChild(Palm01);
			{
				Palm01->addChild(dad_Thumb01);
...
...
When I have to move a node, I use a support node called rotating_node that assume the identity of the node I want to move/rotate (for example palm, or a finger bone).

Code: Select all

			switch(event.KeyInput.Key)
[cut]
			case INDEX3:
			{
				rotating_trans = dad_Index03_trans;
				rotating_node = smgr->addEmptySceneNode();
				*rotating_node = *dad_Index03;
				rotating_joint = INDEX3; 
			}
			break;
[cut]
So when the compiler arrive here:

Code: Select all

*rotating_node = *dad_Index03;
an exception occurs.
typing:

Code: Select all

rotating_node = smgr->addEmptySceneNode();
rotating_node should be initialized, isn't it?
Baal Cadar
Posts: 377
Joined: Fri Oct 28, 2005 10:28 am
Contact:

Post by Baal Cadar »

What is the rationale behind your approach? Why export each finger seperately and then reattaching it in Irrlicht? That's what skeletal animations are for. If you used X as your format, you could export the hand as a whole and still animate each actual and figurative bone seperately.
pat-rizio
Posts: 20
Joined: Thu Jan 05, 2006 10:59 am

Post by pat-rizio »

well I did this job because at first I had the model I need in VRML format, not supported in irrlicht. So I converted it in 3ds format using 3dstudiomax and then I imported each part of it in order to preserve its articulated feature...
I didn't try to export VRML model in X format, I haven't 3dsstudiomax here on the machine I'm typing this post, anyway I will try your suggest, thanks.
hybrid

Post by hybrid »

I don't think that you really want to copy the scene node, beacuse you would have two duplicated fingers in that case. And the new one would have nothing in common with the original one except for shape and connections. I really seems as if you don't know C pointers. Maybe you could give some more rationale on your further process with the rotation node?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

irr::scene::ISceneNode * origin = new CCameraSceneNode(0,smgr,1);
irr::scene::ISceneNode * dest = new CCameraSceneNode(0,smgr,2);

// do some other stuff

*dest = *origin;
This may compile and run, but it is a very, very stupid thing to do. The SceneNode and derived classes don't implement operator= or copy constructors, so the default implementation just copies the pointers [or arrays of].

If origin or dest had any children, or had grabbed pointers to resources, the reference counts to those resources would now be off. This will result in memory leaks, accessing deleted memory and double deletes.

Travis
Guest

Post by Guest »

thanks everybody for answers,
@hybrid: I do the node rotation as follow:

Code: Select all

			case  KEY_KEY_I: //KEY_UP
        {
            if ((rotating_joint != THUMB1)&&(rotating_joint != THUMB2)
               &&(rotating_joint != THUMB3)&&(rotating_joint != PALM_TRANS))
            {
				rot.X = rot.X + ROTATION_STEP;
             if (((rot.X >= INF_LIMIT_X)&&(rot.X <= SUP_LIMIT_X))
                 ||(rotating_joint == PALM)) //il palmo comunque gira
                {
					rotating_node->setRotation(rot);
                }
            }
            
            if (rotating_joint == PALM_TRANS)
            {
				transl.Y = transl.Y + TRANSLATION_STEP;
				rotating_node->setPosition(transl);
            }
        } 
        break;
where rotating_node should be a pointer to the node I want to rotate.
Where I set it? Before rotation, pressing a particular key (rotating_joint). Each finger bone has a particular key on the keyboard (in the future they'll be replaced by Cyberglove).
pat-rizio
Posts: 20
Joined: Thu Jan 05, 2006 10:59 am

Post by pat-rizio »

previous post was mine I was not logged in sorry
Post Reply