Panda3D
 All Classes Functions Variables Enumerations
driveInterface.h
00001 // Filename: driveInterface.h
00002 // Created by:  drose (12Mar02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef DRIVEINTERFACE_H
00016 #define DRIVEINTERFACE_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "mouseInterfaceNode.h"
00021 #include "modifierButtons.h"
00022 #include "luse.h"
00023 #include "linmath_events.h"
00024 #include "transformState.h"
00025 
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : DriveInterface
00029 // Description : This is a TFormer, similar to Trackball, that moves
00030 //               around a transform matrix in response to mouse input.
00031 //               The basic motion is on a horizontal plane, as if
00032 //               driving a vehicle.
00033 ////////////////////////////////////////////////////////////////////
00034 class EXPCL_PANDA_TFORM DriveInterface : public MouseInterfaceNode {
00035 PUBLISHED:
00036   DriveInterface(const string &name = "");
00037   ~DriveInterface();
00038 
00039   INLINE void set_forward_speed(PN_stdfloat speed);
00040   INLINE PN_stdfloat get_forward_speed() const;
00041   INLINE void set_reverse_speed(PN_stdfloat speed);
00042   INLINE PN_stdfloat get_reverse_speed() const;
00043   INLINE void set_rotate_speed(PN_stdfloat speed);
00044   INLINE PN_stdfloat get_rotate_speed() const;
00045   INLINE void set_vertical_dead_zone(PN_stdfloat zone);
00046   INLINE PN_stdfloat get_vertical_dead_zone() const;
00047   INLINE void set_horizontal_dead_zone(PN_stdfloat zone);
00048   INLINE PN_stdfloat get_horizontal_dead_zone() const;
00049 
00050   INLINE void set_vertical_ramp_up_time(PN_stdfloat ramp_up_time);
00051   INLINE PN_stdfloat get_vertical_ramp_up_time() const;
00052   INLINE void set_vertical_ramp_down_time(PN_stdfloat ramp_down_time);
00053   INLINE PN_stdfloat get_vertical_ramp_down_time() const;
00054   INLINE void set_horizontal_ramp_up_time(PN_stdfloat ramp_up_time);
00055   INLINE PN_stdfloat get_horizontal_ramp_up_time() const;
00056   INLINE void set_horizontal_ramp_down_time(PN_stdfloat ramp_down_time);
00057   INLINE PN_stdfloat get_horizontal_ramp_down_time() const;
00058 
00059   INLINE PN_stdfloat get_speed() const;
00060   INLINE PN_stdfloat get_rot_speed() const;
00061 
00062   void reset();
00063 
00064   /// **** Translation ****
00065 
00066   INLINE const LPoint3 &get_pos() const;
00067   INLINE PN_stdfloat get_x() const;
00068   INLINE PN_stdfloat get_y() const;
00069   INLINE PN_stdfloat get_z() const;
00070   INLINE void set_pos(const LVecBase3 &vec);
00071   INLINE void set_pos(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
00072   INLINE void set_x(PN_stdfloat x);
00073   INLINE void set_y(PN_stdfloat y);
00074   INLINE void set_z(PN_stdfloat z);
00075 
00076   /// **** Rotation ****
00077 
00078   INLINE const LVecBase3 &get_hpr() const;
00079   INLINE PN_stdfloat get_h() const;
00080   INLINE PN_stdfloat get_p() const;
00081   INLINE PN_stdfloat get_r() const;
00082   INLINE void set_hpr(const LVecBase3 &hpr);
00083   INLINE void set_hpr(PN_stdfloat h, PN_stdfloat p, PN_stdfloat r);
00084   INLINE void set_h(PN_stdfloat h);
00085   INLINE void set_p(PN_stdfloat p);
00086   INLINE void set_r(PN_stdfloat r);
00087 
00088   void set_force_roll(PN_stdfloat force_roll);
00089 
00090   INLINE void set_ignore_mouse(bool ignore_mouse);
00091   INLINE bool get_ignore_mouse() const;
00092 
00093   INLINE void set_force_mouse(bool force_mouse);
00094   INLINE bool get_force_mouse() const;
00095 
00096   INLINE void set_stop_this_frame(bool stop_this_frame);
00097   INLINE bool get_stop_this_frame() const;
00098 
00099   void set_mat(const LMatrix4 &mat);
00100   const LMatrix4 &get_mat();
00101 
00102   void force_dgraph();
00103 
00104 private:
00105   void apply(double x, double y, bool any_button);
00106 
00107   PN_stdfloat _forward_speed;  // units / sec, mouse all the way up
00108   PN_stdfloat _reverse_speed;  // units / sec, mouse all the way down
00109   PN_stdfloat _rotate_speed;   // degrees / sec, mouse all the way over
00110   PN_stdfloat _vertical_dead_zone;    // fraction of window size
00111   PN_stdfloat _horizontal_dead_zone;  // fraction of window size
00112   PN_stdfloat _vertical_center;    // window units, 0 = center, -1 = bottom, 1 = top
00113   PN_stdfloat _horizontal_center;  // window units, 0 = center, -1 = left, 1 = right
00114 
00115   // The time it takes to ramp up to full speed from a stop (or return
00116   // to a stop from full speed) when using the keyboard.
00117   PN_stdfloat _vertical_ramp_up_time;
00118   PN_stdfloat _vertical_ramp_down_time;
00119   PN_stdfloat _horizontal_ramp_up_time;
00120   PN_stdfloat _horizontal_ramp_down_time;
00121 
00122   PN_stdfloat _speed; // instantaneous units / sec
00123   PN_stdfloat _rot_speed; // instantaneous rotational units / sec
00124 
00125   LPoint3 _xyz;
00126   LVecBase3 _hpr;
00127   LVector3 _vel;
00128   bool _ignore_mouse;
00129   bool _force_mouse;
00130   bool _stop_this_frame;
00131 
00132   // This is only used to return a temporary value in get_mat().
00133   LMatrix4 _mat;
00134 
00135   // Remember which arrow keys are being held down and which aren't,
00136   // and at what point they last changed state.
00137   class KeyHeld {
00138   public:
00139     KeyHeld();
00140     PN_stdfloat get_effect(PN_stdfloat ramp_up_time, PN_stdfloat ramp_down_time);
00141     void set_key(bool down);
00142     void clear();
00143     bool operator < (const KeyHeld &other) const;
00144 
00145     PN_stdfloat _effect;
00146     bool _down;
00147     double _changed_time;
00148     PN_stdfloat _effect_at_change;
00149   };
00150   KeyHeld _up_arrow, _down_arrow;
00151   KeyHeld _left_arrow, _right_arrow;
00152 
00153 
00154 protected:
00155   // Inherited from DataNode
00156   virtual void do_transmit_data(DataGraphTraverser *trav,
00157                                 const DataNodeTransmit &input,
00158                                 DataNodeTransmit &output);
00159 
00160 private:
00161   // inputs
00162   int _xy_input;
00163   int _button_events_input;
00164 
00165   // outputs
00166   int _transform_output;
00167   int _velocity_output;
00168 
00169   CPT(TransformState) _transform;
00170   PT(EventStoreVec3) _velocity;
00171 
00172   // This is the smallest meaningful value we can set on the hpr via
00173   // the public set_hpr() interface.  It's intended to filter out
00174   // small meaningless perturbations of hpr that may get introduced
00175   // due to numerical inaccuracy as we compute relative orientations
00176   // in the show.
00177   static const PN_stdfloat _hpr_quantize;
00178 
00179 public:
00180   static TypeHandle get_class_type() {
00181     return _type_handle;
00182   }
00183   static void init_type() {
00184     MouseInterfaceNode::init_type();
00185     register_type(_type_handle, "DriveInterface",
00186                   MouseInterfaceNode::get_class_type());
00187   }
00188   virtual TypeHandle get_type() const {
00189     return get_class_type();
00190   }
00191   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00192 
00193 private:
00194   static TypeHandle _type_handle;
00195 };
00196 
00197 #include "driveInterface.I"
00198 
00199 #endif
 All Classes Functions Variables Enumerations