root/OpenSceneGraph/trunk/examples/osgimpostor/TestManipulator.h
@
6941
| Revision 6941, 3.9 kB (checked in by robert, 6 years ago) | |
|---|---|
|
|
| Line | |
|---|---|
| 1 | /* -*-c++-*- |
| 2 | * |
| 3 | * OpenSceneGraph example, osgimpostor. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | * of this software and associated documentation files (the "Software"), to deal |
| 7 | * in the Software without restriction, including without limitation the rights |
| 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | * copies of the Software, and to permit persons to whom the Software is |
| 10 | * furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 18 | * THE SOFTWARE. |
| 19 | */ |
| 20 | |
| 21 | #ifndef OSGGA_TESTMANIPULATOR |
| 22 | #define OSGGA_TESTMANIPULATOR 1 |
| 23 | |
| 24 | #include <osgGA/MatrixManipulator> |
| 25 | #include <osg/Quat> |
| 26 | |
| 27 | class TestManipulator : public osgGA::MatrixManipulator |
| 28 | { |
| 29 | public: |
| 30 | |
| 31 | TestManipulator(); |
| 32 | virtual ~TestManipulator(); |
| 33 | |
| 34 | /** set the position of the matrix manipulator using a 4x4 Matrix.*/ |
| 35 | virtual void setByMatrix(const osg::Matrixd& matrix); |
| 36 | |
| 37 | /** set the position of the matrix manipulator using a 4x4 Matrix.*/ |
| 38 | virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); } |
| 39 | |
| 40 | /** get the position of the manipulator as 4x4 Matrix.*/ |
| 41 | virtual osg::Matrixd getMatrix() const; |
| 42 | |
| 43 | /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/ |
| 44 | virtual osg::Matrixd getInverseMatrix() const; |
| 45 | |
| 46 | /** Attach a node to the manipulator. |
| 47 | Automatically detaches previously attached node. |
| 48 | setNode(NULL) detaches previously nodes. |
| 49 | Is ignored by manipulators which do not require a reference model.*/ |
| 50 | virtual void setNode(osg::Node*); |
| 51 | |
| 52 | /** Return node if attached.*/ |
| 53 | virtual const osg::Node* getNode() const; |
| 54 | |
| 55 | /** Return node if attached.*/ |
| 56 | virtual osg::Node* getNode(); |
| 57 | |
| 58 | /** Move the camera to the default position. |
| 59 | May be ignored by manipulators if home functionality is not appropriate.*/ |
| 60 | virtual void home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us); |
| 61 | |
| 62 | /** Start/restart the manipulator.*/ |
| 63 | virtual void init(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us); |
| 64 | |
| 65 | |
| 66 | /** handle events, return true if handled, false otherwise.*/ |
| 67 | virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us); |
| 68 | |
| 69 | private: |
| 70 | |
| 71 | /** Reset the internal GUIEvent stack.*/ |
| 72 | void flushMouseEventStack(); |
| 73 | /** Add the current mouse GUIEvent to internal stack.*/ |
| 74 | void addMouseEvent(const osgGA::GUIEventAdapter& ea); |
| 75 | |
| 76 | void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up); |
| 77 | |
| 78 | /** For the give mouse movement calculate the movement of the camera. |
| 79 | Return true is camera has moved and a redraw is required.*/ |
| 80 | bool calcMovement(); |
| 81 | |
| 82 | /** Check the speed at which the mouse is moving. |
| 83 | If speed is below a threshold then return false, otherwise return true.*/ |
| 84 | bool isMouseMoving(); |
| 85 | |
| 86 | // Internal event stack comprising last three mouse events. |
| 87 | osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t1; |
| 88 | osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t0; |
| 89 | |
| 90 | osg::ref_ptr<osg::Node> _node; |
| 91 | |
| 92 | float _modelScale; |
| 93 | float _minimumZoomScale; |
| 94 | |
| 95 | bool _thrown; |
| 96 | |
| 97 | osg::Vec3 _center; |
| 98 | osg::Quat _rotation; |
| 99 | float _distance; |
| 100 | |
| 101 | }; |
| 102 | |
| 103 | #endif |
Note: See TracBrowser
for help on using the browser.
