Proper scaling/rotation of gun 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
superpws
Posts: 18
Joined: Mon Mar 31, 2014 6:47 am
Contact:

Proper scaling/rotation of gun mesh

Post 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.
IRC: #irrlicht on irc.freenode.net
Github: https://github.com/danyalzia
Homepage: http://danyalzia.com
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Proper scaling/rotation of gun mesh

Post 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.
superpws
Posts: 18
Joined: Mon Mar 31, 2014 6:47 am
Contact:

Re: Proper scaling/rotation of gun mesh

Post 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));
 
IRC: #irrlicht on irc.freenode.net
Github: https://github.com/danyalzia
Homepage: http://danyalzia.com
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Proper scaling/rotation of gun mesh

Post by hendu »

They depend on your model.
superpws
Posts: 18
Joined: Mon Mar 31, 2014 6:47 am
Contact:

Re: Proper scaling/rotation of gun mesh

Post by superpws »

hendu wrote:They depend on your model.
You mean positions aren't separated from models?
IRC: #irrlicht on irc.freenode.net
Github: https://github.com/danyalzia
Homepage: http://danyalzia.com
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Proper scaling/rotation of gun mesh

Post 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.
superpws
Posts: 18
Joined: Mon Mar 31, 2014 6:47 am
Contact:

Re: Proper scaling/rotation of gun mesh

Post 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.
IRC: #irrlicht on irc.freenode.net
Github: https://github.com/danyalzia
Homepage: http://danyalzia.com
Post Reply