Attaching objects to a mesh

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
al7
Posts: 8
Joined: Mon Dec 14, 2009 1:22 pm

Attaching objects to a mesh

Post by al7 »

I'm trying to learn how to do animation with Irrlicht; currently, using data from an older post in the forums (http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=29365).

My question is a bit different from the original post: how do we specify the point of contact between two meshes? (is there a term for that?). I mean attaching sword to the right hand is a bit vague unless there is some implicit notion of attach points both on the sword and the hand. In other words, what part of the sword gets attached to what part of the hand?

This is a generalization of the original (unanswered) question, how to correctly orient the sword?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You need a bone or joint for this, hence it only works for skeletal animated meshes. Just get the bone of a certain name and parent your sword to it.
al7
Posts: 8
Joined: Mon Dec 14, 2009 1:22 pm

Post by al7 »

>> You need a bone or joint for this

You mean a bone or joint on the sword?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Also note that it is "origin" of object that serve as reference point. So when you attach two objects, you attach them relative to their origin. Origin is point [0,0,0] in local space of your object, be it model or bone. You define origin in your modelling program.
You mean a bone or joint on the sword?
No, he mean bone or joint of hand. Your sword does not have bones probably (what for?).
al7
Posts: 8
Joined: Mon Dec 14, 2009 1:22 pm

Post by al7 »

>> No, he mean bone or joint of hand.

Thats exactly what I'm doing, similar to what the user in the original post tried to do.

Code: Select all

   

   //create character mesh 
   IAnimatedMesh* meshPC = smgr->getMesh("../../media/testmodel/mypc.x"); 
   IAnimatedMeshSceneNode* nodePC = smgr->addAnimatedMeshSceneNode(meshPC); 
   nodePC->setMaterialFlag(EMF_LIGHTING,false); 
   nodePC->setAnimationSpeed(3000); 

   IBoneSceneNode* bone = nodePC->getJointNode("game_HumanLPalm"); 

   //create sword mesh 
   IAnimatedMesh* meshWP = smgr->getMesh("../../media/testmodel/sword.x"); 
   IAnimatedMeshSceneNode* nodeWP = smgr->addAnimatedMeshSceneNode(meshWP); 
   nodeWP->setMaterialFlag(EMF_LIGHTING,false); 

   nodeWP->setParent(bone); 

>> So when you attach two objects, you attach them relative to their origin

Ok, if i'm understanding it properly that means the pivot point of the sword gets connected to the pivot point of the hand, right? What about the direction vector? I mean it attaches in the backward direction (sword on the back) and there does not seem to be a way to orient it in any other direction.
al7
Posts: 8
Joined: Mon Dec 14, 2009 1:22 pm

Post by al7 »

Interestingly, the sword changes its direction when it's attached to the right hand.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The sword becomes a child of the bone, so translation and rotation is relative to the bones transformation. You can move the sword to attach it at different positions, though, simply use setPosition or setRotation to the mesh node.
al7
Posts: 8
Joined: Mon Dec 14, 2009 1:22 pm

Post by al7 »

I must be missing something very fundamental then, because no matter what I do it does not affect at all. I even tried various combinations of EJUOR_CONTROL . Here is my entire code. What am I missing?

The models are from this link http://3dcg-yotuba.com/uploader/src/up0053.zip

Code: Select all


int main()
{
	IrrlichtDevice *device = createDevice(video::EDT_SOFTWARE, dimension2d<u32>(640, 480), 16, false, false, false, 0);
	if (!device)
		return 1;

	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();

	matrix4 projMat; 
	projMat.buildProjectionMatrixPerspectiveFovLH(45.0f,1.3333f,1.0f,10000.0f); 
	ICameraSceneNode *camera = smgr->addCameraSceneNode(0, vector3df(2, 2, 2), vector3df(0,1,0));
	camera->setUpVector(vector3df(0.0f,1.0f,0.0f)); 
	camera->setProjectionMatrix(projMat); 

	//create sword mesh 
	IAnimatedMesh* meshWP = smgr->getMesh("../../media/testmodel/sword.x"); 
	IAnimatedMeshSceneNode* nodeWP = smgr->addAnimatedMeshSceneNode(meshWP); 
	nodeWP->setMaterialFlag(EMF_LIGHTING,false); 
	nodeWP->setRotation(vector3df(45.0f,45.0f,45.0f));  // <------------ SET ROTATION
	//nodeWP->setJointMode(EJUOR_CONTROL);

	//create character mesh 
	IAnimatedMesh* meshPC = smgr->getMesh("../../media/testmodel/mypc.x"); 
	IAnimatedMeshSceneNode* nodePC = smgr->addAnimatedMeshSceneNode(meshPC); 
	nodePC->setMaterialFlag(EMF_LIGHTING,false); 
	nodePC->setAnimationSpeed(3000); 
	//nodePC->setJointMode(EJUOR_CONTROL);

	IBoneSceneNode* bone = nodePC->getJointNode("game_HumanRPalm"); 
	nodeWP->setParent(bone); 
	nodeWP->setRotation(vector3df(45.0f,45.0f,45.0f));  // <------------ SET ROTATION (TRY AFTER CONNECTING)

	while(device->run())
	{
		driver->beginScene(true, true, SColor(255,100,101,140));
		nodeWP->setRotation(vector3df(45.0f,45.0f,45.0f));  // <------------ SET ROTATION (TRY HERE)
		smgr->drawAll();
		nodeWP->setRotation(vector3df(45.0f,45.0f,45.0f));  // <------------ SET ROTATION (OR HERE)
		guienv->drawAll();
		driver->endScene();
	}

	device->drop();
	return 0;
}

Post Reply