From 9ba99cbfcf793539f47f34fd637a48f97a249920 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Thu, 15 May 2014 12:51:13 +0200 Subject: OGLWindow: move camera only when one of the key candidates is pressed Change-Id: I52b3d100512cad569a53d10c9dc819e4548ba928 --- avmedia/source/opengl/oglwindow.cxx | 69 ++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 32 deletions(-) (limited to 'avmedia') diff --git a/avmedia/source/opengl/oglwindow.cxx b/avmedia/source/opengl/oglwindow.cxx index 8f9eefa4eaec..f7987188d30a 100644 --- a/avmedia/source/opengl/oglwindow.cxx +++ b/avmedia/source/opengl/oglwindow.cxx @@ -246,40 +246,45 @@ IMPL_LINK(OGLWindow, CameraHandler, VclWindowEvent*, pEvent) if(pKeyEvt) { const sal_uInt16 nCode = pKeyEvt->GetKeyCode().GetCode(); - m_pContext->makeCurrent(); - - // Calculate movement - glm::vec3 vMoveBy; + if (nCode == KEY_Q || nCode == KEY_E || + nCode == KEY_A || nCode == KEY_D || + nCode == KEY_W || nCode == KEY_S ) { - glm::vec3 vEye; - glm::vec3 vView; - glm::vec3 vUp; - gltf_get_camera_pos(&vEye,&vView,&vUp); - float fModelSize =(float)gltf_get_model_size(); - - glm::vec3 vMove = vView-vEye; - vMove = glm::normalize(vMove); - vMove *= 25.0f; - glm::vec3 vStrafe = glm::cross(vView-vEye, vUp); - vStrafe = glm::normalize(vStrafe); - vStrafe *= 25.0f; - glm::vec3 vMup = glm::cross(vView-vEye,glm::vec3(1.f,0.f,0.f) ); - vMup = glm::normalize(vMup); - vMup *= 25.0f; - - if(nCode == KEY_Q)vMoveBy += vMove*(0.1f*fModelSize); - if(nCode == KEY_E)vMoveBy -= vMove*(0.1f*fModelSize); - if(nCode == KEY_A)vMoveBy -= vStrafe*(0.1f*fModelSize); - if(nCode == KEY_D)vMoveBy += vStrafe*(0.1f*fModelSize); - if(nCode == KEY_W)vMoveBy -= vMup*(0.1f*fModelSize); - if(nCode == KEY_S)vMoveBy += vMup*(0.1f*fModelSize); - } + m_pContext->makeCurrent(); + + // Calculate movement + glm::vec3 vMoveBy; + { + glm::vec3 vEye; + glm::vec3 vView; + glm::vec3 vUp; + gltf_get_camera_pos(&vEye,&vView,&vUp); + float fModelSize =(float)gltf_get_model_size(); + + glm::vec3 vMove = vView-vEye; + vMove = glm::normalize(vMove); + vMove *= 25.0f; + glm::vec3 vStrafe = glm::cross(vView-vEye, vUp); + vStrafe = glm::normalize(vStrafe); + vStrafe *= 25.0f; + glm::vec3 vMup = glm::cross(vView-vEye,glm::vec3(1.f,0.f,0.f) ); + vMup = glm::normalize(vMup); + vMup *= 25.0f; + + if(nCode == KEY_Q)vMoveBy += vMove*(0.1f*fModelSize); + if(nCode == KEY_E)vMoveBy -= vMove*(0.1f*fModelSize); + if(nCode == KEY_A)vMoveBy -= vStrafe*(0.1f*fModelSize); + if(nCode == KEY_D)vMoveBy += vStrafe*(0.1f*fModelSize); + if(nCode == KEY_W)vMoveBy -= vMup*(0.1f*fModelSize); + if(nCode == KEY_S)vMoveBy += vMup*(0.1f*fModelSize); + } - gltf_renderer_move_camera(vMoveBy.x,vMoveBy.y,vMoveBy.z,10.0); - gltf_prepare_renderer(m_pHandle); - gltf_renderer(m_pHandle); - gltf_complete_renderer(); - m_pContext->swapBuffers(); + gltf_renderer_move_camera(vMoveBy.x,vMoveBy.y,vMoveBy.z,10.0); + gltf_prepare_renderer(m_pHandle); + gltf_renderer(m_pHandle); + gltf_complete_renderer(); + m_pContext->swapBuffers(); + } } } return 0; -- cgit