Mesh parenting to camera

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
Blynx
Posts: 16
Joined: Sat Apr 12, 2008 8:41 am

Mesh parenting to camera

Post by Blynx »

How can I parent a mesh to the camera so it faces the same direction and same position?

It's for an FPS but instead of the gun it's just hands.
I'm using the FPS camera.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

The answer is in the question.

Code: Select all

    handsNode->setParent(cameraNode);
If you can't see the mesh, try offsetting it along the Z axis:

Code: Select all

    handsNode->setPosition(vector3df(0, 0, 20));
until it appears.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Blynx
Posts: 16
Joined: Sat Apr 12, 2008 8:41 am

Post by Blynx »

Before I parent it, I can see it in front of me as soon as I start the program, but when I parent it, it vanishes.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Because when you set a parent the offset from the parent is the position of the node, so if you have you hands at 0,0,0 then when you parent it to the camera the hands will be moved to the exact position of the camera, and hence probably not visible.

So do as rogerborg suggests and fiddle around with the offset, moving it along the z axis should make it visible at some point and then you can scale and reposition it on the x and y axes as well to get it looking nice.
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Then something screwy is going on. Do you fancy making your source and resources available?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Blynx
Posts: 16
Joined: Sat Apr 12, 2008 8:41 am

Post by Blynx »

Nevermind I solved it.
Thank you.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Great! Could you tell us what was wrong; it might help us to improve the APIs or docs.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
shogun
Posts: 162
Joined: Wed Sep 05, 2007 11:02 am
Location: inside

Post by shogun »

I'm sure the problem was that the camera scenenode doesn't rotate when you rotate the camera. So you have to set the rotation of the scenenode in every frame manually.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

And I'm sure that's not the problem, and that a node attached to a FPS camera node will rotate with the camera node and retain the same apparent orientation.

One of us took the time to test that before posting: can you guess which is which?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
shogun
Posts: 162
Joined: Wed Sep 05, 2007 11:02 am
Location: inside

Post by shogun »

Rogerburg, do me a favor and write a comedy. You're so hilarious. Yawn.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

He's funny but he's right ;)
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Apology accepted.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
shogun
Posts: 162
Joined: Wed Sep 05, 2007 11:02 am
Location: inside

Post by shogun »

Who apologized?
Blynx
Posts: 16
Joined: Sat Apr 12, 2008 8:41 am

Post by Blynx »

The problem was the model jumped up too high out of view, so I change the Z axis to a high number until I saw it, then rotated the model and lowered it, brought the model back along it's Z axis until it was just right.
Post Reply