From 42bf13dcfd9beb9dbb9aff366425b9b606941a1d Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 9 Jul 2013 06:32:02 +0200 Subject: [PATCH] Implemented shape moving/rotating/zooming. Used parts of Dnk's code from object viewer for setting the camera up properly. NOTE: for some reason the ViewPortWidget doesn't receive native mouse wheel events. An investigation is in order. --HG-- branch : gsoc2013-dfighter --- .../material_editor/nel3d_interface.cpp | 47 ++++++++++++++++++- .../plugins/material_editor/nel3d_interface.h | 6 ++- .../material_editor/viewport_widget.cpp | 13 ++++- .../plugins/material_editor/viewport_widget.h | 2 + 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp index 13a0e9b9a..aa421cd3a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp @@ -24,6 +24,7 @@ #include "nel/3d/scene_user.h" #include "nel/3d/u_camera.h" #include "nel/3d/u_instance.h" +#include "nel/3d/u_3d_mouse_listener.h" #include "nel/misc/i_xml.h" #include "nel/misc/o_xml.h" #include "nel/misc/file.h" @@ -204,6 +205,7 @@ namespace MaterialEditor shaderManager = new NL3D::CShaderManager(); driver = NULL; scene = NULL; + mouseListener = NULL; } CNel3DInterface::~CNel3DInterface() @@ -348,15 +350,18 @@ namespace MaterialEditor driver->setDisplay( (nlWindow)wnd, NL3D::UDriver::CMode( w, h, 32 ) ); scene = driver->createScene( true ); - + mouseListener = driver->create3dMouseListener(); + mouseListener->setMouseMode( NL3D::U3dMouseListener::nelStyle ); } void CNel3DInterface::killViewPort() { driver->deleteScene( scene ); + scene = NULL; + driver->delete3dMouseListener( mouseListener ); + mouseListener = NULL; delete driver; driver = NULL; - } void CNel3DInterface::resizeViewPort( unsigned long w, unsigned long h ) @@ -377,6 +382,8 @@ namespace MaterialEditor clearScene(); currentShape = instance; + setupCamera(); + return true; } @@ -397,14 +404,50 @@ namespace MaterialEditor driver->swapBuffers(); } + void CNel3DInterface::updateInput() + { + driver->EventServer.pump(); + } + void CNel3DInterface::renderScene() { if( scene != NULL ) { + scene->getCam().setTransformMode( NL3D::UTransformable::DirectMatrix ); + scene->getCam().setMatrix( mouseListener->getViewMatrix() ); + driver->clearBuffers(); scene->render(); driver->swapBuffers(); } } + + void CNel3DInterface::setupCamera() + { + NLMISC::CAABBox bbox; + currentShape.getShapeAABBox( bbox ); + + NLMISC::CVector center = bbox.getCenter(); + NLMISC::CQuat q( 0.0f, 0.0f, 0.0f, 0.0f ); + currentShape.getDefaultRotQuat( q ); + + NLMISC::CVector max_radius = bbox.getHalfSize(); + float radius = std::max( max_radius.x, std::max( max_radius.y, max_radius.z ) ); + float distance = radius / tan( 45.0f ); + + NLMISC::CVector axis = q.getAxis(); + if( axis.isNull() || ( axis == NLMISC::CVector::I ) ) + axis = NLMISC::CVector::J; + else + if( axis == -NLMISC::CVector::K ) + axis = -NLMISC::CVector::J; + + NLMISC::CVector eye = center - axis * ( radius + distance ); + scene->getCam().lookAt( eye, center ); + + mouseListener->setHotSpot( center ); + mouseListener->setMatrix( scene->getCam().getMatrix() ); + } + } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h index 2aaa7d689..ba94963cd 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h @@ -28,6 +28,7 @@ namespace NL3D class CShaderManager; class UDriver; class UScene; + class U3dMouseListener; } namespace MaterialEditor @@ -150,14 +151,17 @@ namespace MaterialEditor bool loadShape( const std::string &fileName ); void clearScene(); + void updateInput(); void renderScene(); private: + void setupCamera(); + NL3D::CDynMaterial *mat; NL3D::CShaderManager *shaderManager; NL3D::UDriver *driver; NL3D::UScene *scene; - + NL3D::U3dMouseListener *mouseListener; }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.cpp index 799e57e40..871141730 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.cpp @@ -33,7 +33,7 @@ namespace MaterialEditor { nl3dIface = NULL; timerId = 0; - setAttribute( Qt::WA_PaintOnScreen, true ); + setAttribute( Qt::WA_PaintOnScreen ); } ViewPortWidget::~ViewPortWidget() @@ -77,12 +77,22 @@ namespace MaterialEditor update(); } + void ViewPortWidget::wheelEvent( QWheelEvent *evnt ) + { + QWidget::wheelEvent( evnt ); + } + #if defined( NL_OS_WINDOWS ) typedef bool ( *winProc )( NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ); bool ViewPortWidget::winEvent( MSG *message, long *result ) { + if( message->message == WM_MOUSEWHEEL ) + { + printf( "" ); + } + NL3D::UDriver *udriver = nl3dIface->getDriver(); if( ( udriver != NULL ) && udriver->isActive() ) { @@ -145,6 +155,7 @@ namespace MaterialEditor void ViewPortWidget::update() { + nl3dIface->updateInput(); nl3dIface->renderScene(); } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.h index 081cad53a..d7af9ccfc 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.h @@ -46,6 +46,8 @@ namespace MaterialEditor void timerEvent( QTimerEvent *evnt ); + void wheelEvent( QWheelEvent *evnt ); + #if defined ( NL_OS_WINDOWS ) bool winEvent( MSG *message, long *result ); #elif defined( NL_OS_MAC )