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