WGEZoomTrackballManipulator.h 5.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
//---------------------------------------------------------------------------
//
// 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>
29

Robin Eschbach's avatar
Robin Eschbach committed
30 31
#include "WGEZoomTrackballNodeVisitor.h"

32 33 34 35

/**
 * New OSG manipulator: TrackballManipulator with added mouse wheel zoom.
 */
36
class WGEZoomTrackballManipulator: public osgGA::TrackballManipulator
37 38 39 40 41 42 43 44
{
public:
    /**
     * Default constructor
     */
    WGEZoomTrackballManipulator();

    /**
Alexander Wiebel's avatar
Alexander Wiebel committed
45 46
     * Set the position of the manipulator using a 4x4 matrix.
     * \param matrix position of the manipulator
47 48 49 50 51
     */
    virtual void setByMatrix( const osg::Matrixd& matrix );

    /**
     * Get the position of the manipulator as 4x4 matrix.
52 53
     *
     * \return the matrix representing the transformation
54 55 56
     */
    virtual osg::Matrixd getMatrix() const;

57 58 59 60 61 62 63
    /**
     * Get the manipulator only containing rotation and translation.
     *
     * \return the matrix with translation and rotation.
     */
    virtual osg::Matrixd getMatrixWithoutZoom() const;

64 65 66
    /**
     * Get the position of the manipulator as a inverse matrix of the
     * manipulator, typically used as a model view matrix.
67 68
     *
     * \return the inverse matrix
69 70 71 72 73 74
     */
    virtual osg::Matrixd getInverseMatrix() const;

    /**
     * Move the camera to the default position.
     * May be ignored by manipulators if home functionality is not appropriate.
Alexander Wiebel's avatar
Alexander Wiebel committed
75
     * \param currentTime Variable specified in osg class but not used.
76 77 78 79 80
     */
    virtual void home( double currentTime );

    /**
     * Handle events, return true if handled, false otherwise.
Alexander Wiebel's avatar
Alexander Wiebel committed
81 82
     * \param ea Event class for storing Keyboard, mouse and window events.
     * \param us Interface by which GUIEventHandlers may request actions of the GUI system
83 84
     *
     * \return true if event was handled
85 86 87 88
     */
    virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );

    /**
89
     * Get zoom factor.
90 91
     *
     * \return the current zoom factor
92
     */
93
    double getZoom() const;
94 95

    /**
96
     * Set zoom factor.
Alexander Wiebel's avatar
Alexander Wiebel committed
97
     * \param zoom the zoom factor to be set.
98
     */
99
    void setZoom( double zoom );
100

101 102 103 104 105 106 107 108
    /**
     * setter for paint mode
     * when set to something different from 0, a left drag should move the scene
     *
     * \param mode the mode
     */
    void setPaintMode( int mode );

109 110 111 112 113 114 115 116 117 118 119 120 121 122
    /**
     * En-/Disables throwing.
     *
     * \param allowThrow if true, throwing is enabled.
     */
    void setThrow( bool allowThrow = true );

    /**
     * Checks whether throwing is active.
     *
     * \return true if active
     */
    bool getThrow() const;

Robin Eschbach's avatar
Robin Eschbach committed
123 124 125 126 127 128 129 130 131 132 133 134 135
    /**
     * Computes the home position.
     * \param camera The camera from which to compute.
     * \param useBoundingBox if boundingboxes should be used.
     */
    virtual void computeHomePosition( const osg::Camera* camera, bool useBoundingBox );

    /**
     * Zooms and centers to fit screen.
     * \param camera The camera to zoom.
     */
    void fitToScreen( const osg::Camera* camera );

136 137 138
protected:
private:
    /**
Alexander Wiebel's avatar
Alexander Wiebel committed
139
     * Handles events related to zooming.
Alexander Wiebel's avatar
Alexander Wiebel committed
140 141
     * \param ea Event class for storing Keyboard, mouse and window events.
     * \param us Interface by which GUIEventHandlers may request actions of the GUI system
142 143
     *
     * \return true if event was handled
144
     */
Alexander Wiebel's avatar
Alexander Wiebel committed
145 146
    bool zoom( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );

147 148 149 150 151 152 153 154 155 156
    /**
     * Performs the middle mouse button click.
     * \param eventTimeDelta The delta time of the event
     * \param dx The delta x of the mouse.
     * \param dy The delta y of the mouse.
     * \return true It was performed.
     * \return false It was not performed.
     */
    virtual bool performMovementMiddleMouseButton( const double eventTimeDelta, const double dx, const double dy );

Alexander Wiebel's avatar
Alexander Wiebel committed
157
    double m_zoom; //!< Zoom factor.
158
    bool m_allowThrow; //!< Do we want the auto-rotation thingy?
159 160

    int m_paintMode; //!<paint mode
Robin Eschbach's avatar
Robin Eschbach committed
161 162

    double m_radius; //!< The radius of the bounding sphere
163 164
};

165 166 167 168 169 170 171 172 173 174
inline double WGEZoomTrackballManipulator::getZoom() const
{
    return m_zoom;
}

inline void WGEZoomTrackballManipulator::setZoom( double zoom )
{
    m_zoom = zoom;
}

175
#endif  // WGEZOOMTRACKBALLMANIPULATOR_H