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?
Parent nodes, allowing for rotation
Re: Parent nodes, allowing for rotation
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Parent nodes, allowing for rotation
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.
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.
Re: Parent nodes, allowing for rotation
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.
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.
Help Me Help You.
Re: Parent nodes, allowing for rotation
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.
Re: Parent nodes, allowing for rotation
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Parent nodes, allowing for rotation
Okay, thanks!!
Re: Parent nodes, allowing for rotation
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:-
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!
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);
Can´t get my head around this!
Re: Parent nodes, allowing for rotation
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.
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.