RE: ECEF → Unreal position and rotation transformation.
Greetings!
I am building a flight simulator visualization tool. I have an external program which streams aircraft state information (ECEF position and ECEF quaternion) into Unreal Engine. I have setup a Cesium world terrain and added a CesiumGeoreference
. The origin of my CesiumGeoreference
is the same as the initial latitude, longitude, altitude conditions of my external simulator.
In C++ Unreal, I am trying to set the position and orientation of an aircraft. This aircraft is instantiated in as an InstancedMeshComponent
. I am attempting to set its position and rotation by modifying its corresponding InstanceTransform
, like so:
FTransform InstanceTransform(
EngineRotationQuat,
EngineLocation,
FVector(1.0f, 1.0f, 1.0f)
);
InstancedMeshComponent->UpdateInstanceTransform(
*InstanceIndexPtr,
InstanceTransform,
false, // don't update bounds
true // mark render state dirty
);
Currently, I am (incorrectly) performing the ECEF->unreal transformation like so:
EngineRotationQuat
and EngineLocation
are currently being computed like so:
GeoReferencingSystem->ECEFToEngine(position_ecf_m, EngineLocation);
FMatrix ECEFRotationMatrix = quaternion_ecf.ToMatrix();
FMatrix ECEF2Unreal = CesiumGeoreference-> ComputeEastSouthUpAtEarthCenteredEarthFixedPositionToUnrealTransformation(position_ecf_m);
FMatrix UnrealRotationMatrix = ECEF2Unreal * ECEFRotationMatrix;
EngineRotationQuat = UnrealRotationMatrix.ToQuat();
When I send the ECEF quaternion corresponding to level flight (not the pure quaternion), I expect to see my aircraft in unreal with a ‘straight an level’ attitude, but this is not the case.
For context, I have implemented an equivalent functional aircraft renderer in CesiumJS by simply setting the position and quaternion of the entity without any transformations, and it works perfectly:
viewer.entities.add({
name: "Aircraft",
position: new Cesium.CallbackProperty(() => this.getPosition(), false),
orientation: new Cesium.CallbackProperty(() => this.getOrientation(), false)
});
Any help would be greatly appreciated. Thanks!