Can anyone explain what is usage/purpose of compose transform and invert transform functions? Any examples?
Compose transform just applies the first, then the second transfrom.
Invert transform just reverses a transform.
TLDR
If you want to know the Child β Parent transform you use Child β Get Relative Transform and if you want to know the Parent β Child transform you use Child β Get Relative Transform β Invert Transform. But if you want to know A β B when there is not a direct Child-Parent connection [1], like in the Link β Base there is Joint in between, in this case you need to Compose Transform. That is Link(A) and Joint(B) call Compose Transform (A,B) will give Link β Base Transform, that is because
Link β Joint β Base is the relative transform chain [1]. If you call Compose Transform (B,A) that will consider that both the Joint and the Link transforms are relative to the Base, that is they both have Base as their direct Parent [2].
It is easier to use the Get World Transform when you want to know the relative transform of a Actor/Component relative to some other Actor/Component when there is no direct connection [3].
So, if you want to know the relative transform of MeshD β Link you need to use:
What you want as a Child goes in the A pin and the Parent goes in the B pin, and then you will have Child β parent transform, note that you need the Invert Transform of the Parent and both A and B are World Transform.
Long Answer
First you need to understand the difference between Fixed Reference Frame and Moving Reference Frame.
All transforms are relative to something. The Get Relative Transform is relative to the Actor/Component parent, while Get World Transform is relative to the World Fixed Reference Frame.
By default any Local Transform are done in Euler-ZYX notation, that is a Moving Reference Frame, also called Local Frame.
So letβs take a simple example.
Here we have a simple Actor with 3 Static Mesh Component.
If you want to know the relative transform just call the Get Relative Transform directly.
The Base transform is relative to the world due to it beeing the Root Component.
The Joint transform is relative to the Base.
The Link transform is relative to the Joint.
But what if you want to know the transform of the Link relative to the Base?
You need to Compose Transform.
Joint Transform.
Link Transform.
Obs: if you test it and print the transform and see some weird values that is because you have more than 90 degree rotation in Y(pitch) axis, and Unreal have some problems with that, so just use 89.5 as a test value like in the Link transform.
Transform Frames.
So, what happens if we use Compose Transform with the Joint and the Link?
Result Transform.
What Compose Transform does is to first apply A the Joint transform then it applies B the Link transform. If you notice the Z axis just got add together, but the Z axis of the Link transform is actualy in the Y direction of the Base Frame.
The 100 in Z axis of the Link transform is relative to the Joint Frame.
So what Compose Transform did was to consider that both the Joint and the Link transform were relative to the Base, but in this case that would be wrong.
But if we want to know the transform of the Link relative to the Base, we need to switch the pins.
That is because Unreal Invert the transforms in code.
KismetMathLibrary.h more preciselyTransformVectorized.h
That is necessary because in math you do matrix multiplication from right to left, so A is applied first then B.
Result Transform.
Now we can see that the Link Frame is 100 in Y axis and 150 in Z axis that is relative to the Base Frame. And the rotations also are correct, it is an Euler-ZYX rotation of Z(0),Y(-90),X(90). It takes the Base Frame and transform it in the Link Frame.
Now that we have the Link Frame relative to the Base Frame, what if we want the Base relative to the Link? Just use the Invert Transform.
Result Transform.
You can also achieve the same result using Get World Transform
So if you want to know the Link β Base transform you can Compose Transform all elements in the chain, like Link β Joint β Others β Base, but because you have the World Frame as a common Frame for all transforms, you can simply compose two Actor/Component directly.
This will result in Link β Base transform in the same way that Compose Transform the Link and Joint relative tranform.
In general the math is as follow.
B = Base Frame.
L = Link Frame.
W = World Frame.BLT = Link relative to Base transform Link β Base.
WBT = Base relative to World transform Base β World.
BWT = (WBT)-1 = World relative to Base transform World β Base, just apply Invert Transform to the Base β World transform.
WLT = Link relative to World transform Link β World.
BLT = BWT * WLT