Page 1 of 1

Proper scaling/rotation of gun mesh

Posted: Mon Mar 31, 2014 9:19 am
by superpws
Hi, so I read the example of Quake3 explorer and search the way the gun is implemented like in FPS, old posts that I found suggested that we have to attach gun node to camera node, something like this:

Code: Select all

 
camera = smgr->addCameraSceneNodeFPS(); 
gunMesh = smgr->getMesh("gun.md2");
gunNode = smgr->addAnimatedMeshSceneNode(gunMesh , camera, -1);
 
gunNode ->setScale(core::vector3df(14,14,14));
gunNode ->setPosition(core::vector3df(15,-10,30)); 
gunNode ->setRotation(core::vector3df(180,0,180)); 
 
It works and the gun moves along with camera. However, I don't know the exact rotation/position of gun.md2 that is provided with Irrlicht SDK and the example code doesn't have that at all. So, does example implemented it in a different way? Also, I heard that position/rotation/scale isn't stored in mesh formats, so does that mean we have to always manually set them when we load them in irrlicht?

With that:

Code: Select all

 
gunNode->setScale(core::vector3df(4, 4, 4));
gunNode->setPosition(core::vector3df(15, -10, 30));
gunNode->setRotation(core::vector3df(100, -100, -100));
 
I somehow get close with original.
Image


Thank you.

Re: Proper scaling/rotation of gun mesh

Posted: Tue Apr 01, 2014 9:59 am
by thanhle
I think you should do the following in sequence, after making the gun the child node of the camera.

setScale follows by setRotation then setPosition.
-----

After that you don't have to worry about it anymore.
Since rotate the camera automatically transform the gun.


after attached, setPosition to the gun will translate it relative to its parent.

Rotation of the gun can be retrieved by the getAbsoluteTransform or something like that. Look for those function that retrieve the matrice.

Re: Proper scaling/rotation of gun mesh

Posted: Thu Apr 03, 2014 9:45 am
by superpws
Hm, isn't getAbsoluteTransform equivalent to default transform? (without explicitly setting position) Anyway, it turns out I don't need to set scale or position, just setting rotation to arbitrary constants works fine. Still not sure what are the exact transformations.

Code: Select all

 
gunNode->setRotation(core::vector3df(100, -100, -100));
 

Re: Proper scaling/rotation of gun mesh

Posted: Thu Apr 03, 2014 10:11 am
by hendu
They depend on your model.

Re: Proper scaling/rotation of gun mesh

Posted: Thu Apr 03, 2014 10:26 am
by superpws
hendu wrote:They depend on your model.
You mean positions aren't separated from models?

Re: Proper scaling/rotation of gun mesh

Posted: Thu Apr 03, 2014 1:14 pm
by hendu
Your gun model may not be modeled around the origin, in which case you need to translate. Similarly, it may be made in millimeters, so you need to scale, and so on.

Re: Proper scaling/rotation of gun mesh

Posted: Thu Apr 03, 2014 1:30 pm
by superpws
hendu wrote:Your gun model may not be modeled around the origin, in which case you need to translate. Similarly, it may be made in millimeters, so you need to scale, and so on.
I take your answer as yes to my previous question :) And no, the gun model isn't mine. It comes with Sdk.