Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

My hologram is drifting when the parent transform comes from a WorldAnchor point. What am I doing wr

Yes, I seem to have a concept or two wrong in my head. I read the notes on Spatial Anchors

The particular paragraph I was interested in was:-

Group holograms that should form a rigid cluster
Multiple holograms can share the same spatial anchor if the app expects those holograms to maintain fixed relationships to one another.
For example, if you are animating a holographic solar system in a room, it's better to tie all of the solar system objects to a single anchor in the center, so that they move smoothly relative to each other. In this case, it is the solar system as a whole that is anchored, even though its component parts are moving dynamically around the anchor.

Now I tried to follow this recipe by adding in a single WorldAnchor position (red sphere) along with 8 'dependent' spheres ( a 9th is logged being always at (0,0,0)). This picture originally looks like this:-

I save the WorldAnchor along the lines of previous scripts seen in these Q & A's by Patrick et al. I save a serialized version of my dependent points in an XML file to be reloaded later.

As part of the serialization process the snippet looks like this:-

            //The gameobject (white sphere) that I want to record position information for
            marker = go;
            //for what its worth I save the absolute position
            originalposition = pos;
            //I return a pointer to a WorldAnchor GameObject (red sphere)that has the closest distance to the observation I have (white sphere)
            //Please note in the example I have given, there is only a single anchor point and this is within 3 meters of the target
            //as guideline suggest
            var wa = posmarker.get_nearest_world_anchor(marker);
            if (wa == null)
                posmarker.record_it("worldanchor is null");
            //Read the name of the WorldAnchor to be identified later when deserializing the object.
            wa_id = wa.name;
            //make the parent transform of my current white sphere be the same as the chosen WorldAnchor transform
            marker.transform.parent = wa.transform;
            //IS THIS THE DODGY BIT???
            offset = pos - wa.transform.position;
            //We save this when serializing our 
            marker.transform.localPosition = offset;

When I deserialize the object later after the WorldAnchorStore has been reloaded and my scene shows all the red spheres depicting the positions of the anchors (in our example only one appears), I then reload and deserialize the XML file holding the local data. Here is the snippet I use:-

    public savedsphere(serial_object so)
        //Please note 'serial_object' holds the deserialozed data
        ptype = so.ptype;
        originalposition = so.originalposition;
        //This offset is set to the relative position from the closest WorldAnchor position (red sphere)
        offset = so.offset;
        //The name of the WorldAnchor that is closest to the position
        wa_id = so.wa_id;
        posmarker.anchor_now = false; //ignore this - my internal bookkeeping
        marker = posmarker.create_sphere(this.originalposition);//create a sphere somewhere 
        marker.transform.localScale = Vector3.one * 0.04f;
        //find the world anchor that has the same id as the one anchoring our current white sphere observation
        var wa_savedpos = posmarker.anchors.Find(item => item.wa_id == wa_id);
        if (wa_savedpos != null)
            //find the pointer to the WorldAnchor GameObject
            var wa = posmarker.get_worldanchor(wa_savedpos.marker);
            if (wa != null)
                //Set this marker's parent transform the same as the WorldAnchor transform
                marker.transform.SetParent(wa.transform, false);
                //now set the loal position to be offset from this parent position!!!
                marker.transform.localPosition = offset;//********** local offset from world anchor position!!
        //savedmarker(this.ptype, this.originalposition, marker);

Now I am certain there must be an error or maybe even several here in the way I have written or approached this as loading up my XML file later shows erratic and almost random drift. Which I guess means that my local positioning is not the correct way of going about it.

Is there anyone who can give advice on this please?


  • sptspt ✭✭
    edited October 2016

    First, to convert between world and local position, you should use Transform.TransformPoint and Transform.InverseTransformPoint.

    Next, you can just store just the localPosition of your objects, then you shouldn't even need to do transformations.

  • Thank you, I'll try that tomorrow.

  • Thank you spt for your suggestion. I have to say even if I use Transform.TransformPoint and Transform.InverseTransformPoint I still get a drift problem. So probably the problem is elsewhere in my own code otherwise others would complain about this I am sure.

    I still am unsure about the resolution to this so I have made every single one of my points a WorldAnchor point thereby getting my holographic framework to be steady no matter which room I go into. This probably is not best practice and I am sure I will get complainants about this. However it does lead to stability. I have noticed that after a while sometimes these Anchor points do move in a non-linear fashion not to return to their usual site again. I just hope someone out there could explain this as nothing has changed in my coding since I ran it last. I would dearly like to know what is the general algorithm to control the adjustment of WorldAnchor points? I gather the larger the WorldAnchor population you have the worse the book-keeping is to keep it in an optimum way. Does Microsoft use voxel color information and distance to estimate the best position of each WorldAnchor point for instance? It would be nice to know this information so we could plan our Apps out more sensibly.

  • sptspt ✭✭
    edited October 2016

    You will see some drift as the hololens updates its information about the room.
    This is why Young Conkers, for example, has you scan the room first. The more information you start with the less new information will cause drift.

    Another factor is lighting. In certain lighting conditions the hololens has trouble tracking. It is obvious in really dark situations, but there are also some situations where it looks really bright and well lit to a human eye, but the hololens can't quite make it out. So sometimes as you walk around the room, like into a corner, you might see stuff jump around as the hololens is having an epiphany about the room's dimensions.

  • Greetings spt. Yes I observed the same effect you are referring to. Certainly as the day creeps by and lighting angles and intensity change, the recognition part of the Hololens tries very hard to 'see the same things in a different light' . What I just don't get is even if I save and reload relative positioning information from a file and apply that as an offset to the parent WorldAnchor point, I still get it drifting away from that position. I must have a program problem with this but just can't see it yet.

    I must say, despite my irritation with the device and its stability, I am still awed by what they have achieved here.

Sign In or Register to comment.