H3D API  2.4.1
H3DNavigation.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __H3DNAVIGATION_H__
30 #define __H3DNAVIGATION_H__
31 
33 #include <H3D/X3DViewpointNode.h>
34 
35 
36 namespace H3D {
37 
41  class H3DAPI_API H3DNavigation {
42  public:
43 
44  typedef enum {
45  ALL = 1,
46  MOUSE = 2,
47  KEYBOARD = 3,
48  HAPTICSDEVICE = 4,
49  SWS = 5
50  } NavigationDevices;
51 
53  H3DNavigation();
54 
57  old_vp.reset( NULL );
58  h3d_navigations.remove( this );
59  }
60 
62  void doNavigation( string navigation_type, X3DViewpointNode * vp,
63  X3DChildNode *topNode, bool detect_collision,
64  const vector< H3DFloat > &avatar_size,
65  H3DFloat speed,
66  const vector< string > &transition_type,
67  H3DTime transition_time );
68 
70  static void disableDevice( int device );
71 
73  static void enableDevice( int device );
74 
75  static bool isEnabled( int device );
76 
81  X3DViewpointNode *potential_vp ) {
82  if( old_vp.get() && old_vp.get() != potential_vp ) {
83  return old_vp.get();
84  }
85  return potential_vp;
86  }
87 
92  static X3DViewpointNode * viewpointToUse( X3DViewpointNode *potential_vp,
93  int nav_index );
94 
95  static string getTransitionType(
96  const vector< string > &transition_types );
97 
99  inline void leftButtonUpdate( bool _left_button ) {
100  if( mouse_nav.get() )
101  mouse_nav->leftButtonUpdate( _left_button );
102  }
103 
105  inline void motionUpdate( int x, int y ) {
106  if( mouse_nav.get() )
107  mouse_nav->motionUpdate( x, y );
108  }
109 
111  inline void scrollWheelUpdate( bool up ) {
112  if( mouse_nav.get() )
113  mouse_nav->scrollWheelUpdate( up );
114  }
115 
116  inline void handleKeyAction( int key, bool pressed ) {
117  if( keyboard_nav.get() )
118  keyboard_nav->handleKeyAction( key, pressed );
119  }
120 
121  // Used to force jump of a viewpoint, for example when an anchor is
122  // selected.
123  static bool force_jump;
124 
125  protected:
127  H3DUniquePtr< MouseNavigation > mouse_nav;
128  H3DUniquePtr< KeyboardNavigation > keyboard_nav;
129  H3DUniquePtr< HapticDeviceNavigation > haptic_device_nav;
130  H3DUniquePtr< SWSNavigation > sws_navigation;
131 
132  // Time of last update.
133  H3DTime last_time;
134 
135  // Variables needed to correctly do linear interpolation between
136  // two viewpoints.
137  // Flag used to know if we are in linear interpolation mode.
138  bool linear_interpolate;
139  Vec3f goal_position;
140  Rotation goal_orientation;
141  Rotation old_vp_orientation;
142  Vec3f start_position, move_direction;
143  Rotation start_orientation;
144  Vec3f old_vp_pos;
145  H3DTime start_time;
147  // List of H3DNavigation instances, needed by the static functions.
148  static list< H3DNavigation * > h3d_navigations;
149 
150  // Returns true if the scaling factors are uniform, i.e. the same.
151  bool isUniformScaling( const Vec3f &scale );
152 
153  };
154 
155 }
156 
157 #endif
Header file for H3DNavigationDevices, classes for navigation.
Header file for X3DViewpointNode, X3D scene-graph node.
H3DNavigation is a class used for navigation in H3DAPI.
Definition: H3DNavigation.h:41
X3DViewpointNode * viewpointToUse(X3DViewpointNode *potential_vp)
Compares the given X3DViewpointNode to the X3DViewpointNode used by the NavigationInfo.
Definition: H3DNavigation.h:80
void leftButtonUpdate(bool _left_button)
Called when left button has changed.
Definition: H3DNavigation.h:99
void motionUpdate(int x, int y)
Called for each movement change.
Definition: H3DNavigation.h:105
H3DUniquePtr< MouseNavigation > mouse_nav
Devices which it is possible to use for navigation.
Definition: H3DNavigation.h:127
void scrollWheelUpdate(bool up)
Called when scroll wheel updates.
Definition: H3DNavigation.h:111
~H3DNavigation()
Destructor.
Definition: H3DNavigation.h:56
This abstract node type indicates that the concrete nodes which are instantiated based on it may be u...
Definition: X3DChildNode.h:42
The X3DViewpointNode node defines a specific location in the local coordinate system from which the u...
Definition: X3DViewpointNode.h:239
Rotation()
H3DDouble x
float H3DFloat
double H3DTime
H3D API namespace.
Definition: Anchor.h:38