vrpn  07.33
Virtual Reality Peripheral Network
vrpn_Tracker_AnalogFly.h
Go to the documentation of this file.
1 #ifndef INCLUDED_ANALOGFLY
2 #define INCLUDED_ANALOGFLY
3 
4 #include <quat.h> // for q_matrix_type
5 #include <stdio.h> // for NULL
6 
7 #include "vrpn_Analog.h" // for vrpn_ANALOGCB, etc
8 #include "vrpn_Button.h" // for vrpn_BUTTONCB, etc
9 #include "vrpn_Configure.h" // for VRPN_API, VRPN_CALLBACK
10 #include "vrpn_Shared.h" // for timeval
11 #include "vrpn_Tracker.h" // for vrpn_Tracker
12 #include "vrpn_Types.h" // for VRPN_FALSE, vrpn_FALSE
13 
15 struct vrpn_HANDLERPARAM;
16 
17 // This parameter is passed to the constructor for the AnalogFly; it describes
18 // the channel mapping and parameters of that mapping, as well as the button
19 // that will be used to reset the tracker when it is pushed. Any entry which
20 // has a NULL pointer for the name is disabled.
21 
23 
24  public:
25 
27  { name = NULL; channel = 0; offset = 0.0f; thresh = 0.0f;
28  scale = 1.0f; power = 1.0f; };
29 
30  char * name; //< Name of the Analog device driving this axis
31  int channel; //< Which channel to use from the Analog device
32  float offset; //< Offset to apply to values from this channel to reach 0
33  float thresh; //< Threshold to apply after offset within which values count as zero
34  float scale; //< Scale applied to values after offset and threshold
35  float power; //< Power to which values are taken after scaling
36 };
37 
39 
40  public:
41 
43  x.name = y.name = z.name =
44  sx.name = sy.name = sz.name = reset_name = clutch_name = NULL;
45  }
46 
49 
51  vrpn_TAF_axis sx, sy, sz;
52 
54 
55  char * reset_name;
57 
59  // large distances
60 
61  char * clutch_name;
63 };
64 
65 class VRPN_API vrpn_Tracker_AnalogFly; // Forward reference
66 
68 public:
69  vrpn_TAF_fullaxis (void) { ana = NULL; value = 0.0; af = NULL; };
70 
71  vrpn_TAF_axis axis;
74  double value;
75 };
76 
78 // tracker into a tracker by interpreting the joystick
79 // positions as either position or velocity inputs and "flying" the user
80 // around based on analog values.
81 // The "absolute" parameter tells whether the tracker integrates differential
82 // changes (the default, with FALSE) or takes the analog values as absolute
83 // positions or orientations.
84 // The mapping from analog channels to directions (or orientation changes) is
85 // described in the vrpn_Tracker_AnalogFlyParam parameter. For translations,
86 // values above threshold are multiplied by the scale and then taken to the
87 // power; the result is the number of meters (or meters per second) to move
88 // in that direction. For rotations, the result is taken as the number of
89 // revolutions (or revolutions per second) around the given axis.
90 // Note that the reset button has no effect on an absolute tracker.
91 // The time reported by absolute trackers is as of the last report they have
92 // had from their analog devices. The time reported by differential trackers
93 // is the local time that the report was generated. This is to allow a
94 // gen-locked camera tracker to have its time values passed forward through
95 // the AnalogFly class.
96 
97 // If reportChanges is TRUE, updates are ONLY sent if there has been a
98 // change since the last update, in which case they are generated no faster
99 // than update_rate.
100 
101 // If worldFrame is TRUE, then translations and rotations take place in the
102 // world frame, rather than the local frame. Useful for a simulated wand
103 // when doing desktop testing of immersive apps - easier to keep under control.
104 
106  public:
107  vrpn_Tracker_AnalogFly (const char * name, vrpn_Connection * trackercon,
109  float update_rate, bool absolute = vrpn_FALSE,
110  bool reportChanges = VRPN_FALSE, bool worldFrame = VRPN_FALSE);
111 
112  virtual ~vrpn_Tracker_AnalogFly (void);
113 
114  virtual void mainloop ();
115  virtual void reset (void);
116 
117  void update (q_matrix_type &);
118 
119  static void VRPN_CALLBACK handle_joystick (void *, const vrpn_ANALOGCB);
120  static int VRPN_CALLBACK handle_newConnection (void *, vrpn_HANDLERPARAM);
121 
122  protected:
123 
124  double d_update_interval; //< How long to wait between sends
125  struct timeval d_prevtime; //< Time of the previous report
126  bool d_absolute; //< Report absolute (vs. differential)?
129 
130  vrpn_TAF_fullaxis d_x, d_y, d_z, d_sx, d_sy, d_sz;
133 
138 
139  q_matrix_type d_initMatrix, d_currentMatrix, d_clutchMatrix;
140 
141  void update_matrix_based_on_values (double time_interval);
142  void convert_matrix_to_tracker (void);
143 
144  bool shouldReport (double elapsedInterval) const;
145 
146  int setup_channel (vrpn_TAF_fullaxis * full);
147  int teardown_channel (vrpn_TAF_fullaxis * full);
148 
149  static void VRPN_CALLBACK handle_analog_update (void * userdata,
150  const vrpn_ANALOGCB info);
151  static void VRPN_CALLBACK handle_reset_press (void * userdata, const vrpn_BUTTONCB info);
152  static void VRPN_CALLBACK handle_clutch_press (void * userdata, const vrpn_BUTTONCB info);
153 };
154 
155 #endif
This class will turn an analog device such as a joystick or a camera.
vrpn_Button_Remote * d_reset_button
char * clutch_name
Clutch device that is used to enable relative motion over.
Generic connection class not specific to the transport mechanism.
char * reset_name
Button device that is used to reset the matrix to the origin.
#define VRPN_CALLBACK
#define VRPN_API
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
This structure is what is passed to a vrpn_Connection message callback.
vrpn_Button_Remote * d_clutch_button
vrpn_Analog_Remote * ana
vrpn_Tracker_AnalogFly * af
class VRPN_API vrpn_Tracker_AnalogFly