Convert a quaternion from world space to component space

Hi,

I am using quaternions to update an object’s rotation. I need to compute the local-space value of a quaternion from its world-space value, but I can’t manage to found how to.do it.

Any ideas ?

Hey Gween if i was you i’ll rotation matrix because anyway your problem is a mathematic one and what you need to do is to convert value from one coordinate system to another am i right ?

As i understand you the global values of your rotation related to the origin of the level (0,0,0)

so “All you need” to do is to find the matrix to pass from one coordinate system to another.

  1. First you’ll probably need made a change of base
  2. Do others stuff

The best advice i can give you is take a look at mathematic how to Pass from one coordinate system to another. All Good Linear algebra book will have a 3d section and how do it.

Personnally i always keep my book around me.

If you need a concrete example i can build you one or if you need help just tell me

gamer08

Here what i use, get Rotator from FQuat then get the local rotator then converse back to Quat

FQuat WorldQuat;
FRotator WorldRotator = WorldQuat.Rotator();

FTransform ParentWorldTransform;

FVector Forward = ParentWorldTransform.InverseTransformVector(FRotationMatrix(WorldRotator).GetScaledAxis(EAxis::X));
FVector Right = ParentWorldTransform.InverseTransformVector(FRotationMatrix(WorldRotator).GetScaledAxis(EAxis::Y));
FVector Up = ParentWorldTransform.InverseTransformVector(FRotationMatrix(WorldRotator).GetScaledAxis(EAxis::Z));

FMatrix RotMatrix(Forward, Right, Up, FVector::ZeroVector);

FQuat LocalQuat = RotMatrix.ToQuat();

Thanks ! I guess I need to initialize ParentWorldTransform using GetComponentTransform() on the root component ?

The code seems to work - I’ll be back tomorrow for more info on it. Thanks !

Yeah, you can get any transform if you want as long as it from same Space with Quaternion you want to converse to local.

Confirmed working! Thanks !

This seems very logical but also seems computationally intensive. What are the advantages over the more traditional approach?

FQuat LocalQuat = (ParentWorldTransform.GetRotation().Inverse() * WorldQuat);

Other than that the FQuat multiplication order in UE is super confusing (maybe that’s just to me).

Often I double check by referencing FTransform::GetRelativeTransform(const FTransform& Other)'s implementation.

1 Like