0

I am having trouble getting the position of an object in world coordinates, using TryGetTransformTo.

The results are very incoherent.

WHAT I AM DOING

I understand that world coordinate system is the coordinate system of a spatial stationary frame set in the beginning of the program, as said in the doc here. The device coordinate system can be gotten thanks to an attached reference frame, which follows the device.

How I get the device coordinate system ( in Update function, so called each frame) :

HolographicFramePrediction prediction = holographicFrame.CurrentPrediction();
m_attachedReferenceFrame = m_spatialLocator.CreateAttachedFrameOfReferenceAtCurrentHeading();
SpatialCoordinateSystem deviceCoordinateSystem = m_attachedReferenceFrame.GetStationaryCoordinateSystemAtTimestamp(prediction.Timestamp());

m_spatialLocator is SpatialLocator::GetDefault(), set once at the beginning of the app,

How I get the world coordinate system (only once too)

m_stationaryReferenceFrame = m_spatialLocator.CreateStationaryFrameOfReferenceAtCurrentLocation();
m_worldCoordinateSystem = m_stationaryReferenceFrame.CoordinateSystem();

And finally, how I do the transform :

auto tryTransformMatrix = deviceCoordSystem.TryGetTransformTo(m_worldCoordinateSystem);
if (!tryTransformMatrix)
    return;
    
float4x4 transformMatrix = tryTransformMatrix.Value();
    
float3 devicePos = { 0.0f, 0.0f, -1.0f };
auto worldPos = transform(devicePos, transformMatrix);

devicePos is juste an simple example for testing, in practice there could be anything in its values.

The results are really wrong, if I don't move the Hololens worldPos = { 0.0f, 0.0f, -1.0f } (rounded up) so it's correct, if I rotate the device horizontaly it seems to stay correct but if I rotate horizontaly (for example, if the device is looking right at the sky), the results are wrong, the y coordinate does not move in worldPos.

Please keep in mind that devicePos is the position of an object IN the device coordinate system, so here the object is 1 meter in front of the Hololens, whatever orientation it has.

Do you have any ideas ? Thank you !

Nikow
  • 3
  • 2
  • Does "if I rotate horizontaly (for example, if the device is looking right at the sky), the results are wrong, the y coordinate does not move in worldPos" mean that rotating the HoloLens device vertically will not affect the Y axis in the coordinate system? It is probably by design. Can you describe the behavior you expect? If you can provide an [MCVE](https://stackoverflow.com/help/minimal-reproducible-example) we might be able to do some research. – Zuocheng Wang - MSFT May 04 '23 at 07:48

0 Answers0