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
hg/feature/gsoc2013-dfighter
dfighter1985 12 years ago
parent 66fb3c1284
commit 42bf13dcfd

@ -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() );
}
}

@ -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;
};
}

@ -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();
}

@ -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 )

Loading…
Cancel
Save