Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/tform/driveInterface.h

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

Generated on Fri May 2 00:44:26 2003 for Panda by doxygen1.3