Azure / azure-object-anchors

Azure Object Anchors releases and samples
https://docs.microsoft.com/azure/object-anchors
MIT License
37 stars 17 forks source link

Relationship between SpatialGraphLocation and Unity coordinates #38

Closed Jversen closed 2 years ago

Jversen commented 2 years ago

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);
craigktreasure commented 2 years ago

Closing this as you have figured it out.