@DMGregory I got the rotation around a axis working by using following formula... T * Rz * Ry * Rz alpha * -Ry * Rz * -T .... This way we are able to rotate a object around a point and a certain axis... ^^
The only issue left is... i cant get it to work for local rotation... rotation around arbitrary axis should also work in local scope, right ? Normally you do T * Rotx * -T to rotate around the local x axis... any ideas why it may not be working with custom axis ?
Ah! Protests were all over the world, but it was caused by something that happened in Minneapolis. That was horrifying. There are other things horrifying that go on like what happens in Brazil. /shrug.
Quick question... lets say we wanna simulate the parent/child behaviour of unitys gameobjects... when we rotate the parent by 45 degrees, the childs are getting rotated by 45 degrees too... Does the parent simply loops over all children to rotate them around itself by 45 degrees ? Or how is this behaviour done ? ^^
Note that this is often done lazily, since many things will change many objects' transformations during a frame, you might want to avoid doing expensive matrix recalculations for the whole child tree every time.
(Or just keep your trees shallow - that's good too)
So sometimes the parent will only walk through its children to set a dirty flag. Only once something tries to read the child's transformation (like, say, when it's submitted for rendering at the end of the frame) does it need to be updated by multiplying its local to parent matrix by its parent's local to world.
@DMGregory Oh... damn... than im implementing it the wrong way... my first prototype did it the following way... "Rotate Parent, Noticed Rotation ?, Loop over Children rotate with the same degree as the parent rotated around the parents pos"... didnt knew that we can simply use the matrizes ^^
Yep. If I store a local-to-parent matrix and a local-to-world matrix, I can quickly compute a new local-to-world matrix no matter how many transformations have been done to the parent in between just by multiplying my local-to-parent by my parent's local-to-world.
One matrix multiplication will fold in all updates to translation, rotation, scale, for the parent and all grandparents (since the grandparents are already included in the parent's local-to-world matrix).
I've got some existing answers about various flavours of transformation hierarchy implementations that might be useful to you: google.com/…
@0x00004 That is an option available to you. Whether you "should" do that is a judgement call that you will need to make for yourself, based on your situation.
The sun is the parent... the red planet is the child and the green moon is the child of the planet... im rotating the sun by a few degrees... does this rotation apply in the right way at the childs ? :O
I somehow have the feeling that this is not the cause
When the parent rotates about 45 degrees to the left... we need to rotate the childs also 45 degrees to the left with the rotation point based in the parent itself, right ?
@genaray WHen your parent rotates, you need to translate everything w.r.t. the position of your parent, so that you reference frame for your planet is 0,0 (as if you sun was the center of the universe), then you rotate everything that is under the sun. then you translate everything back with the same offset you used before (your sun position).
If your moon is to be rotated about your planet, you'll ahve to do the same thing, translate, rotate, translate back.
I've seen somwhere that you should keep your rotate and translate parameters separate, for greater precision. Also, you don't use your current matrix with the parent, you need to rebuild it every frame with updated data.
Now, unfortunately, it's getting too hot in this room, and I'll have to head out :/
The problem here is... that im already rebuilding my matrix every frame... and my child is calculating its matrix by "child.Model *= parent.model"... the parent rotates itself around the local axis, but the child stays at the same place :o
basically the child is rotating around its own local axis like the parent does :p
Thats fixed now by doing "childModel = parentModel * childModel"... the only problem left... the child of the child escalates pretty quickly to strange new positions, it basically shoots out of the screen
We now do the following... Put local coordinates into translation matrix, childModel = parentModel * childModel, reset position translation for each child/parent at the end of the frame from their model matrix... This results in weird behaviour, the child of the child rotates like crazy around the same point... could anyone solve the mistery of multiplying child and parent models ?
@DMGregory Yes... the real problem here is that the child of a child rotation is broken... thats the only issue left :/
1. Put local offset into matrix 2. child = parent * child 3. Global rotation Works fine for one parent and one child... doesnt work if we have a child rotating around the child ...
Sounds like it could be a recursion or order of update issue. You might be updating the grandchild based on the child before the child's been updated relative to the parent, or you might be failing to recurse all the way down from parent to grandparent.
Thanks... currently it looks like this... first the planet ( parent ) gets updated ( model = parent * model ), than the moon gets updated ( model = planetModel * model )... it works fine for transformations like positions etc... but rotating only works for one child, the other one flipps out...
Lets say our planet rotates around the sun and the moon rotates around the planet...
and first we calculate the rotation, than the model matrix ( model = parent * model ) in the right order... shouldnt the moon rotation get applied later ? Otherwhise we would first rotate our moon and than we apply the planet transform/rotation... wouldnt this cause the weird rotation behaviour ?