concept HMD in category oculus rift

appears as: HMD, HMD
Oculus Rift in Action

This is an excerpt from Manning's book Oculus Rift in Action.

If you plan on running applications built with Oculus SDK 0.3 or earlier on DK1, you should select DK1 Legacy App Support. As we expect that you will be developing on the latest SDK, we won’t spend much time on this option. For applications built on 0.4 or later, you have the choice between two display modes: Direct HMD Access from Apps and Extend the Desktop to the HMD. To help you decide which mode to use, Table 1.1 shows the pros and cons of each mode.

Table 1.1: Rift Display Modes: pros and cons

Display Mode

Advantages

Disadvantages

Direct HMD Access from Apps

Better performance

 

Provides an option to mirror the Rift display on your desktop so that you can see what is on the Rift without wearing the Rift

 

No need to configure displays in your OS

Not currently available for MacOS or Linux

 

Unstable

Extend Desktop to the HMD

Only configuration for MacOS

 

Stable

Requires display configuration

 

There is a portion of the desktop where you can ‘lose’ windows or your mouse

 

You can’t normally see what is displayed on the Rift without wearing the Rift

Listing 3.3 Example_3_3_Tracker.cpp [Abridged]
#include "Common.h" class SensorFusionExample : public GlfwApp { ovrHmd hmd; glm::quat orientation; glm::vec3 linearA; glm::vec3 angularV; bool renderSensors{ false }; public: SensorFusionExample() { } virtual ~SensorFusionExample() { ovrHmd_Destroy(hmd); #A ovr_Shutdown(); } virtual GLFWwindow * createRenderingTarget( glm::uvec2 & outSize, glm::ivec2 & outPosition) { outSize = glm::uvec2(800, 600); outPosition = glm::ivec2(100, 100); Stacks::projection().top() = glm::perspective( PI / 3.0f, aspect(outSize), 0.01f, 10000.0f); Stacks::modelview().top() = glm::lookAt( glm::vec3(0.0f, 0.0f, 3.5f), Vectors::ORIGIN, Vectors::UP); GLFWwindow * result = glfw::createWindow(outSize, outPosition); ovr_Initialize(); #B hmd = ovrHmd_Create(0); #B return result; } void initGl() { GlfwApp::initGl(); glClearColor(0.1f, 0.1f, 0.1f, 1.0f); if (!hmd) { FAIL("Unable to open HMD"); } if (!ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation, 0)) { #C FAIL("Unable to locate Rift sensor device"); } } virtual void onKey(int key, int scancode, int action, int mods) { // ... } void update() { ovrTrackingState trackingState = #D ovrHmd_GetTrackingState(hmd, ovr_GetTimeInSeconds()); #D ovrPoseStatef & poseState = #E trackingState.HeadPose; #E orientation = ovr::toGlm( #F poseState.ThePose.Orientation); #F linearA = ovr::toGlm( #F poseState.LinearAcceleration); #F angularV = ovr::toGlm( #F poseState.AngularVelocity); #F } void draw() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gl::MatrixStack & mv = gl::Stacks::modelview(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); MatrixStack & mv = Stacks::modelview(); mv.withPush([&]{ mv.rotate(orientation); #G oria::renderRift(); #G }); // ... #H } }; RUN_OVR_APP(SensorFusionExample) #A Ensure we release our resources properly when we’re done. #B Acquire the handle to the headset (this is slightly out of the usual order, as explained in a moment) #C Enable the tracking sensors on the headset, requesting orientation data #D Once each frame, we fetch the current sensor data #E We are not interested in prediction at the moment, so we grab the instantaneous data from the returned sensor state. #F We convert from the OVR C API structures to the equivalent GLM types. We’re grabbing the current orientation, as well as the linear velocity and angular acceleration. #G We apply the orientation of the Rift to the modelview matrix and then render our model. #H The remainder of our draw function places some text with the current orientation on the screen in Euler angles, and optionally draws the 3D vectors for the linear velocity and angular acceleration readings we stored.