source: osgVisual/trunk/include/manip_Spacemouse/manip_freeSpaceMouse.h @ 221

Last change on this file since 221 was 221, checked in by Torben Dannhauer, 13 years ago

Updated copyright NOTICE
(No code changes)

File size: 4.7 KB
Line 
1#pragma once
2/* -*-c++-*- osgVisual - Copyright (C) 2009-2011 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/CameraManipulator>
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::CameraManipulator
42{
43        #include <leakDetection.h>
44    public:
45                /**
46                 * \brief Constructor
47                 *
48                 * @param spacemouse : Pointer to the space mouse driver instance.
49                 */ 
50        FreeManipulator(SpaceMouse* spacemouse);
51
52                /**
53                 * \brief This function returns the classname.
54                 *
55                 * @return Classname of this manipulator.
56                 */ 
57        virtual const char* className() const { return "FreeManipulator"; }
58
59                /**
60                 * \brief Set the position of the matrix manipulator using a 4x4 Matrix.
61                 *
62                 * @param matrix : Matrix to set.
63                 */ 
64        virtual void setByMatrix(const osg::Matrixd& matrix);
65
66                /**
67                 * \brief Set the position of the matrix manipulator using a 4x4 Matrix.
68                 *
69                 * @param matrix : Inverse Matrix to set.
70                 */ 
71        virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
72
73        /** get the position of the manipulator as 4x4 Matrix.*/
74        virtual osg::Matrixd getMatrix() const;
75
76        /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
77        virtual osg::Matrixd getInverseMatrix() const;
78
79                /**
80                 * \brief Start/restart the manipulator.
81                 *
82                 * No further implementation
83                 *
84                 * @param ea : GUI eventadapter to use for initialization.
85                 * @param us : GUI actionadapter to use for initialization.
86                 */ 
87        virtual void init(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
88
89        /** handle events, return true if handled, false otherwise.*/
90        virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
91
92        /** Get the keyboard and mouse usage of this manipulator.*/
93        virtual void getUsage(osg::ApplicationUsage& usage) const;
94
95        void setTrackNode(osg::Node* node);
96        osg::Node* getTrackNode() {  return _trackNodePath.empty() ? 0 : _trackNodePath.back().get();  }
97
98        void computeNodeWorldToLocal(osg::Matrixd& worldToLocal) const;
99        void computeNodeLocalToWorld(osg::Matrixd& localToWorld) const;
100        bool validateNodePath() const;
101        osg::NodePath getNodePath() const;
102
103        typedef std::vector< osg::observer_ptr<osg::Node> >   ObserverNodePath;
104
105        ObserverNodePath      _trackNodePath;
106
107
108        void setTrackNodePath(const osg::NodePath& nodePath)
109        {
110           _trackNodePath.clear();
111           _trackNodePath.reserve(nodePath.size());
112           std::copy(nodePath.begin(), nodePath.end(), std::back_inserter(_trackNodePath));
113        }
114
115        osg::Vec3 getTrackNodeCenter();
116
117    protected:
118                /**
119                 * \brief Destructor. Because it is protected, no explicit delete myPointer by external caller is possible.
120                 * This forces the class to be used with osg::ref pointers.
121                 */ 
122        virtual ~FreeManipulator();
123
124                /**
125                 * \brief This function queries the space mouse driver instance and calculates the resultung movement of the manipulator.
126                 *
127                 * @return : True if calculation was successful.
128                 */ 
129        bool calcMovement();
130
131                /**
132                 * Position of the manipulator.
133                 */ 
134        osg::Vec3d  _position;
135
136                /**
137                 * Attitude of the manipulator.
138                 */ 
139        osg::Quat   _attitude;
140
141                /**
142                 * Pointer to the space mouse driver instance.
143                 */ 
144        SpaceMouse* _spaceMouse;
145};
146
147}       // END NAMESPACE
Note: See TracBrowser for help on using the repository browser.