Panda3D
driveInterface.h
1 // Filename: driveInterface.h
2 // Created by: drose (12Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef DRIVEINTERFACE_H
16 #define DRIVEINTERFACE_H
17 
18 #include "pandabase.h"
19 
20 #include "mouseInterfaceNode.h"
21 #include "modifierButtons.h"
22 #include "luse.h"
23 #include "linmath_events.h"
24 #include "transformState.h"
25 
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : DriveInterface
29 // Description : This is a TFormer, similar to Trackball, that moves
30 // around a transform matrix in response to mouse input.
31 // The basic motion is on a horizontal plane, as if
32 // driving a vehicle.
33 ////////////////////////////////////////////////////////////////////
34 class EXPCL_PANDA_TFORM DriveInterface : public MouseInterfaceNode {
35 PUBLISHED:
36  DriveInterface(const string &name = "");
37  ~DriveInterface();
38 
39  INLINE void set_forward_speed(PN_stdfloat speed);
40  INLINE PN_stdfloat get_forward_speed() const;
41  INLINE void set_reverse_speed(PN_stdfloat speed);
42  INLINE PN_stdfloat get_reverse_speed() const;
43  INLINE void set_rotate_speed(PN_stdfloat speed);
44  INLINE PN_stdfloat get_rotate_speed() const;
45  INLINE void set_vertical_dead_zone(PN_stdfloat zone);
46  INLINE PN_stdfloat get_vertical_dead_zone() const;
47  INLINE void set_horizontal_dead_zone(PN_stdfloat zone);
48  INLINE PN_stdfloat get_horizontal_dead_zone() const;
49 
50  INLINE void set_vertical_ramp_up_time(PN_stdfloat ramp_up_time);
51  INLINE PN_stdfloat get_vertical_ramp_up_time() const;
52  INLINE void set_vertical_ramp_down_time(PN_stdfloat ramp_down_time);
53  INLINE PN_stdfloat get_vertical_ramp_down_time() const;
54  INLINE void set_horizontal_ramp_up_time(PN_stdfloat ramp_up_time);
55  INLINE PN_stdfloat get_horizontal_ramp_up_time() const;
56  INLINE void set_horizontal_ramp_down_time(PN_stdfloat ramp_down_time);
57  INLINE PN_stdfloat get_horizontal_ramp_down_time() const;
58 
59  INLINE PN_stdfloat get_speed() const;
60  INLINE PN_stdfloat get_rot_speed() const;
61 
62  void reset();
63 
64  /// **** Translation ****
65 
66  INLINE const LPoint3 &get_pos() const;
67  INLINE PN_stdfloat get_x() const;
68  INLINE PN_stdfloat get_y() const;
69  INLINE PN_stdfloat get_z() const;
70  INLINE void set_pos(const LVecBase3 &vec);
71  INLINE void set_pos(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
72  INLINE void set_x(PN_stdfloat x);
73  INLINE void set_y(PN_stdfloat y);
74  INLINE void set_z(PN_stdfloat z);
75 
76  /// **** Rotation ****
77 
78  INLINE const LVecBase3 &get_hpr() const;
79  INLINE PN_stdfloat get_h() const;
80  INLINE PN_stdfloat get_p() const;
81  INLINE PN_stdfloat get_r() const;
82  INLINE void set_hpr(const LVecBase3 &hpr);
83  INLINE void set_hpr(PN_stdfloat h, PN_stdfloat p, PN_stdfloat r);
84  INLINE void set_h(PN_stdfloat h);
85  INLINE void set_p(PN_stdfloat p);
86  INLINE void set_r(PN_stdfloat r);
87 
88  void set_force_roll(PN_stdfloat force_roll);
89 
90  INLINE void set_ignore_mouse(bool ignore_mouse);
91  INLINE bool get_ignore_mouse() const;
92 
93  INLINE void set_force_mouse(bool force_mouse);
94  INLINE bool get_force_mouse() const;
95 
96  INLINE void set_stop_this_frame(bool stop_this_frame);
97  INLINE bool get_stop_this_frame() const;
98 
99  void set_mat(const LMatrix4 &mat);
100  const LMatrix4 &get_mat();
101 
102  void force_dgraph();
103 
104 private:
105  void apply(double x, double y, bool any_button);
106 
107  PN_stdfloat _forward_speed; // units / sec, mouse all the way up
108  PN_stdfloat _reverse_speed; // units / sec, mouse all the way down
109  PN_stdfloat _rotate_speed; // degrees / sec, mouse all the way over
110  PN_stdfloat _vertical_dead_zone; // fraction of window size
111  PN_stdfloat _horizontal_dead_zone; // fraction of window size
112  PN_stdfloat _vertical_center; // window units, 0 = center, -1 = bottom, 1 = top
113  PN_stdfloat _horizontal_center; // window units, 0 = center, -1 = left, 1 = right
114 
115  // The time it takes to ramp up to full speed from a stop (or return
116  // to a stop from full speed) when using the keyboard.
117  PN_stdfloat _vertical_ramp_up_time;
118  PN_stdfloat _vertical_ramp_down_time;
119  PN_stdfloat _horizontal_ramp_up_time;
120  PN_stdfloat _horizontal_ramp_down_time;
121 
122  PN_stdfloat _speed; // instantaneous units / sec
123  PN_stdfloat _rot_speed; // instantaneous rotational units / sec
124 
125  LPoint3 _xyz;
126  LVecBase3 _hpr;
127  LVector3 _vel;
128  bool _ignore_mouse;
129  bool _force_mouse;
130  bool _stop_this_frame;
131 
132  // This is only used to return a temporary value in get_mat().
133  LMatrix4 _mat;
134 
135  // Remember which arrow keys are being held down and which aren't,
136  // and at what point they last changed state.
137  class KeyHeld {
138  public:
139  KeyHeld();
140  PN_stdfloat get_effect(PN_stdfloat ramp_up_time, PN_stdfloat ramp_down_time);
141  void set_key(bool down);
142  void clear();
143  bool operator < (const KeyHeld &other) const;
144 
145  PN_stdfloat _effect;
146  bool _down;
147  double _changed_time;
148  PN_stdfloat _effect_at_change;
149  };
150  KeyHeld _up_arrow, _down_arrow;
151  KeyHeld _left_arrow, _right_arrow;
152 
153 
154 protected:
155  // Inherited from DataNode
156  virtual void do_transmit_data(DataGraphTraverser *trav,
157  const DataNodeTransmit &input,
158  DataNodeTransmit &output);
159 
160 private:
161  // inputs
162  int _xy_input;
163  int _button_events_input;
164 
165  // outputs
166  int _transform_output;
167  int _velocity_output;
168 
169  CPT(TransformState) _transform;
170  PT(EventStoreVec3) _velocity;
171 
172  // This is the smallest meaningful value we can set on the hpr via
173  // the public set_hpr() interface. It's intended to filter out
174  // small meaningless perturbations of hpr that may get introduced
175  // due to numerical inaccuracy as we compute relative orientations
176  // in the show.
177  static const PN_stdfloat _hpr_quantize;
178 
179 public:
180  static TypeHandle get_class_type() {
181  return _type_handle;
182  }
183  static void init_type() {
184  MouseInterfaceNode::init_type();
185  register_type(_type_handle, "DriveInterface",
186  MouseInterfaceNode::get_class_type());
187  }
188  virtual TypeHandle get_type() const {
189  return get_class_type();
190  }
191  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
192 
193 private:
194  static TypeHandle _type_handle;
195 };
196 
197 #include "driveInterface.I"
198 
199 #endif
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
This is a TFormer, similar to Trackball, that moves around a transform matrix in response to mouse in...
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
A handy class object for storing simple values (like integers or strings) passed along with an Event ...
Definition: paramValue.h:109
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
This is the base class for some classes that monitor the mouse and keyboard input and perform some ac...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
Encapsulates the data generated from (or sent into) any particular DataNode.
This object supervises the traversal of the data graph and the moving of data from one DataNode to it...