source: osgVisual/include/manip_Spacemouse/manip_freeSpaceMouse.h @ 40

Last change on this file since 40 was 32, checked in by Torben Dannhauer, 15 years ago

Adding first version of osgVisual!!

File size: 4.7 KB
Line 
1#pragma once
2/* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer
3 *
4 * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under
5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 * (at your option) any later version.  The full license is in LICENSE file
7 * included with this distribution, and on the openscenegraph.org website.
8 *
9 * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
10 * You have to aquire licenses for all used proprietary modules.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * OpenSceneGraph Public License for more details.
16*/
17
18// Spacemouse implementation
19#include <manip_spaceMouse.h>
20
21// OSG includes
22#include <osgGA/MatrixManipulator>
23#include <osgGA/GUIEventAdapter>
24#include <osgGA/GUIActionAdapter>
25
26#include <osg/Quat>
27#include <osg/Notify>
28#include <osg/BoundsChecking>
29#include <osg/observer_ptr>
30
31
32namespace osgVisual
33{ 
34
35/**
36 * \brief This class is a free spacemouse manipulator. It uses the 3DConnexion SpaceNavigator, which interface is implemented in manip_spaceMouse.h
37 *
38 * @author Torben Dannhauer
39 * @date  Aug 2009
40 */ 
41class FreeManipulator : public osgGA::MatrixManipulator
42{
43    public:
44                /**
45                 * \brief Constructor
46                 *
47                 * @param spacemouse : Pointer to the space mouse driver instance.
48                 */ 
49        FreeManipulator(SpaceMouse* spacemouse);
50
51                /**
52                 * \brief This function returns the classname.
53                 *
54                 * @return Classname of this manipulator.
55                 */ 
56        virtual const char* className() const { return "FreeManipulator"; }
57
58                /**
59                 * \brief Set the position of the matrix manipulator using a 4x4 Matrix.
60                 *
61                 * @param matrix : Matrix to set.
62                 */ 
63        virtual void setByMatrix(const osg::Matrixd& matrix);
64
65                /**
66                 * \brief Set the position of the matrix manipulator using a 4x4 Matrix.
67                 *
68                 * @param matrix : Inverse Matrix to set.
69                 */ 
70        virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
71
72        /** get the position of the manipulator as 4x4 Matrix.*/
73        virtual osg::Matrixd getMatrix() const;
74
75        /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
76        virtual osg::Matrixd getInverseMatrix() const;
77
78                /**
79                 * \brief Start/restart the manipulator.
80                 *
81                 * No further implementation
82                 *
83                 * @param ea : GUI eventadapter to use for initialization.
84                 * @param us : GUI actionadapter to use for initialization.
85                 */ 
86        virtual void init(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
87
88        /** handle events, return true if handled, false otherwise.*/
89        virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
90
91        /** Get the keyboard and mouse usage of this manipulator.*/
92        virtual void getUsage(osg::ApplicationUsage& usage) const;
93
94        void setTrackNode(osg::Node* node);
95        osg::Node* getTrackNode() {  return _trackNodePath.empty() ? 0 : _trackNodePath.back().get();  }
96
97        void computeNodeWorldToLocal(osg::Matrixd& worldToLocal) const;
98        void computeNodeLocalToWorld(osg::Matrixd& localToWorld) const;
99        bool validateNodePath() const;
100        osg::NodePath getNodePath() const;
101
102        typedef std::vector< osg::observer_ptr<osg::Node> >   ObserverNodePath;
103
104        ObserverNodePath      _trackNodePath;
105
106
107        void setTrackNodePath(const osg::NodePath& nodePath)
108        {
109           _trackNodePath.clear();
110           _trackNodePath.reserve(nodePath.size());
111           std::copy(nodePath.begin(), nodePath.end(), std::back_inserter(_trackNodePath));
112        }
113
114        osg::Vec3 getTrackNodeCenter();
115
116    protected:
117                /**
118                 * \brief Destructor. Because it is protected, no explicit delete myPointer by external caller is possible.
119                 * This forces the class to be used with osg::ref pointers.
120                 */ 
121        virtual ~FreeManipulator();
122
123                /**
124                 * \brief This function queries the space mouse driver instance and calculates the resultung movement of the manipulator.
125                 *
126                 * @return : True if calculation was successful.
127                 */ 
128        bool calcMovement();
129
130                /**
131                 * Position of the manipulator.
132                 */ 
133        osg::Vec3d  _position;
134
135                /**
136                 * Attitude of the manipulator.
137                 */ 
138        osg::Quat   _attitude;
139
140                /**
141                 * Pointer to the space mouse driver instance.
142                 */ 
143        SpaceMouse* _spaceMouse;
144};
145
146}       // END NAMESPACE
Note: See TracBrowser for help on using the repository browser.