Transform from Local Space to World Space?

So if you have two transforms, let’s say: A and B.
You can get the B transform’s relative location to the transform A by doing B.GetRelativeTransform(A) let’s store the value of that into C. Now C represents B’s location in the local space of A.

So, the problem is: is there any way to reverse the FTransform::GetRelativeTransform in a way that we could get the transform B by knowing only A and C (AKA get the C transform in the world space).

I’m 99% sure there is a way to do it and I probably could write it my self, but it wouldn’t make any sense for the FTransform API to not include it then.

I’m also aware that there is a function FTransform::GetRelativeTransformReferse but that doesn’t seem to be what I’m looking for, in fact I think A.GetRelativeTransform(B) == B.GetRelativeTransformReverse(A);

This could also be one of those cases where I miss something pretty obvious, since I’m pretty tired currently.

Anyhow, thanks for the help :slight_smile:

1 Like

is this what you are looking for ? Link

1 Like

I don’t think FTransfrom has anything innately, but AActor::ActorToWorld I think does what you want. Maybe take a look at that function. There’s also one for ComponentToWorld

In the end they all call this function
USceneComponent::UpdateComponentToWorldWIthParent ← Id check there and break it down

3 Likes

Well, there you use the USceneComponent’s API to get it’s world transform, my problem however is how to get the world space transform by only having the two transforms: A in the world space and B that is relative to A.

I find it pretty weird how the function GetWorldTransform does not exist for FTransform (as GetRelativeTransform does).

I Guess one way of achieving my goal would be to construct two scene components, give those the transforms A and B and use the USceneComponent::GetWorldTransform there. Though that would be so wacky that I rather wouldn’t do it that way…

1 Like

Good idea @Rumzie

I’m going to check out those functions tomorrow, since it’s already midnight here.

Hopefully I can find the solution there :grin:

2 Likes

I’ve found for a number of reasons that using SceneComponents to do any kind of hierarchal transformation always ends up benefitting me in the long run.

Especially in cases where you run into dealing with 3+ coordinate spaces all stacked on each other. Sometimes it’s just nice to see it all visually in the editor that way.

It can seem pretty bloated to do it that way I agree, but it’s never been a bottleneck for me personally.

2 Likes

This is what I got, hopefully it works for you, I tested a couple scenarios and it seems to work.

FTransform ACodeFiveCharacter::CalculateReverseT(const FTransform& A, const FTransform& C)
{
	FTransform Result;

	FVector SafeRecipScale3D = A.GetSafeScaleReciprocal(C.GetScale3D(), SMALL_NUMBER);
	Result.SetScale3D(A.GetScale3D() * SafeRecipScale3D);

	const FQuat Inverse = C.GetRotation().Inverse();
	Result.SetRotation(A.GetRotation() * Inverse);
	Result.SetTranslation(A.GetTranslation() - ((A.GetRotation() * (Inverse * C.GetTranslation())) * SafeRecipScale3D));

	return Result;
}
4 Likes

Yeah I believe that could be beneficial in many cases, not just in mine.

I have a component that has an array of relative transforms and they have an application where they must be converted to world space, they can’t be in world space initially however since they are relative to the owning actor of the component.

So the reason I think having a scene component for every transform is not a good idea is the fact that there might be tens of transforms in the array. The unnecessary bloat that would come by having that many components for just one function use is a bit too much in my mind.

Thanks for the help anyway :slight_smile:

This is what I see the best solution in hand, so I’m going to go with it.

Thanks for @KaidoomDev and all of you for helping me. :grin:

I still just find it so weird how something like @KaidoomDev 's function isn’t included in the FTransform API. Maybe the people at Epic had a stroke or something while writing it idk XD

2 Likes

Don’t use Ftransform, you are going to run into problems when transforming if you want to do other stuff. Use vectors directly to transform.

1 Like