Set Actor rotation from ecef forward up vectors

I have models that are simulated in ecef coordinates. I have successfully set their corresponding ue4 actors position using the georeference MoveToEcef function (I add the georeference component to my aktors). I am, however having trouble setting the rotation. I have a rotation matrix describing the ECEF rotation to body system. Ie I can easily get the forward an up vectors expressed in ecef coordinates.
I can also get the rotation in ENU (but at a computational cost), at some ecef coordinate.
I am using c++.

My current setup is as follows:

FRotator ueRotator = GeoRef->Georeference->TransformRotationEnuToUe(
   {posEcef.x, posEcef.y, posEcef.z});


Where my ‘GetENURotator’ is implemented like this:

// east north, down are vectors in ecef frame
glm::dvec3 down = -glm: :normalize(posECEF); // simplified inaccurate 
glm::dvec3 east = glm::normalize(glm::cross(down, {0.0,0.0,1.0}));
glm::dvec3 north = glm::normalize(glm::cross(east,down));
glm::dmat3x3 T_ENU_ECEF(east.x, north.x, -down.x, east.y, north.y, -down.y, east.z, north.z, -down.z);

glm::dvec3 forwardENU =  T_ENU_ECEF*forwardECEF;
glm::dvec3 upENU =  T_ENU_ECEF*upECEF;

return UKismetMathLibrary::MakeRotFromXZ({forwardENU.x, forwardENU.y, forwardENU.z},{upENU.x, upENU.y, upENU.z});

This don’t get absolutely correct however. I guess I somehow will have to form my transform at the GeoRef origin instead of at my entity location?

How do I do this?
Thank you!

Hello @Emil,

I think you are looking for CesiumGeoreference::GetEllipsoidCenteredToUnrealWorldTransform, you could do something like this:

const glm::dmat4& ecefTransform = //The ECEF transform matrix for your model.
const glm::dmat4& ecefToUeAbs = 

// The transformation matrix for your model in Unreal absolute world.
glm::dmat4 ueAbsTransform = ecefToUeAbs * ecefTransform;

// Remember you have to subtract out the world origin to get to Unreal relative world,
// which is what actual Unreal coordinates are specified in.
glm::dmat4 ueTransform = ueAbsTransform;
ueTransform[3] -= worldOrigin;

// Now turn ueTransform into an FMatrix and you can use AActor->SetActorTransform