Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
psychophysics's avatar
psychophysics
Honored Guest
11 years ago

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

  • 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.
  • Thanks a lot for the code sample. I'll give it a try and see how it goes!

    Cheers!
  • 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.
  • 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.