OpenCOVER
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"
27namespace opencover {
28namespace ui {
29class Group;
30class Menu;
31class Action;
32class ButtonGroup;
33class Button;
34class Slider;
35}
36}
37
38#include <osg/Vec3>
39#include <osg/Matrix>
40#include <osg/MatrixTransform>
41#include <osg/Geometry>
42
43namespace vrui
44{
45class coNavInteraction;
46class coMouseButtonInteraction;
47class coRelativeInputInteraction;
48class coButtonMenuItem;
49class coRowMenu;
50}
51namespace opencover
52{
53class coMeasurement;
54class coVRLabel;
55class coVRPlugin;
56
57class COVEREXPORT coVRNavigationProvider
58{
59public:
60 coVRNavigationProvider(const std::string name, coVRPlugin* plugin);
63 ui::Button* navMenuButton = nullptr;
64 std::string getName() { return name; };
65 virtual void setEnabled(bool enabled);
66 bool isEnabled() { return enabled; };
67 int ID;
68private:
69 std::string name;
70 bool enabled=false;
71};
72
73class COVEREXPORT coVRNavigationManager: public ui::Owner
74{
75 static coVRNavigationManager *s_instance;
77
78public:
80 {
81 NavOther=-1,
96 NumNavModes // keep last
97 };
98
99 float AnalogX, AnalogY;
100
103
105
106 // process key events
107 bool keyEvent(int type, int keySym, int mod);
108
110 void processHotKeys(int keymask);
113 {
114 return collision;
115 }
116
117 void update();
118 void setMenuMode(bool state);
119
120 void updateHandMat(osg::Matrix &mat);
121 void setHandType(int pt);
122 void setNavMode(NavMode mode, bool updateGroup=true);
123 void setNavMode(std::string navMode);
125 {
126 return navMode;
127 }
128 ui::ButtonGroup *navGroup() const;
130 {
131 return navMode != NavNone;
132 }
133 bool mouseNav()
134 {
135 return doMouseNav;
136 }
138 {
139 return isViewerPosRotation;
140 }
142 {
143 isViewerPosRotation = b;
144 }
145
147 bool avoidCollision(osg::Vec3 &glideVec); // returns true if collision occurred
148
151 void setDriveSpeed(float speed);
152 bool isSnapping() const;
153 bool isDegreeSnapping() const;
154 float snappingDegrees() const;
155 void enableSnapping(bool enable);
156 void enableDegreeSnapping(bool enable, float degree);
157 bool restrictOn() const;
158
159 void setStepSize(float stepsize);
160 float getStepSize() const;
161 void doGuiScale(float scale);
162 void doGuiRotate(float x, float y, float z);
163 void doGuiTranslate(float x, float y, float z);
164
166
167 void toggleShowName(bool state);
168 void toggleInteractors(bool state);
169 void toggleCollide(bool state);
170
172 void doXform();
173 void stopXform();
175 void doScale();
176 void stopScale();
177 void startWalk();
178 void doWalk();
179 void stopWalk();
181 void doDrive();
182 void stopDrive();
183 void startFly();
184 void doFly();
185 void stopFly();
189 void doMouseScale(float);
197 void doMeasure();
199
200 void toggleSelectInteract(bool state);
203 void stopSelectInteract(bool mouse);
204
205
208
209 void highlightSelectedNode(osg::Node *selectedNode);
210 double speedFactor(double delta) const;
211 osg::Vec3 applySpeedFactor(osg::Vec3 vec) const;
212
213 void getHandWorldPosition(float *, float *, float *);
214
215 float getPhi(float relCoord1, float width1);
216
217 float getPhiZHori(float x2, float x1, float y2, float widthY, float widthX);
218 float getPhiZVerti(float y2, float y1, float x2, float widthX, float widthY);
219 void makeRotate(float heading, float pitch, float roll, int headingBool, int pitchBool, int rollBool);
220
222 {
223 rotationPoint = false;
224 }
226 {
227 rotationAxis = false;
228 }
230 {
231 return rotationPoint;
232 }
234 {
235 return rotationAxis;
236 }
237 void setRotationPoint(float x, float y, float z, float size = 1.f);
238 void setRotationPointVisible(bool visible);
240 {
241 return rotPointVec;
242 }
243 void setRotationAxis(float x, float y, float z);
244 void setTranslateFactor(float f)
245 {
246 guiTranslateFactor = f;
247 }
250
251
252private:
253 bool doMouseNav;
254 int mouseNavButtonRotate, mouseNavButtonScale, mouseNavButtonTranslate;
255 bool wiiNav;
256 double menuButtonStartTime;
257 double menuButtonQuitInterval;
258
259 bool collision;
260 bool ignoreCollision;
261 NavMode navMode;
262 NavMode oldNavMode;
263 std::list<coVRNavigationProvider*> navigationProviders;
264
265 /* until button is released */
266
267 bool shiftEnabled, shiftMouseNav;
268 bool isViewerPosRotation; // mouse rotate around current viewer position
269 osg::Matrix mat0;
270
271 osg::Matrix invBaseMatrix;
272 osg::Matrix oldInvBaseMatrix;
273 osg::Node *oldFloorNode = nullptr;
274 osg::Matrix oldFloorMatrix;
275 osg::NodePath oldNodePath;
276
277
278 float currentVelocity;
279
280 osg::Matrix old_mat, old_dcs_mat;
281 osg::Matrix old_xform_mat;
282 osg::Matrix handMat;
283 osg::Vec3 startHandPos; //we need the start value for ongoing interaction
284 osg::Vec3 startHandDir; //we need the start value for ongoing interaction
285 osg::Vec3 handPos, oldHandPos;
286 osg::Vec3 handDir, oldHandDir;
287 osg::Vec3 transformVec;
288 osg::Vec3 rotationVec;
289 bool rotationPoint;
290 bool rotationPointVisible;
291 bool rotationAxis;
292 float guiTranslateFactor;
293
294 float actScaleFactor; //fuer die Skalieroption, Initialisierung in der naechsten ifSchleife
295 float mx, my;
296 float x0, y0, relx0, rely0;
297 float oldRotx, newRotx, oldRoty, newRoty;
298 float modifiedVSize, modifiedHSize, yValViewer, yValObject;
299 float transXRel, transYRel, transZRel;
300 float originX, originY;
301
302 int wiiFlag;
303
304 osg::Node *oldSelectedNode_;
305
306 float oldDcsScaleFactor;
307
308 osg::Vec3 currentLeftPos; // in WC
309 osg::Vec3 currentRightPos;
310 osg::Vec3 oldLeftPos; // in WC
311 osg::Vec3 oldRightPos;
312 float collisionDist;
313
314 int jsZeroPosX, jsZeroPosY, jsOffsetX, jsOffsetY, jsXmax, jsYmax, jsXmin, jsYmin;
315 bool jsEnabled;
316
317 bool visensoJoystick;
318 bool joystickActive;
319
320 vrui::coNavInteraction *interactionA = nullptr;
321 vrui::coNavInteraction *interactionB = nullptr;
322 vrui::coNavInteraction *interactionC = nullptr;
323 vrui::coNavInteraction *interactionMenu = nullptr;
324 vrui::coNavInteraction *interactionShortcut = nullptr;
325 vrui::coMouseButtonInteraction *interactionMA = nullptr;
326 vrui::coMouseButtonInteraction *interactionMB = nullptr;
327 vrui::coMouseButtonInteraction *interactionMC = nullptr;
328 vrui::coRelativeInputInteraction *interactionRel = nullptr;
329
330 float navExp;
331
332 float syncInterval;
333
334 float stepSize;
335
336 float driveSpeed;
337
338 void init();
339 bool jump; // set to true if a jump has been performed to disable collision detection
340 bool snapping;
341 bool snappingD;
342 float snapDegrees;
343 bool m_restrict = false;
344 float rotationSpeed;
345 bool turntable;
346 bool animationWasRunning=false;
347
348 bool showGeodeName_;
349 osg::Node *oldShowNamesNode_ = nullptr;
350 coVRLabel *nameLabel_;
351 vrui::coRowMenu *nameMenu_;
352 vrui::coButtonMenuItem *nameButton_;
353 ui::Menu *navMenu_ = nullptr;
354 ui::Action *m_viewAll=nullptr, *m_resetView=nullptr;
355 ui::Group *navModes_ = nullptr;
356 ui::ButtonGroup *navGroup_ = nullptr;
357 ui::Button *noNavButton_=nullptr;
358 ui::Button *xformButton_=nullptr, *scaleButton_=nullptr, *flyButton_=nullptr, *walkButton_=nullptr, *driveButton_=nullptr;
359 ui::Button *xformRotButton_=nullptr, *xformTransButton_=nullptr, *selectButton_=nullptr, *showNameButton_=nullptr;
360 ui::Button *selectInteractButton_=nullptr;
361 ui::Button *measureButton_=nullptr, *traverseInteractorButton_=nullptr;
362 ui::Button *collisionButton_=nullptr, *snapButton_=nullptr;
363 ui::Slider *driveSpeedSlider_=nullptr;
364 ui::Action *scaleUpAction_=nullptr, *scaleDownAction_=nullptr;
365 ui::Slider *scaleSlider_=nullptr;
366 ui::Action *centerViewButton = nullptr;
367 ui::Action *printObjectTransform = nullptr;
368 osg::Vec3 rotPointVec;
369 osg::ref_ptr<osg::MatrixTransform> rotPoint;
370
371 std::vector<coMeasurement *> measurements;
372
373 void initInteractionDevice();
374 void initAxis();
375 void initHandDeviceGeometry();
376 void initCollMenu();
377 void initMatrices();
378 void initMenu();
379 void initShowName();
380 void initMeasure();
381
382 osg::Vec3 getCenter() const;
383 void centerView();
384 osg::Vec3 mouseNavCenter;
385};
386}
387#endif
double OSGVRUIEXPORT mod(double a, double b)
Definition: ARToolKit.h:33
collaborative interface manager
Definition: coVRCommunication.h:41
Definition: coVRLabel.h:52
Definition: coVRNavigationManager.h:58
virtual void setEnabled(bool enabled)
std::string getName()
Definition: coVRNavigationManager.h:64
coVRNavigationProvider(const std::string name, coVRPlugin *plugin)
bool isEnabled()
Definition: coVRNavigationManager.h:66
coVRPlugin * plugin
Definition: coVRNavigationManager.h:62
int ID
Definition: coVRNavigationManager.h:66
Definition: coVRNavigationManager.h:74
bool mouseNav()
Definition: coVRNavigationManager.h:133
bool getRotationAxisAcitve()
Definition: coVRNavigationManager.h:233
NavMode
Definition: coVRNavigationManager.h:80
@ XForm
Definition: coVRNavigationManager.h:83
@ Measure
Definition: coVRNavigationManager.h:93
@ Glide
Definition: coVRNavigationManager.h:86
@ Fly
Definition: coVRNavigationManager.h:85
@ Walk
Definition: coVRNavigationManager.h:87
@ TraverseInteractors
Definition: coVRNavigationManager.h:91
@ Menu
Definition: coVRNavigationManager.h:92
@ XFormRotate
Definition: coVRNavigationManager.h:89
@ SelectInteract
Definition: coVRNavigationManager.h:95
@ ShowName
Definition: coVRNavigationManager.h:88
@ Select
Definition: coVRNavigationManager.h:94
@ NavNone
Definition: coVRNavigationManager.h:82
@ Scale
Definition: coVRNavigationManager.h:84
@ XFormTranslate
Definition: coVRNavigationManager.h:90
void enableDegreeSnapping(bool enable, float degree)
void toggleInteractors(bool state)
void processHotKeys(int keymask)
osg::Vec3 getRotationPoint()
Definition: coVRNavigationManager.h:239
bool getCollision()
Definition: coVRNavigationManager.h:112
void setTranslateFactor(float f)
Definition: coVRNavigationManager.h:244
void enableSnapping(bool enable)
void registerNavigationProvider(coVRNavigationProvider *)
float AnalogX
Definition: coVRNavigationManager.h:99
bool isNavigationEnabled()
Definition: coVRNavigationManager.h:129
bool avoidCollision(osg::Vec3 &glideVec)
void unregisterNavigationProvider(coVRNavigationProvider *)
void setRotationPoint(float x, float y, float z, float size=1.f)
void enableViewerPosRotation(bool b)
Definition: coVRNavigationManager.h:141
void doGuiTranslate(float x, float y, float z)
float getPhiZHori(float x2, float x1, float y2, float widthY, float widthX)
bool isViewerPosRotationEnabled()
Definition: coVRNavigationManager.h:137
void updateHandMat(osg::Matrix &mat)
static coVRNavigationManager * instance()
void toggleSelectInteract(bool state)
osg::Vec3 applySpeedFactor(osg::Vec3 vec) const
double speedFactor(double delta) const
bool keyEvent(int type, int keySym, int mod)
void makeRotate(float heading, float pitch, float roll, int headingBool, int pitchBool, int rollBool)
float getPhi(float relCoord1, float width1)
void setNavMode(std::string navMode)
void highlightSelectedNode(osg::Node *selectedNode)
NavMode getMode()
Definition: coVRNavigationManager.h:124
void setRotationAxis(float x, float y, float z)
void disableRotationAxis()
Definition: coVRNavigationManager.h:225
void getHandWorldPosition(float *, float *, float *)
void setRotationPointVisible(bool visible)
void stopSelectInteract(bool mouse)
void doGuiRotate(float x, float y, float z)
bool getRotationPointActive()
Definition: coVRNavigationManager.h:229
void setStepSize(float stepsize)
ui::ButtonGroup * navGroup() const
float getPhiZVerti(float y2, float y1, float x2, float widthX, float widthY)
void disableRotationPoint()
Definition: coVRNavigationManager.h:221
void setNavMode(NavMode mode, bool updateGroup=true)
make sure to clean up properly in the plugin's dtor
Definition: coVRPlugin.h:73
Definition: coButtonMenuItem.h:31
Definition: coMouseButtonInteraction.h:21
Definition: coNavInteraction.h:19
Definition: coRelativeInputInteraction.h:18
Definition: coRowMenu.h:37