OpenCOVER
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
coVRNavigationManager.h
Go to the documentation of this file.
1 /* This file is part of COVISE.
2 
3  You can use it under the terms of the GNU Lesser General Public License
4  version 2.1 or later, see lgpl-2.1.txt.
5 
6  * License: LGPL 2+ */
7 
8 #ifndef COVR_NAVIGATION_MANAGER_H
9 #define COVR_NAVIGATION_MANAGER_H
10 
24 #include <util/common.h>
25 
26 #include "ui/Owner.h"
27 namespace opencover {
28 namespace ui {
29 class Group;
30 class Menu;
31 class Action;
32 class ButtonGroup;
33 class Button;
34 class Slider;
35 }
36 }
37 
38 #include <osg/Vec3>
39 #include <osg/Matrix>
40 #include <osg/MatrixTransform>
41 #include <osg/Geometry>
42 
43 namespace vrui
44 {
45 class coNavInteraction;
48 class coButtonMenuItem;
49 class coRowMenu;
50 }
51 namespace opencover
52 {
53 class coMeasurement;
54 class coVRLabel;
55 
56 class COVEREXPORT coVRNavigationManager: public ui::Owner
57 {
58  static coVRNavigationManager *s_instance;
60 
61 public:
62  enum NavMode
63  {
64  NavOther=-1,
68  Fly,
79  NumNavModes // keep last
80  };
81 
82  float AnalogX, AnalogY;
83 
85  void updatePerson();
86 
87  static coVRNavigationManager *instance();
88 
89  // process key events
90  bool keyEvent(int type, int keySym, int mod);
91 
92  void doWalkMoveToFloor();
93  void processHotKeys(int keymask);
94  void adjustFloorHeight();
95  bool getCollision()
96  {
97  return collision;
98  }
99 
100  void update();
101  void setMenuMode(bool state);
102 
103  void updateHandMat(osg::Matrix &mat);
104  void setHandType(int pt);
105  void setNavMode(NavMode mode, bool updateGroup=true);
107  {
108  return navMode;
109  }
110  ui::ButtonGroup *navGroup() const;
112  {
113  return navMode != NavNone;
114  }
115  bool mouseNav()
116  {
117  return doMouseNav;
118  }
120  {
121  return isViewerPosRotation;
122  }
124  {
125  isViewerPosRotation = b;
126  }
127 
128  void saveCurrentBaseMatAsOldBaseMat();
129  bool avoidCollision(osg::Vec3 &glideVec); // returns true if collision occurred
130 
131  void wasJumping();
132  float getDriveSpeed();
133  void setDriveSpeed(float speed);
134  bool isSnapping() const;
135  bool isDegreeSnapping() const;
136  float snappingDegrees() const;
137  void enableSnapping(bool enable);
138  void enableDegreeSnapping(bool enable, float degree);
139  bool restrictOn() const;
140 
141  void setStepSize(float stepsize);
142  float getStepSize() const;
143  void doGuiScale(float scale);
144  void doGuiRotate(float x, float y, float z);
145  void doGuiTranslate(float x, float y, float z);
146 
147  int readConfigFile();
148 
149  void toggleShowName(bool state);
150  void toggleInteractors(bool state);
151  void toggleCollide(bool state);
152 
153  void startXform();
154  void doXform();
155  void stopXform();
156  void startScale();
157  void doScale();
158  void stopScale();
159  void startWalk();
160  void doWalk();
161  void stopWalk();
162  void startDrive();
163  void doDrive();
164  void stopDrive();
165  void startFly();
166  void doFly();
167  void stopFly();
168  void doMouseFly();
169  void doMouseXform();
170  void doMouseScale();
171  void doMouseScale(float);
172  void doMouseWalk();
173  void stopMouseNav();
174  void startMouseNav();
175  void startShowName();
176  void doShowName();
177  void stopShowName();
178  void startMeasure();
179  void doMeasure();
180  void stopMeasure();
181 
182  void toggleSelectInteract(bool state);
183  void startSelectInteract();
184  void doSelectInteract();
185  void stopSelectInteract(bool mouse);
186 
187 
188  void doXformRotate();
189  void doXformTranslate();
190 
191  void highlightSelectedNode(osg::Node *selectedNode);
192  double speedFactor(double delta) const;
193  osg::Vec3 applySpeedFactor(osg::Vec3 vec) const;
194 
195  void getHandWorldPosition(float *, float *, float *);
196 
197  float getPhi(float relCoord1, float width1);
198 
199  float getPhiZHori(float x2, float x1, float y2, float widthY, float widthX);
200  float getPhiZVerti(float y2, float y1, float x2, float widthX, float widthY);
201  void makeRotate(float heading, float pitch, float roll, int headingBool, int pitchBool, int rollBool);
202 
204  {
205  rotationPoint = false;
206  }
208  {
209  rotationAxis = false;
210  }
212  {
213  return rotationPoint;
214  }
216  {
217  return rotationAxis;
218  }
219  void setRotationPoint(float x, float y, float z, float size = 1.f);
220  void setRotationPointVisible(bool visible);
221  osg::Vec3 getRotationPoint()
222  {
223  return rotPointVec;
224  }
225  void setRotationAxis(float x, float y, float z);
226  void setTranslateFactor(float f)
227  {
228  guiTranslateFactor = f;
229  }
230 
231 private:
232  bool doMouseNav;
233  int mouseNavButtonRotate, mouseNavButtonScale, mouseNavButtonTranslate;
234  bool wiiNav;
235  double menuButtonStartTime;
236  double menuButtonQuitInterval;
237 
238  bool collision;
239  bool ignoreCollision;
240  NavMode navMode;
241  NavMode oldNavMode;
242 
243  /* until button is released */
244 
245  bool shiftEnabled, shiftMouseNav;
246  bool isViewerPosRotation; // mouse rotate around current viewer position
247  osg::Matrix mat0;
248 
249  osg::Matrix invBaseMatrix;
250  osg::Matrix oldInvBaseMatrix;
251  osg::Node *oldFloorNode = nullptr;
252  osg::Matrix oldFloorMatrix;
253  osg::NodePath oldNodePath;
254 
255 
256  float currentVelocity;
257 
258  osg::Matrix old_mat, old_dcs_mat;
259  osg::Matrix old_xform_mat;
260  osg::Matrix handMat;
261  osg::Vec3 startHandPos; //we need the start value for ongoing interaction
262  osg::Vec3 startHandDir; //we need the start value for ongoing interaction
263  osg::Vec3 handPos, oldHandPos;
264  osg::Vec3 handDir, oldHandDir;
265  osg::Vec3 transformVec;
266  osg::Vec3 rotationVec;
267  bool rotationPoint;
268  bool rotationPointVisible;
269  bool rotationAxis;
270  float guiTranslateFactor;
271 
272  float actScaleFactor; //fuer die Skalieroption, Initialisierung in der naechsten ifSchleife
273  float mx, my;
274  float x0, y0, relx0, rely0;
275  float oldRotx, newRotx, oldRoty, newRoty;
276  float modifiedVSize, modifiedHSize, yValViewer, yValObject;
277  float transXRel, transYRel, transZRel;
278  float originX, originY;
279 
280  int wiiFlag;
281 
282  osg::Node *oldSelectedNode_;
283 
284  float oldDcsScaleFactor;
285 
286  osg::Vec3 currentLeftPos; // in WC
287  osg::Vec3 currentRightPos;
288  osg::Vec3 oldLeftPos; // in WC
289  osg::Vec3 oldRightPos;
290  float collisionDist;
291 
292  int jsZeroPosX, jsZeroPosY, jsOffsetX, jsOffsetY, jsXmax, jsYmax, jsXmin, jsYmin;
293  bool jsEnabled;
294 
295  bool visensoJoystick;
296  bool joystickActive;
297 
298  vrui::coNavInteraction *interactionA = nullptr;
299  vrui::coNavInteraction *interactionB = nullptr;
300  vrui::coNavInteraction *interactionC = nullptr;
301  vrui::coNavInteraction *interactionMenu = nullptr;
302  vrui::coNavInteraction *interactionShortcut = nullptr;
303  vrui::coMouseButtonInteraction *interactionMA = nullptr;
304  vrui::coMouseButtonInteraction *interactionMB = nullptr;
305  vrui::coMouseButtonInteraction *interactionMC = nullptr;
306  vrui::coRelativeInputInteraction *interactionRel = nullptr;
307 
308  float navExp;
309 
310  float syncInterval;
311 
312  float stepSize;
313 
314  float driveSpeed;
315 
316  void init();
317  bool jump; // set to true if a jump has been performed to disable collision detection
318  bool snapping;
319  bool snappingD;
320  float snapDegrees;
321  bool m_restrict = false;
322  float rotationSpeed;
323  bool turntable;
324  bool animationWasRunning=false;
325 
326  bool showGeodeName_;
327  osg::Node *oldShowNamesNode_ = nullptr;
328  coVRLabel *nameLabel_;
329  vrui::coRowMenu *nameMenu_;
330  vrui::coButtonMenuItem *nameButton_;
331  ui::Menu *navMenu_ = nullptr;
332  ui::Action *m_viewAll=nullptr, *m_resetView=nullptr;
333  ui::Group *navModes_ = nullptr;
334  ui::ButtonGroup *navGroup_ = nullptr;
335  ui::Button *noNavButton_=nullptr;
336  ui::Button *xformButton_=nullptr, *scaleButton_=nullptr, *flyButton_=nullptr, *walkButton_=nullptr, *driveButton_=nullptr;
337  ui::Button *xformRotButton_=nullptr, *xformTransButton_=nullptr, *selectButton_=nullptr, *showNameButton_=nullptr;
338  ui::Button *selectInteractButton_=nullptr;
339  ui::Button *measureButton_=nullptr, *traverseInteractorButton_=nullptr;
340  ui::Button *collisionButton_=nullptr, *snapButton_=nullptr;
341  ui::Slider *driveSpeedSlider_=nullptr;
342  ui::Action *scaleUpAction_=nullptr, *scaleDownAction_=nullptr;
343  ui::Slider *scaleSlider_=nullptr;
344 
345  osg::Vec3 rotPointVec;
346  osg::ref_ptr<osg::MatrixTransform> rotPoint;
347 
348  std::vector<coMeasurement *> measurements;
349 
350  void initInteractionDevice();
351  void initAxis();
352  void initHandDeviceGeometry();
353  void initCollMenu();
354  void initMatrices();
355  void initMenu();
356  void initShowName();
357  void initMeasure();
358 
359  osg::Vec3 getCenter() const;
360 
361  osg::Vec3 mouseNavCenter;
362 };
363 }
364 #endif
Definition: coVRNavigationManager.h:65
NavMode getMode()
Definition: coVRNavigationManager.h:106
Definition: coButtonMenuItem.h:30
Definition: coVRNavigationManager.h:69
osg::Vec3 getRotationPoint()
Definition: coVRNavigationManager.h:221
Definition: coVRNavigationManager.h:67
Definition: coVRNavigationManager.h:74
Definition: coVRNavigationManager.h:66
Definition: coNavInteraction.h:17
Definition: coVRNavigationManager.h:76
void setTranslateFactor(float f)
Definition: coVRNavigationManager.h:226
Definition: coVRNavigationManager.h:70
bool mouseNav()
Definition: coVRNavigationManager.h:115
bool getRotationAxisAcitve()
Definition: coVRNavigationManager.h:215
Definition: coVRNavigationManager.h:72
float AnalogY
Definition: coVRNavigationManager.h:82
double OSGVRUIEXPORT mod(double a, double b)
bool getRotationPointActive()
Definition: coVRNavigationManager.h:211
bool isNavigationEnabled()
Definition: coVRNavigationManager.h:111
bool isViewerPosRotationEnabled()
Definition: coVRNavigationManager.h:119
bool getCollision()
Definition: coVRNavigationManager.h:95
Definition: coRowMenu.h:36
void disableRotationAxis()
Definition: coVRNavigationManager.h:207
Definition: coVRNavigationManager.h:78
Definition: coVRNavigationManager.h:77
void disableRotationPoint()
Definition: coVRNavigationManager.h:203
Definition: coVRLabel.h:51
Definition: coRelativeInputInteraction.h:16
Definition: coVRNavigationManager.h:56
NavMode
Definition: coVRNavigationManager.h:62
Definition: coVRNavigationManager.h:75
Definition: coMouseButtonInteraction.h:19
Definition: coVRNavigationManager.h:73
Definition: coVRNavigationManager.h:68
void enableViewerPosRotation(bool b)
Definition: coVRNavigationManager.h:123
Definition: coVRNavigationManager.h:71