Panda3D

Loading...
Searching...
No Matches
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 {
32PUBLISHED:
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
DataGraphTraverser
This object supervises the traversal of the data graph and the moving of data from one DataNode to it...
Definition dataGraphTraverser.h:32
DataNodeTransmit
Encapsulates the data generated from (or sent into) any particular DataNode.
Definition dataNodeTransmit.h:32
DriveInterface::get_rotate_speed
PN_stdfloat get_rotate_speed() const
Returns the maximum rate at which the user can rotate left or right, when the mouse is at the very ed...
Definition driveInterface.I:65
DriveInterface::set_rotate_speed
void set_rotate_speed(PN_stdfloat speed)
Sets the maximum rate at which the user can rotate left or right, when the mouse is at the very edge ...
Definition driveInterface.I:55
DriveInterface::get_horizontal_ramp_up_time
PN_stdfloat get_horizontal_ramp_up_time() const
Returns the amount of time, in seconds, it takes between the time a left or right arrow key is presse...
Definition driveInterface.I:165
DriveInterface::set_vertical_dead_zone
void set_vertical_dead_zone(PN_stdfloat zone)
Sets the size of the horizontal bar in the center of the screen that represents the "dead zone" of ve...
Definition driveInterface.I:76
DriveInterface::get_mat
const LMatrix4 & get_mat()
Returns the current transform.
Definition driveInterface.cxx:183
DriveInterface::set_mat
void set_mat(const LMatrix4 &mat)
Stores the indicated transform in the DriveInterface.
Definition driveInterface.cxx:174
DriveInterface::set_force_roll
void set_force_roll(PN_stdfloat force_roll)
This function is no longer used and does nothing.
Definition driveInterface.cxx:167
DriveInterface::get_horizontal_dead_zone
PN_stdfloat get_horizontal_dead_zone() const
Returns the size of the vertical bar in the center of the screen that represents the "dead zone" of h...
Definition driveInterface.I:109
DriveInterface::get_speed
PN_stdfloat get_speed() const
Returns the speed of the previous update in units/sec.
Definition driveInterface.I:191
DriveInterface::get_horizontal_ramp_down_time
PN_stdfloat get_horizontal_ramp_down_time() const
Returns the amount of time, in seconds, it takes between the time a left or right arrow key is releas...
Definition driveInterface.I:183
DriveInterface::get_ignore_mouse
bool get_ignore_mouse() const
Returns the current setting of the ignore_mouse flag.
Definition driveInterface.I:328
DriveInterface::reset
void reset()
Reinitializes the driver to the origin and resets any knowledge about buttons being held down.
Definition driveInterface.cxx:153
DriveInterface::get_vertical_ramp_down_time
PN_stdfloat get_vertical_ramp_down_time() const
Returns the amount of time, in seconds, it takes between the time an up or down arrow key is released...
Definition driveInterface.I:147
DriveInterface::set_pos
void set_pos(const LVecBase3 &vec)
Directly sets the driver's position.
Definition driveInterface.I:231
DriveInterface::get_stop_this_frame
bool get_stop_this_frame() const
Returns the current setting of the stop_this_frame flag.
Definition driveInterface.I:367
DriveInterface::get_hpr
const LVecBase3 & get_hpr() const
Returns the driver's orientation.
Definition driveInterface.I:260
DriveInterface::set_reverse_speed
void set_reverse_speed(PN_stdfloat speed)
Sets the speed of full reverse motion, when the mouse is at the very bottom of the window.
Definition driveInterface.I:37
DriveInterface::set_vertical_ramp_down_time
void set_vertical_ramp_down_time(PN_stdfloat ramp_down_time)
Sets the amount of time, in seconds, it takes between the time an up or down arrow key is released an...
Definition driveInterface.I:138
DriveInterface::set_force_mouse
void set_force_mouse(bool force_mouse)
Changes the state of the force_mouse flag.
Definition driveInterface.I:337
DriveInterface::get_forward_speed
PN_stdfloat get_forward_speed() const
Returns the speed of full forward motion, when the mouse is at the very top of the window.
Definition driveInterface.I:28
DriveInterface::set_ignore_mouse
void set_ignore_mouse(bool ignore_mouse)
Changes the state of the ignore_mouse flag.
Definition driveInterface.I:319
DriveInterface::set_horizontal_dead_zone
void set_horizontal_dead_zone(PN_stdfloat zone)
Sets the size of the vertical bar in the center of the screen that represents the "dead zone" of hori...
Definition driveInterface.I:98
DriveInterface::set_forward_speed
void set_forward_speed(PN_stdfloat speed)
Sets the speed of full forward motion, when the mouse is at the very top of the window.
Definition driveInterface.I:19
DriveInterface::set_horizontal_ramp_up_time
void set_horizontal_ramp_up_time(PN_stdfloat ramp_up_time)
Sets the amount of time, in seconds, it takes between the time a left or right arrow key is pressed a...
Definition driveInterface.I:156
DriveInterface::set_vertical_ramp_up_time
void set_vertical_ramp_up_time(PN_stdfloat ramp_up_time)
Sets the amount of time, in seconds, it takes between the time an up or down arrow key is pressed and...
Definition driveInterface.I:119
DriveInterface::get_rot_speed
PN_stdfloat get_rot_speed() const
Returns the rot_speed of the previous update in units/sec.
Definition driveInterface.I:199
DriveInterface::get_vertical_dead_zone
PN_stdfloat get_vertical_dead_zone() const
Returns the size of the horizontal bar in the center of the screen that represents the "dead zone" of...
Definition driveInterface.I:87
DriveInterface::force_dgraph
void force_dgraph()
This is a special kludge for DriveInterface to allow us to avoid the one- frame latency after a colli...
Definition driveInterface.cxx:198
DriveInterface::get_reverse_speed
PN_stdfloat get_reverse_speed() const
Returns the speed of full reverse motion, when the mouse is at the very bottom of the window.
Definition driveInterface.I:46
DriveInterface::set_horizontal_ramp_down_time
void set_horizontal_ramp_down_time(PN_stdfloat ramp_down_time)
Sets the amount of time, in seconds, it takes between the time a left or right arrow key is released ...
Definition driveInterface.I:174
DriveInterface::get_vertical_ramp_up_time
PN_stdfloat get_vertical_ramp_up_time() const
Returns the amount of time, in seconds, it takes between the time an up or down arrow key is pressed ...
Definition driveInterface.I:129
DriveInterface::get_pos
const LPoint3 & get_pos() const
Returns the driver's position.
Definition driveInterface.I:207
DriveInterface::set_stop_this_frame
void set_stop_this_frame(bool stop_this_frame)
If stop_this_frame is true, the next time the frame is computed no motion will be allowed,...
Definition driveInterface.I:358
DriveInterface::get_force_mouse
bool get_force_mouse() const
Returns the current setting of the force_mouse flag.
Definition driveInterface.I:346
DriveInterface::set_hpr
void set_hpr(const LVecBase3 &hpr)
Directly sets the driver's orientation.
Definition driveInterface.I:284
TransformState
Indicates a coordinate-system transform on vertices.
Definition transformState.h:54
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
driveInterface.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
linmath_events.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
luse.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
modifierButtons.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
mouseInterfaceNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
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
transformState.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.