hololensurhosharpurho3d

Spatial Anchor with Urho on HoloLens


Does anybody know how to use Spatial Anchors with Urho? I've looked at all the samples, didn't find anything. Nothing in the documentation either. I tried using 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.


Solution

  • You can create spatial anchors like this

    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-handed coordinate system while HoloLens API has a right-handed coordinate system hence the minus z.

    You can map an anchor to the current system like this:

        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
        }