Calculating a child Position, Rotation and Scale values?
- by Sergio Plascencia
I am making my own game editor(just for fun) anyway I have problem that I had several days trying to resolve but I have been unsuccessful. Here goes...
I have an object "A":
Position: (3,3,3), Rotation: (45,10,0), Scale(1,2,2.5)
And an object "B":
Position: (1,1,1), Rotation: (10,34,18), Scale(1.5,2,1)
I now make a parent/child relationship. "B" is a child of "A":
A
|--B
When I do the relationship I need to re-calculate the Child("B") Position, Rotation and Scale such that it maintains its current position, rotation and scale(Location in world). So for child position "B" it would now be (-2, -2, -2) since now "A" it is center and (-2, -2, -2) will keep the object in its same position.
I think I got the Position and scale figure out, but rotation I cant.
So I was trying to figure out what to do and what I did is opened Unity and run the same example and I did noticed that when making an abject a child object the child object did not moved at all but had its Position, Rotation and Scale values changed(Related to the parent).
For example:
Unity (Parent Object "A"):
Position: (0,0,0)
Rotation: (45,10,0)
Scale: (1,1,1)
Unity (Child Object "B"):
Position: (0,0,0)
Rotation: (0,0,0)
Scale: (1,1,1)
When making it a parent child relation("B" is a child of "A") the child object("B") in its Rotation values now has:
X: -44.13605
Y: -14.00195
Z: 9.851074
If I plug the same values to my editor(To the child "B" rotation X, Y, Z values) the object does not move at all.
So I basically need to know how did Unity arrive at those rotation values for the child(What are the calculations?).
If you can help and put all the equations for the Position, Rotation or Scale then I can double check I am doing it correctly but with the Rotation I really need help.
Thanks!