Search Unity

Hololens camera tracking behaviour

Discussion in 'AR/VR (XR) Discussion' started by cellarmation, Nov 22, 2017.

  1. cellarmation

    cellarmation

    Joined:
    Jan 17, 2015
    Posts:
    30
    I am trying to use the Hololens with an external tracking source. I have an external application streaming in positional data in headset relative coordinates. In Unity I decode this data and place an object relative to the location of the camera during Update(). I haven't found any way to stop Unity adjusting the transform of the camera, so I have just been placing the object taking into account the camera's transform during Update(). I have tried this via calculation, and via placing the object as a child of the camera.

    I am sure the transformation maths is correct as I can check for alignment. Moving the tracked object works well, but some of the time the tracking can be very jittery especially if the headset is moving. I suspect that Unity's automatic adjustment of the camera's transform using the Hololen's internal tracking system is clashing with what I am trying to do. When does the camera's transform get updated in the sequence of the event functions? Is it updated more than once per Update()? Is there any way to stop Unity moving the camera?

    The behaviour I see appears to vary between the editor, emulator and headset, and build configuration.

    I have produced a simplified scene which potentially shows some of the issue I am seeing. In this scene two spheres are placed head-locked in front of the user's vision. The top sphere is a child of the camera. The bottom sphere sits at the scene level, but has a script that places it relative to the camera:
    HololensExternalTracking.png

    Code (CSharp):
    1. void Update()
    2. {
    3.  Vector3 relPos = new Vector3(0, -0.25f, 4);
    4.  Quaternion relRot = Quaternion.identity;
    5.  gameObject.transform.position = (Camera.main.transform.localRotation * relPos) + Camera.main.transform.localPosition;
    6.  gameObject.transform.rotation = Camera.main.transform.localRoation * relRot);
    7. }
    Some of the time the bottom sphere will separate from the top sphere. Can anyone provide some insight in to why this might happen? The child approach works well in this simplified context, but only because it at a fixed offset. If I tried to dynamically adjust its relative position during Update() I would get similar issues to the bottom sphere.
     
  2. summertao

    summertao

    Joined:
    Feb 10, 2017
    Posts:
    1
    Hi. I am facing the same question. I create a gameobject in unity and make it parent of the hololens camera, on app start i disable the hololens position tracking, then i update the parent object with the external position data streaming from the device on top of the hololens, and let hololens control its own rotation. It seems the position not adjust very well and still a little jittery when hololens is moving.
    Do you find any solution to the problem? Could you share your idea if you have some?