Spatial Anchor with Urho on HoloLens

Does anyone know how to use spatial anchors with Urho? I looked through all the samples, found nothing. Nothing in the documentation. I tried using the regular holographic API:

    var store = await SpatialAnchorManager.RequestStoreAsync();
    var anchors = store.GetAllSavedAnchors();
    store.TrySave("myanchor", SpatialAnchor.TryCreateRelativeTo(???SpatialCoordinateSystem???));

but I don’t know where to get the spatial coordinate system from.

+4
source share
1 answer

You can create spatial anchors such as

var anchor = SpatialAnchor.TryCreateRelativeTo(UrhoAppView.Current.ReferenceFrame.CoordinateSystem, new System.Numerics.Vector3(x, y, -z));
store.TrySave("anchorname", anchor);

Note that Urho has a left coordinate system, while the HoloLens API has a right coordinate system, therefore, minus z.

You can anchor the anchor to the current system as follows:

    var matrix = store["anchorname"].CoordinateSystem.TryGetTransformTo(UrhoAppView.Current.ReferenceFrame.CoordinateSystem);
    if (matrix.HasValue)
    {
       System.Numerics.Vector3 scale;
       System.Numerics.Quaternion rotation;
       System.Numerics.Vector3 translation;

       System.Numerics.Matrix4x4.Decompose(matrix.Value, out scale, out rotation, out translation);

       var q = new Quaternion(rotation.X, rotation.Y, rotation.Z, rotation.W);

       var v = new Vector3(translation.X, translation.Y, -translation.Z);// -Z Right-handed to left-handed
    }
+1
source

Source: https://habr.com/ru/post/1671227/


All Articles