Commit 30eed935 authored by cornimueller's avatar cornimueller
Browse files

[ADD] Added zooming using the mouse wheel by using a new manipulator derived...

[ADD] Added zooming using the mouse wheel by using a new manipulator derived from the TrackballManipulator
parent 4300d6a8
......@@ -169,6 +169,9 @@ void WGEGraphicsWindow::mouseEvent( MouseEvents eventType, int x, int y, int but
case MOUSEMOVE:
m_GraphicsWindow->getEventQueue()->mouseMotion( x, y );
break;
case MOUSESCROLL:
m_GraphicsWindow->getEventQueue()->mouseScroll2D( x, y );
break;
}
}
......@@ -86,7 +86,7 @@ public:
*/
enum MouseEvents
{
MOUSEPRESS, MOUSERELEASE, MOUSEDOUBLECLICK, MOUSEMOVE
MOUSEPRESS, MOUSERELEASE, MOUSEDOUBLECLICK, MOUSEMOVE, MOUSESCROLL
};
/**
......
......@@ -27,7 +27,6 @@
#include <osg/ShapeDrawable>
#include <osg/Geode>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/UFOManipulator>
......@@ -81,7 +80,7 @@ WGEViewer::WGEViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, i
m_View->addEventHandler( new osgViewer::StatsHandler );
// camera manipulator
m_View->setCameraManipulator( new osgGA::TrackballManipulator() );
m_View->setCameraManipulator( new WGEZoomTrackballManipulator() );
m_View->setLightingMode( osg::View::HEADLIGHT ); // this is the default anyway
......
......@@ -29,7 +29,6 @@
#include <osg/Node>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/TerrainManipulator>
......@@ -43,6 +42,7 @@
#include "WGEGraphicsWindow.h"
#include "WGECamera.h"
#include "WGEZoomTrackballManipulator.h"
/**
* Class for managing one viewer to the scene. This includes viewport, camera and graphics context.
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "WGEZoomTrackballManipulator.h"
WGEZoomTrackballManipulator::WGEZoomTrackballManipulator():
TrackballManipulator()
{
m_zoom = 1.0;
}
void WGEZoomTrackballManipulator::setByMatrix( const osg::Matrixd& matrix )
{
m_zoom = 1.0 / matrix.getScale()[0];
TrackballManipulator::setByMatrix( matrix );
}
osg::Matrixd WGEZoomTrackballManipulator::getMatrix() const
{
return osg::Matrixd::scale( 1.0 / m_zoom, 1.0 / m_zoom, 1.0 ) * TrackballManipulator::getMatrix();
}
osg::Matrixd WGEZoomTrackballManipulator::getInverseMatrix() const
{
return TrackballManipulator::getInverseMatrix() * osg::Matrixd::scale( m_zoom, m_zoom, 1.0 );
}
void WGEZoomTrackballManipulator::home( double currentTime )
{
m_zoom = 1.0;
TrackballManipulator::home( currentTime );
}
bool WGEZoomTrackballManipulator::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us )
{
if( ea.getEventType() == osgGA::GUIEventAdapter::SCROLL )
{
double zoomDelta;
switch( ea.getScrollingMotion() )
{
case osgGA::GUIEventAdapter::SCROLL_UP:
zoomDelta = -0.05;
break;
case osgGA::GUIEventAdapter::SCROLL_DOWN:
zoomDelta = 0.05;
break;
case osgGA::GUIEventAdapter::SCROLL_2D:
zoomDelta = -0.05 / 120.0 * ea.getScrollingDeltaY();
break;
// case osgGA::GUIEventAdapter::SCROLL_LEFT:
// case osgGA::GUIEventAdapter::SCROLL_RIGHT:
// case osgGA::GUIEventAdapter::SCROLL_NONE:
default:
// do nothing
zoomDelta = 0.0;
break;
}
if (zoomDelta != 0.0)
{
m_zoom *= 1.0 + zoomDelta;
us.requestRedraw();
}
us.requestContinuousUpdate( false );
_thrown = false;
return true;
}
else
{
return TrackballManipulator::handle( ea, us );
}
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WGEZOOMTRACKBALLMANIPULATOR_H
#define WGEZOOMTRACKBALLMANIPULATOR_H
#include <osgGA/TrackballManipulator>
/**
* New OSG manipulator: TrackballManipulator with added mouse wheel zoom.
*/
class WGEZoomTrackballManipulator: public osgGA::TrackballManipulator
{
public:
/**
* Default constructor
*/
WGEZoomTrackballManipulator();
/**
* Set the position of the matrix manipulator using a 4x4 matrix.
*/
virtual void setByMatrix( const osg::Matrixd& matrix );
/**
* Get the position of the manipulator as 4x4 matrix.
*/
virtual osg::Matrixd getMatrix() const;
/**
* Get the position of the manipulator as a inverse matrix of the
* manipulator, typically used as a model view matrix.
*/
virtual osg::Matrixd getInverseMatrix() const;
/**
* Move the camera to the default position.
* May be ignored by manipulators if home functionality is not appropriate.
*/
virtual void home( double currentTime );
/**
* Handle events, return true if handled, false otherwise.
*/
virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
/**
* Get zoom faktor.
*/
double getZoom() const
{
return m_zoom;
}
/**
* Set zoom faktor.
*/
void setZoom( double zoom )
{
m_zoom = zoom;
}
protected:
private:
/**
* Zoom faktor
*/
double m_zoom;
};
#endif // WGEZOOMTRACKBALLMANIPULATOR_H
......@@ -122,7 +122,7 @@ void WQtGLWidget::setCameraManipulator( WQtGLWidget::CameraManipulators manipula
default:
std::cout << "selected trackball manipulator" << std::endl;
m_Viewer->setCameraManipulator( new( osgGA::TrackballManipulator ) );
m_Viewer->setCameraManipulator( new( WGEZoomTrackballManipulator ) );
break;
}
}
......@@ -225,5 +225,21 @@ void WQtGLWidget::mouseMoveEvent( QMouseEvent* event )
{
m_Viewer->mouseEvent( WGEViewer::MOUSEMOVE, event->x(), event->y(), 0 );
}
void WQtGLWidget::wheelEvent( QWheelEvent* event )
{
int x, y;
if( event->orientation() == Qt::Vertical )
{
x = 0;
y = event->delta();
}
else
{
x = event->delta();
y = 0;
}
m_Viewer->mouseEvent( WGEViewer::MOUSESCROLL, x, y, 0 );
}
#endif
......@@ -168,6 +168,13 @@ protected:
* \param event the event description.
*/
virtual void mouseMoveEvent( QMouseEvent* event );
/**
* Event handler for the mouse wheel.
*
* \param event the event description.
*/
virtual void wheelEvent( QWheelEvent* event );
#endif
/**
......
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