Azure/azure-object-anchors

Relationship between SpatialGraphLocation and Unity coordinates

Closed this issue · 1 comments

When detecting a model and acquiring an ObjectInstance, the SpatialGraphLocation has the pose information about the object. I'm trying to place a GameObject at the same position as the real world object, but setting its transform position to the same one as in the SpatialGraphLocation does not match the position in the room at all.

Is there any kind of conversion needed to go from the SpatialGraphLocation Pose to Unity's standard coordinate system or am I missing something else?

Update

I finally got it working by first converting the SpatialGraphCoordinateSystem to SpatialCoordinateSystem.

SpatialGraphCoordinateSystem coordinateSystem
[...]

//After getting an ObjectInstance instance
SpatialCoordinateSystem spatialCoordinateSystem = instance.TryGetCurrentState().Center.ToSpatialCoordinateSystem();
var instancePos = spatialCoordinateSystem.TryGetTransformTo(coordinateSystem.Value.ToSpatialCoordinateSystem()).Value.ToUnityLocation().Position;
var instanceOrientation = spatialCoordinateSystem.TryGetTransformTo(coordinateSystem.Value.ToSpatialCoordinateSystem()).Value.ToUnityLocation().Ori;

//Place my hologram on the detected position
mySphere.transform.SetPositionAndRotation(instancePos, instanceOri);

Closing this as you have figured it out.