unity-game-enginehololenswindows-mixed-realityazure-spatial-anchors

Place content relative to an azure spatial anchor


I am working on a simple unity app testing azure spatial anchors on the HoloLens.

The documentation stats out here https://learn.microsoft.com/de-de/windows/mixed-reality/spatial-anchors that one can (or rather should) place holograms relative to a spatial anchor using the spatial anchors coordinate system. But i did not found any documentation on how i can achive this in code.

I took a look at this https://github.com/Azure/azure-spatial-anchors-samples unity example. As i understood it shows how to place a gameobject directly at the origin of a spatial anchor. But how can i achive that an object is always placed in a certain distance to the anchor in a specific direction e.g. using a 4x4 translation matrix or something similar?


Solution

  • There are a lot of ways to do this in Unity by manipulating game object transforms. You could try the following:

    1. Create a game object at the origin of the spatial anchor.
    2. Create a second game object.
    3. Set the second game object's transform's parent to be the first game object's transform.
    4. Update the local position and orientation of this second game object to be at the offset you desire from the spatial anchor.