Commit 610ab1b9 authored by cornimueller's avatar cornimueller
Browse files

[ADD] Projection mode (ortho/perspective) is selectable for the views....

[ADD] Projection mode (ortho/perspective) is selectable for the views. Currently the NavWidgets are ortho, the central widget is perspective.
parent 237eb386
......@@ -42,7 +42,7 @@
#include "exceptions/WGEInitFailed.h"
#include "WGEViewer.h"
WGEViewer::WGEViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height ):
WGEViewer::WGEViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height, WGECamera::ProjectionMode projectionMode ):
WGEGraphicsWindow( wdata, x, y, width, height )
{
try
......@@ -54,9 +54,22 @@ WGEViewer::WGEViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, i
m_View = osg::ref_ptr<osgViewer::Viewer>( new osgViewer::Viewer() );
m_View->getCamera()->setGraphicsContext( m_GraphicsContext );
// m_View->getCamera()->setProjectionMatrixAsPerspective(
// 30.0, static_cast< double >( width ) / static_cast< double >( height ), 1.0, 1000.0 );
m_View->getCamera()->setProjectionMatrixAsOrtho( -120.0 * width / height, 120.0 * width / height, -120.0, 120.0, -1000.0, +1000.0 );
switch( projectionMode )
{
case( WGECamera::ORTHOGRAPHIC ):
m_View->getCamera()->setProjectionMatrixAsOrtho(
-120.0 * width / height, 120.0 * width / height, -120.0, 120.0, -1000.0, +1000.0 );
break;
case( WGECamera::PERSPECTIVE ):
m_View->getCamera()->setProjectionMatrixAsPerspective(
30.0, static_cast< double >( width ) / static_cast< double >( height ), 1.0, 1000.0 );
break;
default:
throw WGEInitFailed( "Unknown projection mode" );
break;
}
m_View->getCamera()->setViewport( 0, 0, width, height );
m_View->getCamera()->setProjectionResizePolicy( osg::Camera::HORIZONTAL );
......
......@@ -42,6 +42,7 @@
#include "../common/WThreadedRunner.h"
#include "WGEGraphicsWindow.h"
#include "WGECamera.h"
/**
* Class for managing one viewer to the scene. This includes viewport, camera and graphics context.
......@@ -52,7 +53,6 @@ class WGEViewer: public WGEGraphicsWindow,
public WThreadedRunner
{
public:
/**
* Default constructor.
*
......@@ -61,9 +61,11 @@ public:
* \param y Y coordinate of widget where to create the context.
* \param width Width of the widget.
* \param height Height of the Widget.
* \param projectionMode Projection mode of the viewer.
* \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
*/
WGEViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height );
WGEViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height,
WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
/**
* Destructor.
......@@ -157,4 +159,3 @@ private:
};
#endif // WGEVIEWER_H
......@@ -71,9 +71,10 @@ void WGraphicsEngine::threadMain()
// }
}
boost::shared_ptr<WGEViewer> WGraphicsEngine::createViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height )
boost::shared_ptr<WGEViewer> WGraphicsEngine::createViewer(
osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height, WGECamera::ProjectionMode projectionMode )
{
boost::shared_ptr<WGEViewer> viewer = boost::shared_ptr<WGEViewer>( new WGEViewer( wdata, x, y, width, height ) );
boost::shared_ptr<WGEViewer> viewer = boost::shared_ptr<WGEViewer>( new WGEViewer( wdata, x, y, width, height, projectionMode ) );
viewer->setScene( this->getScene() );
// start rendering
......
......@@ -84,10 +84,12 @@ public:
* \param y Y coordinate of widget where to create the context.
* \param width Width of the widget.
* \param height Height of the Widget.
* \param projectionMode Projection mode of the viewer.
* \return the new instance, ready to be used.
* \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
*/
boost::shared_ptr<WGEViewer> createViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height );
boost::shared_ptr<WGEViewer> createViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height,
WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
protected:
......
......@@ -69,7 +69,7 @@ void WMainWindow::setupGUI( QMainWindow *mainWindow )
mainWindow->setCentralWidget( m_centralwidget );
std::cout << "init main gl" << std::endl;
boost::shared_ptr<WQtGLWidget> widget = boost::shared_ptr<WQtGLWidget>( new WQtGLWidget( mainWindow ) );
boost::shared_ptr<WQtGLWidget> widget = boost::shared_ptr<WQtGLWidget>( new WQtGLWidget( mainWindow, WGECamera::PERSPECTIVE ) );
m_glWidgets.push_back( widget );
mainWindow->setCentralWidget( widget.get() );
......
......@@ -32,7 +32,7 @@
#include "../../kernel/WKernel.h"
WQtGLWidget::WQtGLWidget( QWidget* parent )
WQtGLWidget::WQtGLWidget( QWidget* parent, WGECamera::ProjectionMode projectionMode )
: QWidget( parent ),
m_recommendedSize()
{
......@@ -55,7 +55,7 @@ WQtGLWidget::WQtGLWidget( QWidget* parent )
#endif
// create viewer
m_Viewer = WKernel::getRunningKernel()->getGraphicsEngine()->createViewer( wdata, x(), y(), width(), height() );
m_Viewer = WKernel::getRunningKernel()->getGraphicsEngine()->createViewer( wdata, x(), y(), width(), height(), projectionMode );
// required
setAttribute( Qt::WA_PaintOnScreen );
......
......@@ -50,7 +50,7 @@ public:
*
* \return
*/
explicit WQtGLWidget( QWidget* parent = 0 );
explicit WQtGLWidget( QWidget* parent = 0, WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
/**
* Destructor.
......
......@@ -45,7 +45,7 @@ WQtNavGLWidget::WQtNavGLWidget( QString title, int maxValue, std::string sliderT
QVBoxLayout* layout = new QVBoxLayout();
m_glWidget = boost::shared_ptr<WQtGLWidget>( new WQtGLWidget( panel ) );
m_glWidget = boost::shared_ptr<WQtGLWidget>( new WQtGLWidget( panel, WGECamera::ORTHOGRAPHIC ) );
layout->addWidget( m_glWidget.get() );
layout->addWidget( slider );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment