Skip to main content
Up and Coming
September 3, 2014

DK2 Head and Position tracking - simple code / Sensor Box

Hi,

With the DK1 I had been using the modified Sensor Box sample code to read out head tracking data and send it to another program via shared memory.

With the DK2 there is no updated Sensor Box sample to build onto. While it might be relatively straightforward to accomplish, before starting to write something on my own, I'd like to ask if someone has already updated this simple program to work with DK2 or even include positional tracking.
Or maybe, is there already some other sample code in the internet which can just output head tracker / positional data?

Thank you!

    5 replies

    kojack
    Honored Contributor
    September 3, 2014
    Here's a little minimal example:
    	ovr_Initialize();
    m_hmd = ovrHmd_Create(0);
    ovrHmd_ConfigureTracking(m_hmd, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, 0);
    int frame = 0;
    while (true)
    {
    ovrHmd_BeginFrameTiming(m_hmd, frame);
    ovrPosef pp = ovrHmd_GetEyePose(m_hmd, ovrEyeType::ovrEye_Left);
    cout << pp.Position.x << " " << pp.Position.y << " " << pp.Position.z << endl;
    ovrHmd_EndFrameTiming(m_hmd);
    frame++;
    }

    pp contains a position (vector 3) and orientation (quaternion).

    Instead of ovrHmd_GetEyePose (which gets just one eye) you can use ovrHmd_GetTrackingState (should be the whole rift). ovrHmd_GetEyePose is supposed to be used to get the values for the camera before rendering each eye. There's also an order that should be followed to give best results on the DK2's sideways screen (it scans sideways instead of top to bottom), the sdk can tell you that.
    But for simple example access to tracking data, the above code works fine.
    Author: Oculus Monitor , Auto Oculus Touch , Forum Dark Mode , Phantom Touch Remover , X-Plane Fixer Hardware: Threadripper 1950x, MSI Gaming Trio 2080TI, Asrock X399 Taich Headsets: Wrap 1200VR, DK1, DK2, CV1, Rift-S, GearVR, Go, Quest, Quest 2, Reverb G2, Quest 3
    Up and Coming
    September 4, 2014
    Thanks a lot for the code sample. I'll give it a try and see how it goes!

    Cheers!
    Up and Coming
    September 5, 2014
    Hi kojack,

    I'm trying to run your minimal example and am getting there. Unfortunately I can't get the HMD to initialise, since I have not plugged in the HDMI cable. It has to work without the HDMI cable connected, since the aim is to get head tracking data while at the same time connect the Oculus HDMI display to another PC.

    On the DK1, this was working without a problem.

    If you've got any tips on how to achieve initialising the HMD (ovrHmd_Create) or any other way to connect to the sensor without this, that would be greatly appreciated!

    Thanks!


    "kojack" wrote:
    Here's a little minimal example:
    	ovr_Initialize();
    m_hmd = ovrHmd_Create(0);
    ovrHmd_ConfigureTracking(m_hmd, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, 0);
    int frame = 0;
    while (true)
    {
    ovrHmd_BeginFrameTiming(m_hmd, frame);
    ovrPosef pp = ovrHmd_GetEyePose(m_hmd, ovrEyeType::ovrEye_Left);
    cout << pp.Position.x << " " << pp.Position.y << " " << pp.Position.z << endl;
    ovrHmd_EndFrameTiming(m_hmd);
    frame++;
    }

    pp contains a position (vector 3) and orientation (quaternion).

    Instead of ovrHmd_GetEyePose (which gets just one eye) you can use ovrHmd_GetTrackingState (should be the whole rift). ovrHmd_GetEyePose is supposed to be used to get the values for the camera before rendering each eye. There's also an order that should be followed to give best results on the DK2's sideways screen (it scans sideways instead of top to bottom), the sdk can tell you that.
    But for simple example access to tracking data, the above code works fine.
    kojack
    Honored Contributor
    September 5, 2014
    From some quick testing, it appears you can't use the DK2 tracking without the hdmi cable attached.
    The DK2 goes into standby if the hdmi is unplugged.
    "psychophysics" wrote:
    since the aim is to get head tracking data while at the same time connect the Oculus HDMI display to another PC.

    That might work. I haven't tested yet. I don't know if headset creation is failing due to the rift being in standby mode (so hooking hdmi to a different pc would power it up) or if it needs to detect the rift via hdmi to know it's available. I'm guessing the latter.
    Author: Oculus Monitor , Auto Oculus Touch , Forum Dark Mode , Phantom Touch Remover , X-Plane Fixer Hardware: Threadripper 1950x, MSI Gaming Trio 2080TI, Asrock X399 Taich Headsets: Wrap 1200VR, DK1, DK2, CV1, Rift-S, GearVR, Go, Quest, Quest 2, Reverb G2, Quest 3
    Up and Coming
    September 6, 2014
    Thanks for testing and your thoughts. I'll play around with it a bit.