From bf703a7ef97008a19b7cd725acd98e3b86889283 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Tue, 13 May 2014 00:07:48 +0200 Subject: glTF rendering: first try to move camera position SystemChildWindow can't handle events by its own that's why it's parent is used as an event handler. Mouse pointer specify the active model. This patch made for editing, in case of slideshow we have one less window. Change-Id: If8ac57176b9a0abab518f8d8a06a2a41177a4881 --- avmedia/source/opengl/oglwindow.cxx | 87 ++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) (limited to 'avmedia/source/opengl/oglwindow.cxx') diff --git a/avmedia/source/opengl/oglwindow.cxx b/avmedia/source/opengl/oglwindow.cxx index 31688741e639..35b1ab4d4a4f 100644 --- a/avmedia/source/opengl/oglwindow.cxx +++ b/avmedia/source/opengl/oglwindow.cxx @@ -14,9 +14,10 @@ using namespace com::sun::star; namespace avmedia { namespace ogl { -OGLWindow::OGLWindow( glTFHandle* pHandle, OpenGLContext* pContext ) +OGLWindow::OGLWindow( glTFHandle* pHandle, OpenGLContext* pContext, SystemChildWindow* pChildWindow ) : m_pHandle( pHandle ) , m_pContext( pContext ) + , m_pEventHandler( pChildWindow->GetParent() ) , m_bVisible ( false ) , meZoomLevel( media::ZoomLevel_ORIGINAL ) { @@ -122,7 +123,17 @@ void SAL_CALL OGLWindow::setVisible( sal_Bool bSet ) throw (uno::RuntimeException, std::exception) { if( bSet && !m_bVisible ) + { update(); + m_pEventHandler->GetParent()->AddEventListener( LINK(this, OGLWindow, FocusGrabber)); + m_pEventHandler->AddEventListener( LINK(this, OGLWindow, CameraHandler)); + m_pEventHandler->GrabFocus(); + } + else if( !bSet ) + { + m_pEventHandler->GetParent()->RemoveEventListener( LINK(this, OGLWindow, FocusGrabber)); + m_pEventHandler->RemoveEventListener( LINK(this, OGLWindow, CameraHandler)); + } m_bVisible = bSet; } @@ -196,6 +207,80 @@ void SAL_CALL OGLWindow::removePaintListener( const uno::Reference< awt::XPaintL { } +IMPL_LINK(OGLWindow, FocusGrabber, VclWindowEvent*, pEvent) +{ + assert(m_pEventHandler); + if( pEvent->GetId() == VCLEVENT_WINDOW_MOUSEMOVE ) + { + MouseEvent* pMouseEvt = (MouseEvent*)pEvent->GetData(); + if(pMouseEvt) + { + const Point& rMousePos = pMouseEvt->GetPosPixel(); + const Rectangle aWinRect(m_pEventHandler->GetPosPixel(),m_pEventHandler->GetSizePixel()); + if( aWinRect.IsInside(rMousePos) ) + { + if ( !m_pEventHandler->HasFocus() ) + { + m_pEventHandler->GrabFocus(); + } + } + else if ( m_pEventHandler->HasFocus() ) + { + m_pEventHandler->GrabFocusToDocument(); + } + } + } + + return 0; +} + +IMPL_LINK(OGLWindow, CameraHandler, VclWindowEvent*, pEvent) +{ + if( pEvent->GetId() == VCLEVENT_WINDOW_KEYINPUT ) + { + KeyEvent* pKeyEvt = (KeyEvent*)pEvent->GetData(); + if(pKeyEvt) + { + sal_uInt16 nCode = pKeyEvt->GetKeyCode().GetCode(); + 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(); + } + } + return 0; +} + } // namespace ogl } // namespace avmedia -- cgit