25 #include "WGEAdvancedManipulator.h"
26 #include "WGraphicsEngine.h"
29 TrackballManipulator(),
31 m_allowThrow( false ),
34 setTrackballSize( .3 );
39 m_zoom = 1.0 / matrix.getScale()[0];
42 TrackballManipulator::setByMatrix( osg::Matrixd::inverse( osg::Matrixd::scale( 1.0 /
m_zoom, 1.0 /
m_zoom, 1.0 /
m_zoom ) ) * matrix );
47 return osg::Matrixd::scale( 1.0 /
m_zoom, 1.0 /
m_zoom, 1.0 /
m_zoom ) * TrackballManipulator::getMatrix();
52 return TrackballManipulator::getMatrix();
57 return TrackballManipulator::getInverseMatrix() * osg::Matrixd::scale(
m_zoom,
m_zoom,
m_zoom );
64 TrackballManipulator::getHomePosition( dummy, center, dummy );
66 m_zoom = 100.0 / center[0];
68 TrackballManipulator::home( 0 );
73 double zoomDelta = 0.0;
75 if( ea.getKey() && ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN )
77 if( ea.getKey() == osgGA::GUIEventAdapter::KEY_Minus )
81 if( ea.getKey() == osgGA::GUIEventAdapter::KEY_Plus )
85 if( zoomDelta != 0.0 )
98 switch( ea.getScrollingMotion() )
100 case osgGA::GUIEventAdapter::SCROLL_UP:
103 case osgGA::GUIEventAdapter::SCROLL_DOWN:
106 case osgGA::GUIEventAdapter::SCROLL_2D:
107 zoomDelta = 0.05 / 120.0 * ea.getScrollingDeltaY();
119 if( zoomDelta != 0.0 )
121 m_zoom *= 1.0 + zoomDelta;
125 us.requestContinuousUpdate(
false );
134 || ( ea.getKey() == osgGA::GUIEventAdapter::KEY_Space
135 && ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN )
144 else if( ea.getEventType() == osgGA::GUIEventAdapter::SCROLL
145 || ea.getKey() == osgGA::GUIEventAdapter::KEY_Minus
146 || ea.getKey() == osgGA::GUIEventAdapter::KEY_Plus )
148 return zoom( ea, us );
152 else if( ( ea.getEventType() == osgGA::GUIEventAdapter::DRAG ) || ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH ) )
154 if( ea.getButtonMask() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON )
158 else if( ( ea.getButtonMask() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ) && (
m_paintMode == 1 ) )
164 return TrackballManipulator::handle( ea, us );
169 return TrackballManipulator::handle( ea, us );
void setPaintMode(int mode)
setter for paint mode when set to something different from 0, a left drag should move the scene
bool getThrow() const
Checks whether throwing is active.
double m_zoom
Zoom factor.
int m_paintMode
paint mode
WGEAdvancedManipulator()
Default constructor.
void setThrow(bool allowThrow=true)
En-/Disables throwing.
bool zoom(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Handles events related to zooming.
bool m_allowThrow
Do we want the auto-rotation thingy?
virtual osg::Matrixd getMatrix() const
Get the position of the manipulator as 4x4 matrix.
virtual osg::Matrixd getInverseMatrix() const
Get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model...
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Handle events, return true if handled, false otherwise.
virtual osg::Matrixd getMatrixWithoutZoom() const
Get the manipulator only containing rotation and translation.
virtual void setByMatrix(const osg::Matrixd &matrix)
Set the position of the manipulator using a 4x4 matrix.
virtual void home(double currentTime)
Move the camera to the default position.
static std::shared_ptr< WGraphicsEngine > getGraphicsEngine()
Returns instance of the graphics engine.