void keyboard(GLFWwindow* pWindow, int key, int codes, int action, int mods) { (void)pWindow; (void)codes; if ((key > -1) && (key <= GLFW_KEY_LAST)) { m_keyStates[key] = action; //printf("key ac %d %d\n", key, action); } const float f = 0.9f; const float ff = 0.99f; ShaderToyGlobalState& gs = g_app.m_galleryScene.m_globalShadertoyState; switch (key) { default: break; case GLFW_KEY_BACKSLASH: { if (action==GLFW_PRESS ) g_app.m_dashScene.SendMouseClick(1); else if (action==GLFW_RELEASE) g_app.m_dashScene.SendMouseClick(0); } break; case GLFW_KEY_SLASH: { if (action==GLFW_PRESS ) g_app.m_dashScene.SetHoldingFlag(1); else if (action==GLFW_RELEASE) g_app.m_dashScene.SetHoldingFlag(0); } break; } if (action == GLFW_PRESS) { g_app.DismissHealthAndSafetyWarning(); switch (key) { default: break; case GLFW_KEY_F1: if (mods & GLFW_MOD_CONTROL) { g_renderMode.toggleRenderingTypeReverse(); } else { g_renderMode.toggleRenderingType(); } LOG_INFO("Render Type: %d", g_renderMode.outputType); break; case GLFW_KEY_F2: g_renderMode.toggleRenderingTypeMono(); LOG_INFO("Render Type: %d", g_renderMode.outputType); break; case GLFW_KEY_F3: g_renderMode.toggleRenderingTypeHMD(); LOG_INFO("Render Type: %d", g_renderMode.outputType); break; case GLFW_KEY_F4: g_renderMode.toggleRenderingTypeDistortion(); LOG_INFO("Render Type: %d", g_renderMode.outputType); break; case GLFW_KEY_F5: g_dynamicallyScaleFBO = false; g_app.SetFBOScale(f * g_app.GetFBOScale()); break; case GLFW_KEY_F6: g_dynamicallyScaleFBO = false; g_app.SetFBOScale(ff * g_app.GetFBOScale()); break; case GLFW_KEY_F7: g_dynamicallyScaleFBO = false; g_app.SetFBOScale((1.f/ff) * g_app.GetFBOScale()); break; case GLFW_KEY_F8: g_dynamicallyScaleFBO = false; g_app.SetFBOScale((1.f/f) * g_app.GetFBOScale()); break; case GLFW_KEY_F9: SetVsync(0); break; case GLFW_KEY_F10: SetVsync(1); break; case GLFW_KEY_F11: SetVsync(-1); break; case GLFW_KEY_DELETE: g_dynamicallyScaleFBO = !g_dynamicallyScaleFBO; break; case GLFW_KEY_SEMICOLON: gs.animatedThumbnails = !gs.animatedThumbnails; break; case GLFW_KEY_APOSTROPHE: gs.panesAsPortals = !gs.panesAsPortals; break; case '`': ///@todo Is there a way to create an auxiliary window in Direct to rift mode? /// The call to glfwCreateWindow crashes the app in Win7. #ifdef USE_OCULUSSDK if (g_app.UsingDirectMode() == false) #endif { if (g_AuxWindow == NULL) { g_AuxWindow = initializeAuxiliaryWindow(g_pHMDWindow); #ifdef USE_ANTTWEAKBAR ///@note This will break PaneScene's tweakbar positioning TwWindowSize(g_auxWindow_w, g_auxWindow_h); #endif } else { destroyAuxiliaryWindow(g_AuxWindow); glfwMakeContextCurrent(g_pHMDWindow); } } break; case GLFW_KEY_TAB: if (g_app.UsingDebugHmd() == false) { g_app.m_dashScene.m_bDraw = !g_app.m_dashScene.m_bDraw; if (g_app.m_dashScene.m_bDraw) { g_app.m_dashScene.ResizeTweakbar(); } } break; case GLFW_KEY_SPACE: g_app.RecenterPose(); FindPreferredJoystick(); break; case 'J': FindPreferredJoystick(); break; case 'R': g_app.ResetChassisTransformations(); break; case GLFW_KEY_PAGE_DOWN: g_app.m_cinemaScopeFactor += 0.1f; g_app.m_cinemaScopeFactor = std::min(0.95f, g_app.m_cinemaScopeFactor); break; case GLFW_KEY_PAGE_UP: g_app.m_cinemaScopeFactor -= 0.1f; g_app.m_cinemaScopeFactor = std::max(0.f, g_app.m_cinemaScopeFactor); break; case GLFW_KEY_ENTER: g_app.ToggleShaderWorld(); break; case GLFW_KEY_PRINT_SCREEN: g_app.SaveShaderSettings(); break; case GLFW_KEY_ESCAPE: if (g_AuxWindow == NULL) { // Clear the frame before calling all the destructors - even a few // frames worth of frozen video is enough to cause discomfort! ///@note This does not seem to work in Direct mode. glClearColor(58.f/255.f, 110.f/255.f, 165.f/255.f, 1.f); // Win7 default desktop color glClear(GL_COLOR_BUFFER_BIT); glfwSwapBuffers(g_pHMDWindow); glClear(GL_COLOR_BUFFER_BIT); glfwSwapBuffers(g_pHMDWindow); g_app.exitVR(); glfwDestroyWindow(g_pHMDWindow); glfwTerminate(); exit(0); } else { destroyAuxiliaryWindow(g_AuxWindow); glfwMakeContextCurrent(g_pHMDWindow); } break; } } //g_app.keyboard(key, action, 0,0); const glm::vec3 forward(0.f, 0.f, -1.f); const glm::vec3 up(0.f, 1.f, 0.f); const glm::vec3 right(1.f, 0.f, 0.f); // Handle keyboard movement(WASD keys) glm::vec3 keyboardMove(0.0f, 0.0f, 0.0f); if (m_keyStates['W'] != GLFW_RELEASE) { keyboardMove += forward; } if (m_keyStates['S'] != GLFW_RELEASE) { keyboardMove -= forward; } if (m_keyStates['A'] != GLFW_RELEASE) { keyboardMove -= right; } if (m_keyStates['D'] != GLFW_RELEASE) { keyboardMove += right; } if (m_keyStates['Q'] != GLFW_RELEASE) { keyboardMove -= up; } if (m_keyStates['E'] != GLFW_RELEASE) { keyboardMove += up; } if (m_keyStates[GLFW_KEY_UP] != GLFW_RELEASE) { keyboardMove += forward; } if (m_keyStates[GLFW_KEY_DOWN] != GLFW_RELEASE) { keyboardMove -= forward; } if (m_keyStates[GLFW_KEY_LEFT] != GLFW_RELEASE) { keyboardMove -= right; } if (m_keyStates[GLFW_KEY_RIGHT] != GLFW_RELEASE) { keyboardMove += right; } float mag = 1.0f; if (m_keyStates[GLFW_KEY_LEFT_SHIFT] != GLFW_RELEASE) mag *= 0.1f; if (m_keyStates[GLFW_KEY_LEFT_CONTROL] != GLFW_RELEASE) mag *= 10.0f; if (m_keyStates[GLFW_KEY_RIGHT_SHIFT] != GLFW_RELEASE) mag *= 0.1f; if (m_keyStates[GLFW_KEY_RIGHT_CONTROL] != GLFW_RELEASE) mag *= 10.0f; // Yaw keys g_app.m_keyboardYaw = 0.0f; const float dyaw = 0.5f * mag; // radians at 60Hz timestep if (m_keyStates['1'] != GLFW_RELEASE) { g_app.m_keyboardYaw = -dyaw; } if (m_keyStates['3'] != GLFW_RELEASE) { g_app.m_keyboardYaw = dyaw; } // Pitch and roll controls - if yaw is VR poison, // this is torture and death! g_app.m_keyboardDeltaPitch = 0.0f; g_app.m_keyboardDeltaRoll = 0.0f; if (g_allowPitch) { if (m_keyStates['2'] != GLFW_RELEASE) { g_app.m_keyboardDeltaPitch = -dyaw; } if (m_keyStates['X'] != GLFW_RELEASE) { g_app.m_keyboardDeltaPitch = dyaw; } } if (g_allowRoll) { if (m_keyStates['Z'] != GLFW_RELEASE) { g_app.m_keyboardDeltaRoll = -dyaw; } if (m_keyStates['C'] != GLFW_RELEASE) { g_app.m_keyboardDeltaRoll = dyaw; } } g_app.m_keyboardMove = mag * keyboardMove; }
void keyboard(GLFWwindow* pWindow, int key, int codes, int action, int mods) { (void)pWindow; (void)codes; if ((key > -1) && (key <= GLFW_KEY_LAST)) { m_keyStates[key] = action; //printf("key ac %d %d\n", key, action); } const float f = 0.9f; const float ff = 0.99f; if (action == GLFW_PRESS) { switch (key) { default: g_app.DismissHealthAndSafetyWarning(); break; case GLFW_KEY_F1: if (mods & GLFW_MOD_CONTROL) { g_renderMode.toggleRenderingTypeReverse(); } else { g_renderMode.toggleRenderingType(); } LOG_INFO("Render Type: %d", g_renderMode.outputType); break; case GLFW_KEY_F2: g_renderMode.toggleRenderingTypeMono(); LOG_INFO("Render Type: %d", g_renderMode.outputType); break; case GLFW_KEY_F3: g_renderMode.toggleRenderingTypeHMD(); LOG_INFO("Render Type: %d", g_renderMode.outputType); break; case GLFW_KEY_F4: g_renderMode.toggleRenderingTypeDistortion(); LOG_INFO("Render Type: %d", g_renderMode.outputType); break; case GLFW_KEY_F5: g_dynamicallyScaleFBO = false; g_app.SetFBOScale(f * g_app.GetFBOScale()); break; case GLFW_KEY_F6: g_dynamicallyScaleFBO = false; g_app.SetFBOScale(ff * g_app.GetFBOScale()); break; case GLFW_KEY_F7: g_dynamicallyScaleFBO = false; g_app.SetFBOScale((1.f/ff) * g_app.GetFBOScale()); break; case GLFW_KEY_F8: g_dynamicallyScaleFBO = false; g_app.SetFBOScale((1.f/f) * g_app.GetFBOScale()); break; case GLFW_KEY_F9: SetVsync(0); break; case GLFW_KEY_F10: SetVsync(1); break; case GLFW_KEY_F11: SetVsync(-1); break; case GLFW_KEY_DELETE: g_dynamicallyScaleFBO = !g_dynamicallyScaleFBO; break; case '`': #if defined(OVRSDK05) ///@todo Is there a way to create an auxiliary window in Direct to rift mode? /// The call to glfwCreateWindow crashes the app in Win7. if ( (g_app.UsingDirectMode() == false) || (g_app.UsingDebugHmd() == true)) { if (g_AuxWindow == NULL) { LOG_INFO("Creating auxiliary window."); g_AuxWindow = initializeAuxiliaryWindow(g_pHMDWindow); } else { LOG_INFO("Destroying auxiliary window."); destroyAuxiliaryWindow(g_AuxWindow); glfwMakeContextCurrent(g_pHMDWindow); } } #endif break; case GLFW_KEY_SPACE: g_app.RecenterPose(); break; case 'R': g_app.ResetChassisTransformations(); break; #ifdef USE_OCULUSSDK case 'V': g_app.ToggleVignette(); break; case 'T': g_app.ToggleTimeWarp(); break; case 'O': g_app.ToggleOverdrive(); break; case 'L': g_app.ToggleLowPersistence(); break; case 'M': g_app.ToggleMirrorToWindow(); break; case 'P': g_app.ToggleDynamicPrediction(); break; #endif case GLFW_KEY_ESCAPE: { // Clear the frame before calling all the destructors - even a few // frames worth of frozen video is enough to cause discomfort! ///@note This does not seem to work in Direct mode. glClearColor(58.f/255.f, 110.f/255.f, 165.f/255.f, 1.f); // Win7 default desktop color glClear(GL_COLOR_BUFFER_BIT); glfwSwapBuffers(g_pHMDWindow); glClear(GL_COLOR_BUFFER_BIT); glfwSwapBuffers(g_pHMDWindow); g_app.exitVR(); glfwDestroyWindow(g_pHMDWindow); glfwTerminate(); exit(0); } break; } } //g_app.keyboard(key, action, 0,0); const glm::vec3 forward(0.f, 0.f, -1.f); const glm::vec3 up(0.f, 1.f, 0.f); const glm::vec3 right(1.f, 0.f, 0.f); // Handle keyboard movement(WASD keys) glm::vec3 keyboardMove(0.0f, 0.0f, 0.0f); if (m_keyStates['W'] != GLFW_RELEASE) { keyboardMove += forward; } if (m_keyStates['S'] != GLFW_RELEASE) { keyboardMove -= forward; } if (m_keyStates['A'] != GLFW_RELEASE) { keyboardMove -= right; } if (m_keyStates['D'] != GLFW_RELEASE) { keyboardMove += right; } if (m_keyStates['Q'] != GLFW_RELEASE) { keyboardMove -= up; } if (m_keyStates['E'] != GLFW_RELEASE) { keyboardMove += up; } if (m_keyStates[GLFW_KEY_UP] != GLFW_RELEASE) { keyboardMove += forward; } if (m_keyStates[GLFW_KEY_DOWN] != GLFW_RELEASE) { keyboardMove -= forward; } if (m_keyStates[GLFW_KEY_LEFT] != GLFW_RELEASE) { keyboardMove -= right; } if (m_keyStates[GLFW_KEY_RIGHT] != GLFW_RELEASE) { keyboardMove += right; } float mag = 1.0f; if (m_keyStates[GLFW_KEY_LEFT_SHIFT] != GLFW_RELEASE) mag *= 0.1f; if (m_keyStates[GLFW_KEY_LEFT_CONTROL] != GLFW_RELEASE) mag *= 10.0f; // Yaw keys g_app.m_keyboardYaw = 0.0f; const float dyaw = 0.5f * mag; // radians at 60Hz timestep if (m_keyStates['1'] != GLFW_RELEASE) { g_app.m_keyboardYaw = -dyaw; } if (m_keyStates['3'] != GLFW_RELEASE) { g_app.m_keyboardYaw = dyaw; } // Pitch and roll controls - if yaw is VR poison, this is torture and death! g_app.m_keyboardDeltaPitch = 0.0f; g_app.m_keyboardDeltaRoll = 0.0f; if (g_allowPitch) { if (m_keyStates['2'] != GLFW_RELEASE) { g_app.m_keyboardDeltaPitch = -dyaw; } if (m_keyStates['X'] != GLFW_RELEASE) { g_app.m_keyboardDeltaPitch = dyaw; } } if (g_allowRoll) { if (m_keyStates['Z'] != GLFW_RELEASE) { g_app.m_keyboardDeltaRoll = -dyaw; } if (m_keyStates['C'] != GLFW_RELEASE) { g_app.m_keyboardDeltaRoll = dyaw; } } g_app.m_keyboardMove = mag * keyboardMove; }