[Closed] problem seting rotation relative to parent
I have child and parent nodes and want to set child transformation relative to parent. The parent transform is the identity matrix. The code looks something like this:
transform=matrix3 [0,-1,0] [0,0,1] [-1,0,0] [0,0,-0.0629014]
in coordsys parent (
child.rotation = transform
child.position = transform[4]
)
When I want to get child.transform after that, the result is: matrix3 [0,0,-1] [-1,-1.65754e-007,0] [-1.65754e-007,1,0] [0,0,-0.0629014]
Looks like there is some problem with matrix arithmetics in max. Any way to fix that problem?
tm = matrix3 [0,-1,0] [0,0,1] [-1,0,0] [0,0,-0.0629014]
$.rotation = inverse tm.rotation
$.position = tm.pos
$.transform
Sory, not really understanding, why inverse?
Also this was just a special example, normaly parent transform can be not only identity matrix. Also I normaly have more then 1 child and I link al the child nodes to the parent in a for loop.
inverse is the key if you want to set rotation directly. do you want me to tell you also the matrix algebra briefly?
Sory my bad english again, I just need to thet the child transform relative to parent.
child’s transform in parent coordinate system:
child.transform * inverse parent.transform
because rotation controller value is always in parent coordinate system we set it directly “inverse”
Thanks, my code looks like this now:
fn appendToParent p children transforms=(
for i=1 to children.count do(
children[i].parent=p
in coordsys parent (
children[i].rotation = transforms[i]
children[i].position = transforms[i][4]
)
)
)
and it seems to worck, like it should.
However if I remoove in coordsys parent, everithing f*cks up. Posibly I misunderstood something?