Access to DK2's tracking state in C++

Hi there,

I am trying to access the tracking state (gyroscope, accelerometer, magnetometer) of the Oculus Rift DK2 in C++. The OculusWorldDemo does this by creating an instance of ovrHmd and calling ovrHmd_GetTrackingState. This does not seem to be possible in a UE4 project, because there is no ovrHmd. The only thing I can find is GEngine->HmdDevice which is an interface for any HMD - even those without sensors. So it cannot provide me with a tracking state.

Creating my own instance of ovrHmd cannot be the solution, because UE4 should take care of that.

Can anyone help me with this?

Hi Kepakiano,

You can access the class it extends IHeadMountedDisplay using GEngine. If you get this, you can get Orientation. If you want more, you can always add functions to the OculusRift (IHeadMountedDisplay) plugin to do this. It should look like something below.

IHeadMountedDisplay* riftHMD = Cast<FOculusRiftHMD>(GEngine->HMDDevice);
FQuat HMDOrient(riftHMD->GetBaseOrientation());

Hope this helps!

-Peter L. Newton

Hi Peter, thank you for your answer,

so, there is no way I can read the sensor values without modifying the engine’s source code? FOculusRiftHMD is in the private part of the plugin, so it’s not visible when I don’t compile the engine myself.
This is not a big problem now, but it might become one in the future :confused:

My way of solving the problem now would be the following:
Add the following three lines to IHeadMountedDisplay:

virtual FVector Get{Gyroscope,Accelerometer,Magnetometer}Readings const { return FVector(0.f,0.f,0.f);}

The HMDs implementing IHeadMountedDisplay can then decide to override this function. If not, the default value (0,0,0) is returned.
I would then override the functions in OculusRiftHMD.h and return the sensor readings.

I hope this is what you meant :smiley:

Is this a clean enough way to do or am I overseeing something?



Oculus have already implemented this on their own UE4 GitHub branch, but i think it’s still not integrated on the official 4.7.1 (haven’t checked).

Nice, now I won’t need to write the pull request myself ^.^
And there is a good chance that the proposed change will make it into UE4, right?

Thank you very much!