void OVR::recenter() { if (NULL != m_hmd) { ovrHmd_RecenterPose(m_hmd); } }
void resetCamera() { player = glm::inverse(glm::lookAt( glm::vec3(0, eyeHeight, 0.3f), // Position of the camera glm::vec3(0, eyeHeight, 0), // Where the camera is looking GlUtils::Y_AXIS)); // Camera up axis ovrHmd_RecenterPose(hmd); }
void OculusVRSensorDevice::reset() { if(!mIsValid) return; ovrHmd_RecenterPose(mDevice); }
void VR_ResetOrientation() { cl.aimangles[YAW] = cl.viewangles[YAW]; cl.aimangles[PITCH] = cl.viewangles[PITCH]; if (vr_enabled.value) { ovrHmd_RecenterPose(hmd); VectorCopy(cl.aimangles,lastAim); } }
void RiftGlfwApp::onKey(int key, int scancode, int action, int mods) { if (!oria::clearHSW(hmd)) { if (GLFW_PRESS == action) { switch (key) { case GLFW_KEY_R: ovrHmd_RecenterPose(hmd); return; } } GlfwApp::onKey(key, scancode, action, mods); } }
virtual void onKey(int key, int scancode, int action, int mods) { if (GLFW_PRESS != action) { return; } switch (key) { case GLFW_KEY_S: renderSensors = !renderSensors; return; case GLFW_KEY_R: ovrHmd_RecenterPose(hmd); return; } GlfwApp::onKey(key, scancode, action, mods); }
void CubeScene::onKey(int key, int scancode, int action, int mods) { if (CameraControl::instance().onKey(key, scancode, action, mods)) { return; } if (GLFW_PRESS == action) { switch (key) { case GLFW_KEY_R: resetCamera(); ovrHmd_RecenterPose(hmd); return; } } RiftGlfwApp::onKey(key, scancode, action, mods); }
virtual void onKey(int key, int scancode, int action, int mods) { if (GLFW_PRESS != action && GLFW_REPEAT != action) { return; } switch (key) { case GLFW_KEY_S: if (0 == (mods & GLFW_MOD_SHIFT)) { renderSensors = !renderSensors; return; } break; case GLFW_KEY_R: ovrHmd_RecenterPose(hmd); return; } GlfwApp::onKey(key, scancode, action, mods); }
void OculusRift::keyDown(KeyEvent event) { //recenter camera forward if(event.isControlDown() && event.getChar() == 'r') ovrHmd_RecenterPose(mHmd); }
void ResetOrientation() { ovrHmd_RecenterPose(m_device); }
void OcculusCameraComponent::init() { ovr_Initialize(); parent->getStage()->getGame()->getGraphicsHandle()->setAutoBufferSwap( false ); hmd = ovrHmd_Create(0); if (hmd) { ovrSizei resolution = hmd->Resolution; resolution; } else { hmd = ovrHmd_CreateDebug( ovrHmdType::ovrHmd_DK2 ); } // Start the sensor which provides the Rift’s pose and motion. //ovrHmd_SetEnabledCaps(hmd, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction); ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, 0); ovrHmd_RecenterPose( hmd ); ovrFovPort eyeFov[2] = { hmd->DefaultEyeFov[0], hmd->DefaultEyeFov[1] } ; ovrGLConfig oglConfig; oglConfig.OGL.Header.API = ovrRenderAPI_OpenGL; oglConfig.OGL.Header.RTSize = OVR::Sizei(hmd->Resolution.w, hmd->Resolution.h); oglConfig.OGL.Header.Multisample = 1; oglConfig.OGL.Window = parent->getStage()->getGame()->getGraphicsHandle()->getHandle(); oglConfig.OGL.DC = parent->getStage()->getGame()->getGraphicsHandle()->getHDC(); #pragma comment(lib,"libovrd.lib") ovrBool result = ovrHmd_ConfigureRendering( hmd, &oglConfig.Config, ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette | ovrDistortionCap_TimeWarp | ovrDistortionCap_Overdrive, eyeFov, EyeRenderDesc); result; ovrHmd_AttachToWindow(hmd, oglConfig.OGL.Window, NULL, NULL); //Sets up FBOS // Configure Stereo settings. OVR::Sizei recommenedTex0Size = ovrHmd_GetFovTextureSize(hmd, ovrEye_Left, hmd->DefaultEyeFov[0], 1.0f); OVR::Sizei recommenedTex1Size = ovrHmd_GetFovTextureSize(hmd, ovrEye_Right, hmd->DefaultEyeFov[1], 1.0f); OVR::Sizei renderTargetSize; renderTargetSize.w = recommenedTex0Size.w + recommenedTex1Size.w; renderTargetSize.h = max ( recommenedTex0Size.h, recommenedTex1Size.h ); renderTarget = FrameBufferObject::createFrameBuffer( renderTargetSize.w, renderTargetSize.h ); //Set up viewports EyeRenderViewport[0].Pos = OVR::Vector2i(0,0); EyeRenderViewport[0].Size = OVR::Sizei(renderTarget->width / 2, renderTarget->height); EyeRenderViewport[1].Pos = OVR::Vector2i((renderTarget->width + 1) / 2, 0); EyeRenderViewport[1].Size = EyeRenderViewport[0].Size; EyeTexture[0].OGL.Header.API = ovrRenderAPI_OpenGL; EyeTexture[0].OGL.Header.TextureSize = renderTargetSize; EyeTexture[0].OGL.Header.RenderViewport = EyeRenderViewport[0]; EyeTexture[0].OGL.TexId = renderTarget->colorTexture->textureID; EyeTexture[1].OGL.Header.API = ovrRenderAPI_OpenGL; EyeTexture[1].OGL.Header.TextureSize = renderTargetSize; EyeTexture[1].OGL.Header.RenderViewport = EyeRenderViewport[1]; EyeTexture[1].OGL.TexId = renderTarget->colorTexture->textureID; }
void VR_OVR_ResetHMDOrientation() { if (hmd) ovrHmd_RecenterPose(hmd); }
void machine::setup(ofxXmlSettings * se) { ovr_Initialize(); hmd = ovrHmd_Create(0); if (!hmd || !ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation |ovrTrackingCap_MagYawCorrection |ovrTrackingCap_Position, ovrTrackingCap_Orientation |ovrTrackingCap_MagYawCorrection |ovrTrackingCap_Position)) { cout << "Unable to detect Oculus Rift" << endl; fboLeft.allocate(800,600); fboRight.allocate(800,600); } else { if (hmd->Type == ovrHmd_DK2 ) { cout << "Detected Oculus Rift DK2" << endl; fboLeft.allocate(DK2_WIDTH/2, DK2_HEIGHT); fboRight.allocate(DK2_WIDTH/2, DK2_HEIGHT); } else if(hmd->Type == ovrHmd_DK1) { cout << "Detected Oculus Rift DK1" << endl; fboLeft.allocate(DK1_WIDTH/2, DK1_HEIGHT); fboRight.allocate(DK1_WIDTH/2, DK1_HEIGHT); } } ovrHmd_RecenterPose(hmd); vidGrabberLeft.listDevices(); settings = se; setup_type = settings->getValue("settings:setup_type", ONE_WAY_SWAP); camera_type = settings->getValue("settings:camera_type", MONO); ipd = settings->getValue("settings:ipd", 8); camWidth = 1280; camHeight =1024; drift_correction = 0; if (camera_type == MONO) { vidGrabberLeft.setVerbose(true); vidGrabberLeft.setDeviceID(settings->getValue("settings:camera_id", 1)); vidGrabberLeft.setDesiredFrameRate(75); vidGrabberLeft.initGrabber(camWidth, camHeight); vidGrabberLeft.setAnchorPercent(0.5,0.5); } else if (camera_type == STEREO) { vidGrabberRight.setVerbose(true); vidGrabberRight.setDeviceID(settings->getValue("settings:camera_id", 2)); vidGrabberRight.setDesiredFrameRate(75); vidGrabberRight.initGrabber(camWidth, camHeight); vidGrabberRight.setAnchorPercent(0.5, 0.5); } else if (camera_type == OVRVISION) { g_pOvrvision = new OVR::Ovrvision(); g_pOvrvision->Open(0, OVR::OV_CAMVGA_FULL); left.allocate(camWidth, camHeight,GL_RGB); left.setAnchorPercent(0.5, 0.5); right.allocate(camWidth, camHeight, GL_RGB); right.setAnchorPercent(0.5,0.5); } pitch = 0; yaw = 0; roll = 0; rx_pitch = 0; rx_yaw = 0; rx_roll = 0; fboLeft.setAnchorPercent(0.5, 0.5); fboRight.setAnchorPercent(0.5, 0.5); zoom = settings->getValue("settings:zoom", 0.85); speed = settings->getValue("settings:speed", 920); alignment = settings->getValue("settings:alignment", 0); ipd = settings->getValue("settings:ipd", 8); orientation = settings->getValue("settings:camera_orientation", 0); servo_roll = settings->getValue( "settings:servo_roll", 0); //start with screen off dimmed = true; dimValue = 255; //set debug to false by default deb = true; videoPlayer.loadVideos(se); }
void OculusDevice::resetSensorOrientation() const { ovrHmd_RecenterPose(m_hmdDevice); }
void HeadMountedDisplay::recenterPose() { KVS_OVR_CALL( ovrHmd_RecenterPose( m_handler ) ); }
OculusManager& OculusManager::getOculusManager() { static OculusManager* oculusManager = NULL; if (oculusManager == NULL) { oculusManager = new OculusManager(); if (!ovr_Initialize()) { fprintf(stderr, "Failed to initialize the Oculus SDK"); } //= *OculusManager::getHmd(); g_Hmd = ovrHmd_Create(0); if (!g_Hmd) { printf("No Oculus Rift device attached, using virtual version...\n"); g_Hmd = ovrHmd_CreateDebug(ovrHmd_DK2); } printf("initialized HMD: %s - %s\n", g_Hmd->Manufacturer, g_Hmd->ProductName); if (!glfwInit()) exit(EXIT_FAILURE); if (l_MultiSampling) glfwWindowHint(GLFW_SAMPLES, 4); else glfwWindowHint(GLFW_SAMPLES, 0); bool l_DirectMode = ((g_Hmd->HmdCaps & ovrHmdCap_ExtendDesktop) == 0); GLFWmonitor* l_Monitor; ovrSizei l_ClientSize; if (l_DirectMode) { printf("Running in \"Direct\" mode...\n"); l_Monitor = NULL; l_ClientSize.w = g_Hmd->Resolution.w / 2; // Something reasonable, smaller, but maintain aspect ratio... l_ClientSize.h = g_Hmd->Resolution.h / 2; // Something reasonable, smaller, but maintain aspect ratio... } else // Extended Desktop mode... { printf("Running in \"Extended Desktop\" mode...\n"); int l_Count; GLFWmonitor** l_Monitors = glfwGetMonitors(&l_Count); switch (l_Count) { case 0: printf("No monitors found, exiting...\n"); exit(EXIT_FAILURE); break; case 1: printf("Two monitors expected, found only one, using primary...\n"); l_Monitor = glfwGetPrimaryMonitor(); break; case 2: printf("Two monitors found, using second monitor...\n"); l_Monitor = l_Monitors[1]; break; default: printf("More than two monitors found, using second monitor...\n"); l_Monitor = l_Monitors[1]; } l_ClientSize.w = g_Hmd->Resolution.w; // 1920 for DK2... l_ClientSize.h = g_Hmd->Resolution.h; // 1080 for DK2... } l_Window = glfwCreateWindow(l_ClientSize.w, l_ClientSize.h, "GLFW Oculus Rift Test", l_Monitor, NULL); if (!l_Window) { glfwTerminate(); exit(EXIT_FAILURE); } #if defined(_WIN32) if (l_DirectMode) { ovrBool l_AttachResult = ovrHmd_AttachToWindow(g_Hmd, glfwGetWin32Window(l_Window), NULL, NULL); if (!l_AttachResult) { printf("Could not attach to window..."); exit(EXIT_FAILURE); } } #endif glfwMakeContextCurrent(l_Window); glewExperimental = GL_TRUE; GLenum l_GlewResult = glewInit(); if (l_GlewResult != GLEW_OK) { printf("glewInit() error.\n"); exit(EXIT_FAILURE); } int l_Major = glfwGetWindowAttrib(l_Window, GLFW_CONTEXT_VERSION_MAJOR); int l_Minor = glfwGetWindowAttrib(l_Window, GLFW_CONTEXT_VERSION_MINOR); int l_Profile = glfwGetWindowAttrib(l_Window, GLFW_OPENGL_PROFILE); printf("OpenGL: %d.%d ", l_Major, l_Minor); if (l_Major >= 3) // Profiles introduced in OpenGL 3.0... { if (l_Profile == GLFW_OPENGL_COMPAT_PROFILE) printf("GLFW_OPENGL_COMPAT_PROFILE\n"); else printf("GLFW_OPENGL_CORE_PROFILE\n"); } printf("Vendor: %s\n", (char*)glGetString(GL_VENDOR)); printf("Renderer: %s\n", (char*)glGetString(GL_RENDERER)); ovrSizei l_EyeTextureSizes[2]; l_EyeTextureSizes[ovrEye_Left] = ovrHmd_GetFovTextureSize(g_Hmd, ovrEye_Left, g_Hmd->MaxEyeFov[ovrEye_Left], 1.0f); l_EyeTextureSizes[ovrEye_Right] = ovrHmd_GetFovTextureSize(g_Hmd, ovrEye_Right, g_Hmd->MaxEyeFov[ovrEye_Right], 1.0f); // Combine for one texture for both eyes... g_RenderTargetSize.w = l_EyeTextureSizes[ovrEye_Left].w + l_EyeTextureSizes[ovrEye_Right].w; g_RenderTargetSize.h = (l_EyeTextureSizes[ovrEye_Left].h > l_EyeTextureSizes[ovrEye_Right].h ? l_EyeTextureSizes[ovrEye_Left].h : l_EyeTextureSizes[ovrEye_Right].h); // Create the FBO being a single one for both eyes (this is open for debate)... glGenFramebuffers(1, &l_FBOId); glBindFramebuffer(GL_FRAMEBUFFER, l_FBOId); // The texture we're going to render to... glGenTextures(1, &l_TextureId); // "Bind" the newly created texture : all future texture functions will modify this texture... glBindTexture(GL_TEXTURE_2D, l_TextureId); // Give an empty image to OpenGL (the last "0") glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, g_RenderTargetSize.w, g_RenderTargetSize.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); // Linear filtering... glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Create Depth Buffer... glGenRenderbuffers(1, &l_DepthBufferId); glBindRenderbuffer(GL_RENDERBUFFER, l_DepthBufferId); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, g_RenderTargetSize.w, g_RenderTargetSize.h); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, l_DepthBufferId); // Set the texture as our colour attachment #0... glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, l_TextureId, 0); // Set the list of draw buffers... GLenum l_GLDrawBuffers[1] = { GL_COLOR_ATTACHMENT0 }; glDrawBuffers(1, l_GLDrawBuffers); // "1" is the size of DrawBuffers // Check if everything is OK... GLenum l_Check = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); if (l_Check != GL_FRAMEBUFFER_COMPLETE) { printf("There is a problem with the FBO.\n"); exit(EXIT_FAILURE); } // Unbind... glBindRenderbuffer(GL_RENDERBUFFER, 0); glBindTexture(GL_TEXTURE_2D, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); // Setup textures for each eye... // Left eye... g_EyeTextures[ovrEye_Left].Header.API = ovrRenderAPI_OpenGL; g_EyeTextures[ovrEye_Left].Header.TextureSize = g_RenderTargetSize; g_EyeTextures[ovrEye_Left].Header.RenderViewport.Pos.x = 0; g_EyeTextures[ovrEye_Left].Header.RenderViewport.Pos.y = 0; g_EyeTextures[ovrEye_Left].Header.RenderViewport.Size = l_EyeTextureSizes[ovrEye_Left]; ((ovrGLTexture&)(g_EyeTextures[ovrEye_Left])).OGL.TexId = l_TextureId; // Right eye (mostly the same as left but with the viewport on the right side of the texture)... g_EyeTextures[ovrEye_Right] = g_EyeTextures[ovrEye_Left]; g_EyeTextures[ovrEye_Right].Header.RenderViewport.Pos.x = (g_RenderTargetSize.w + 1) / 2; g_EyeTextures[ovrEye_Right].Header.RenderViewport.Pos.y = 0; // Oculus Rift eye configurations... g_Cfg.OGL.Header.API = ovrRenderAPI_OpenGL; g_Cfg.OGL.Header.RTSize.w = l_ClientSize.w; g_Cfg.OGL.Header.RTSize.h = l_ClientSize.h; g_Cfg.OGL.Header.Multisample = (l_MultiSampling ? 1 : 0); #if defined(_WIN32) g_Cfg.OGL.Window = glfwGetWin32Window(l_Window); g_Cfg.OGL.DC = GetDC(g_Cfg.OGL.Window); #elif defined(__linux__) l_Cfg.OGL.Win = glfwGetX11Window(l_Window); l_Cfg.OGL.Disp = glfwGetX11Display(); #endif // Enable capabilities... // ovrHmd_SetEnabledCaps(g_Hmd, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction); ovrBool l_ConfigureResult = ovrHmd_ConfigureRendering(g_Hmd, &g_Cfg.Config, g_DistortionCaps, g_Hmd->MaxEyeFov, g_EyeRenderDesc); glUseProgram(0); // Avoid OpenGL state leak in ovrHmd_ConfigureRendering... if (!l_ConfigureResult) { printf("Configure failed.\n"); exit(EXIT_FAILURE); } // Start the sensor which provides the Rift’s pose and motion... uint32_t l_SupportedSensorCaps = ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position; uint32_t l_RequiredTrackingCaps = 0; ovrBool l_TrackingResult = ovrHmd_ConfigureTracking(g_Hmd, l_SupportedSensorCaps, l_RequiredTrackingCaps); if (!l_TrackingResult) { printf("Could not start tracking..."); exit(EXIT_FAILURE); } // Projection matrici for each eye will not change at runtime, we can set them here... g_ProjectionMatrici[ovrEye_Left] = ovrMatrix4f_Projection(g_EyeRenderDesc[ovrEye_Left].Fov, 0.3f, 100.0f, true); g_ProjectionMatrici[ovrEye_Right] = ovrMatrix4f_Projection(g_EyeRenderDesc[ovrEye_Right].Fov, 0.3f, 100.0f, true); // IPD offset values will not change at runtime, we can set them here... g_EyeOffsets[ovrEye_Left] = g_EyeRenderDesc[ovrEye_Left].HmdToEyeViewOffset; g_EyeOffsets[ovrEye_Right] = g_EyeRenderDesc[ovrEye_Right].HmdToEyeViewOffset; ovrHmd_RecenterPose(g_Hmd); return *oculusManager; } }
void machine::calibrate() { ovrHmd_RecenterPose(hmd); drift_correction=0; }
void OVRResetTracking() { ovrHmd_RecenterPose( _OVRGlobals.HMD ); }
virtual void resetPosition() { static const glm::vec3 EYE = glm::vec3(0, eyeHeight, ipd * 5.0f); static const glm::vec3 LOOKAT = glm::vec3(0, eyeHeight, 0); player = glm::inverse(glm::lookAt(EYE, LOOKAT, Vectors::UP)); ovrHmd_RecenterPose(hmd); }
void OVRSDK06AppSkeleton::RecenterPose() { if (m_Hmd == NULL) return; ovrHmd_RecenterPose(m_Hmd); }
void RiftAppSkeleton::RecenterPose() { if (m_Hmd == NULL) return; ovrHmd_RecenterPose(m_Hmd); }