Parent nodes, allowing for rotation

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Parent nodes, allowing for rotation

Post by robmar »

Does anyone have a simple way to parent a node to a rotated parent?

Should I rotate the child by the parent´s rotation value on the origin of the parent, then calculate the xyz offsets from the child´s new position, or is there a quicker calculation?
CuteAlien
Admin
Posts: 9930
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Parent nodes, allowing for rotation

Post by CuteAlien »

Once you added a child to the a parent and have called updateAbsolutePosition once the child should already regard the parent's rotation. Or is that not the result you want?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Parent nodes, allowing for rotation

Post by robmar »

I mean more if a node (not parented) moves to a position near another object, and I want to parent it, so that from then on it will track the parent.

If I just parent, its coordinates become offsets to the parent, so they must be recalculated, but if the parent-to-be is rotated, I have to rotate the position of the child-to-be so that the offsets will be correct.

That´s sounds more complex than it is. I´m thinking I need to apply the reversed rotation of the patent-to-be to the child-to-be´s location, then calculate the offsets.

Someone must have done that already, just wanted to check.
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Re: Parent nodes, allowing for rotation

Post by kklouzal »

If I understand correctly, you want a specific node to parent another node in the respect that no matter how you rotate the parent node the child will stay in the same place? Maybe allowing for the child to update in the Y axis but maybe not the X and Z axis?

If this is true I think you could figure out the difference between the child and parent's rotations after you get it situated into the correct place, then subtract that value from the parents rotation whenever the parent is rotated to get the child back into it's original rotation.

Another idea is to just get the amount of rotation that has occurred then subtract that from the new rotation. But I may not understand your original goal.
Dream Big Or Go Home.
Help Me Help You.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Parent nodes, allowing for rotation

Post by robmar »

Not really, imagine a fish randomly swimming along a path until it gets with X distance of another fish. Both fish nodes will have rotations, and at this point, a distance X or less, I want the software to automatically parent the approaching fish to the other.
CuteAlien
Admin
Posts: 9930
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Parent nodes, allowing for rotation

Post by CuteAlien »

robmar - ah yeah, I understand it now. And I think I saw someone do that in the forum once, but I don't know the thread. But you are thinking along the correct lines already.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Parent nodes, allowing for rotation

Post by robmar »

Okay, thanks!!
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Parent nodes, allowing for rotation

Post by robmar »

Is this a Matrix math issue? I can parent two existing nodes in the scene keeping their current world-space positions as long as any rotations of the nodes is in one and the same axis only.

I take the position of the child-to-be node, and rotate it equal to the -(neg) of the parent-to-be´s current rotation.

This is necessary to keep the worldspace positions the same, so the XYZ offsets must be the same as in the model space, so I rotate the node back to match the unrotated parent.

This works using this math:-

Code: Select all

matrix4 m;
m.setRotationDegrees(-rotation);   // Parent´s rotation
m.setRotationCentre(center, vector3df());
m.transformVect(childPos);
 
If rotation has more than one axis with rotation, the child shift off its original pre-parented world-space.

Can´t get my head around this!
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Parent nodes, allowing for rotation

Post by robmar »

Okay, easy when you know how!

Just take the inverse of the absolute transformation of the parent-to-be and multiply it by the abs transformation of the child-to-be, then extract the pos and rot to set the child.
Post Reply