concept action in category oculus rift

appears as: ctions, ction, action
Oculus Rift in Action

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

update() is a virtual GlfwApp member function that is called once per frame, and is specifically for doing actions which manage the state or impact the output of the application, but which  are not themselves rendering commands.  Technically you could put anything you wanted in there, including OpenGL rendering instructions, but that would be foolish (figure 2.10).

Well, there are plenty.  For one thing, there may be times when you want to know what the head pose is outside of the rendering loop.  For example, if the user leans their head forward or to the side, that may need to trigger some event or action within the application.  In such a case it would be advantageous to have a stored pose that is updated once per frame, rather than once per eye, and use that as the aggregate head pose for the user as a whole. 

Listing 4.3: Distorting a scene image using a lookup texture
#include "Common.h" Resource SCENE_IMAGES_DK1[2] = { #A Resource::IMAGES_TUSCANY_UNDISTORTED_LEFT_DK1_PNG, Resource::IMAGES_TUSCANY_UNDISTORTED_RIGHT_DK1_PNG }; Resource SCENE_IMAGES_DK2[2] = { #A Resource::IMAGES_TUSCANY_UNDISTORTED_LEFT_DK2_PNG, Resource::IMAGES_TUSCANY_UNDISTORTED_RIGHT_DK2_PNG }; class DistortedExample : public RiftGlfwApp { #B protected: Texture2dPtr sceneTextures[2]; #C ovrTexture eyeTextures[2]; #D public: void initGl() { #E RiftGlfwApp::initGl(); Resource * sceneImages = SCENE_IMAGES_DK2; #F if (hmd->Type == ovrHmd_DK1) { #F sceneImages = SCENE_IMAGES_DK1; #F } #F for_each_eye([&](ovrEyeType eye){ #H glm::uvec2 textureSize; #I sceneTextures[eye] = oria::load2dTexture(sceneImages[eye], textureSize);#I memset(eyeTextures + eye, 0, #J sizeof(eyeTextures[eye])); #J ovrTextureHeader & eyeTextureHeader = #J eyeTextures[eye].Header; #J eyeFovPorts[eye] = hmd->DefaultEyeFov[eye]; #J eyeTextureHeader.TextureSize = #J Rift::toOvr(textureSize); #J eyeTextureHeader.RenderViewport.Size = #J eyeTextureHeader.TextureSize; #J eyeTextureHeader.API = ovrRenderAPI_OpenGL; #J ((ovrGLTextureData&)eyeTextures[eye]).TexId = #L sceneTextures[eye]->texture; #L }); ovrRenderAPIConfig cfg; #K memset(&cfg, 0, sizeof(cfg)); #K cfg.Header.API = ovrRenderAPI_OpenGL; #K cfg.Header.RTSize.w = windowSize.x; #K cfg.Header.RTSize.h = windowSize.y; #K cfg.Header.Multisample = 1; #K int distortionCaps = ovrDistortionCap_Vignette #K | ovrDistortionCap_Chromatic; #K #if defined(OVR_OS_WIN32) #K ((ovrGLConfigData&)config).Window = 0; #K #elif defined(OVR_OS_LINUX) #K ((ovrGLConfigData&)config).Win = 0; #K ((ovrGLConfigData&)config).Disp = 0; #K #endif #K ovrEyeRenderDesc eyeRenderDescs[2]; #K int configResult = ovrHmd_ConfigureRendering(hmd, &cfg, #K distortionCaps, hmdDesc.DefaultEyeFov, eyeRenderDescs); #K if (0 == configResult) { #K FAIL("Unable to configure rendering"); #K } #K ovrhmd_EnableHSWDisplaySDKRender(hmd, false); #Q } virtual void finishFrame() { #R } void onKey(int key, int scancode, int action, int mods) { if (action == GLFW_PRESS) { static ovrHSWDisplayState hswDisplayState; ovrHmd_GetHSWDisplayState(hmd, &hswDisplayState); if (hswDisplayState.Displayed) { ovrHmd_DismissHSWDisplay(hmd); return; } } RiftGlfwApp::onKey(key, scancode, action, mods); } virtual void finishFrame() { } void draw() { #M static int frameIndex = 0; static ovrPosef poses[2]; glClear(GL_COLOR_BUFFER_BIT); ovrHmd_BeginFrame(hmd, frameIndex++); #N ovrHmd_EndFrame(hmd, poses, eyeTextures); #N } }; RUN_OVR_APP(DistortedExample) #A Undistorted screen grabs from the Tuscanny demo, one per eye. Note that we have different images for the DK1 and DK2 models, because they have different projections. #B Our application derives from RiftGlfwApp, which takes care of creating the HMD handle and the OpenGL window in the proper location #C Our OpenGL wrappers for the per-eye texture data. #D Oculus SDK structures for holding information about the textures. #E Most of our SDK setup can only be done after the OpenGL context has been created, so we do it in this function #F We use the type variable inside the HMD instance to determine which pair of images we should be using. #G Setting a background color other than black makes it easy to distinguish the area on the screen rendered to by the distortion effect versus the un-rendered background. #H Per-eye setup of the textures #I Load the per-eye image our of our resources into OpenGL #J Initialize the SDK texture structure #L The Oculus API expects the non-API specific ovrTexture, but we need to cast the type into a ovrGLTextureData type in order to set the texture ID in the structure. If you’re working with Direct3D you’d need to cast to ovrD3D11Texture or one of the other DirectX compatible texture types #K Set up the SDK distortion functionality. Note again we have platform specific code that we need to initialize. #Q In our code we disable the health and safety warning, which would otherwise automatically be displayed by the SDK #R We override the finishFrame method of the parent class to prevent our application from performing the OpenGL buffer swapping, because the SDK will be doing it instead. #M Our per-frame drawing call #N The SDK requires that distorted frames be book-ended by these begin/end frame calls. Normally we would render our scene in between them, but since we’re working with static textures there’s no work to be done.
Figure 9.7:  Ray casting in action.  After choosing a ray origin (the camera eye) and computing the direction from the origin through the center of each pixel, we choose the color of the pixel based on the object in the scene hit by the ray.