[Closed] Matrix Offset/Difference between 2 Matrices
Hey all,
I’m currently working with Manipulators, and I am needing to set a manipulator’s gizmo transform to that of another object in the scene. (sounds simple enough…)
The problem here is that with a manipulator gizmo, you can only use the method “transform”
Scripted Manipulators [left]giz.transform matrix
[/left]
[left]This transforms the gizmo by the given Matrix3 transform.
[/left]
So I need to move the matrix by applying a matrix that is the difference/offset between the 2 objects.
Any ideas?
for now I am using a horribly slow process: (so that I could move on to other parts of my script)
creating 2 points at each objects transforms.
Parenting destination object to originating object.
Setting originating objects transform to world zero.
Use destination object’s new transform as my “transform” matrix.
(yuck)
I’m trying to wrap my head around this matrix stuff, any help here would be much appreciated.
Regards
it will be much more easier for me to understand what you want to achieve if you post an image.
but if you have the object1 with transform tm1, and the object2 with transform tm2, the difference of transform matrices is:
object1 to object2: tm1*(inverse tm2)
object2 to object1: tm2*(inverse tm1)
in case you have 2 objects o1 and o2 – they have both an uvw_map modifier as the only modificator the math for aligning the gizmo of the first to the second would look like this:
o1.modifiers[1].gizmo.transform = o2.modifiers[1].gizmo.transform*o2.transform *(inverse o1.transform)
regards,
stefan
@stefan: this is a manipulator gizmo so I cannot directly set the transform (with = ). I only have a function mygizmo.transform (matrix3) which transforms the gizmo’s transform. Why they don’t let me set it directly is a mystery.
@denis: thanks I’ll give that a try, I feel like I tried that before and something was off about it, but maybe I had it wrong. [attached a pic] The manipulator is a set of stereoscopic eyes. These show up fine when a camera is selected, but disappear when you select a camera’s target, so I am making them show up even when you select the target. To do this the manipulator gizmo gets added to the target object, but of course is oriented to the target, so I have to offset translate the gizmo so that it appears to be oriented the target’s camera.
I’ll give your math a try, and post back if it’s giving me trouble. Thanks!
EDIT: The opposite was DOES work: “tm2*(inverse tm1)”, which seems backward from the explanation. Oh well, it works now thanks Denis.
hmmm… this is what “tm1*(inverse tm2)” yielded.
You can see the gizmo being offset from the target object, but not at all in the right directions.
(ignore the grid, I'll have separate code for aligning that on the target)
[img] http://forums.cgsociety.org/attachment.php?attachmentid=154757&stc=1 [/img]