Notifications
Clear all

[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?

6 Replies
6 Replies
(@denist)
Joined: 1 year ago

Posts: 0

tm = matrix3 [0,-1,0] [0,0,1] [-1,0,0] [0,0,-0.0629014]

$.rotation = inverse tm.rotation
$.position = tm.pos

$.transform

(@gtafan)
Joined: 1 year ago

Posts: 0

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.

(@denist)
Joined: 1 year ago

Posts: 0

inverse is the key if you want to set rotation directly. do you want me to tell you also the matrix algebra briefly?

(@gtafan)
Joined: 1 year ago

Posts: 0

Sory my bad english again, I just need to thet the child transform relative to parent.

(@denist)
Joined: 1 year ago

Posts: 0

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”

(@gtafan)
Joined: 1 year ago

Posts: 0

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?