Panda3D

trackball.h

00001 // Filename: trackball.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 TRACKBALL_H
00016 #define TRACKBALL_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "mouseInterfaceNode.h"
00021 #include "nodePath.h"
00022 #include "modifierButtons.h"
00023 #include "luse.h"
00024 #include "transformState.h"
00025 
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : Trackball
00029 // Description : Trackball acts like Performer in trackball mode.  It
00030 //               can either spin around a piece of geometry directly,
00031 //               or it can spin around a camera with the inverse
00032 //               transform to make it appear that the whole world is
00033 //               spinning.
00034 //
00035 //               The Trackball object actually just places a transform
00036 //               in the data graph; parent a Transform2SG node under
00037 //               it to actually transform objects (or cameras) in the
00038 //               world.
00039 ////////////////////////////////////////////////////////////////////
00040 class EXPCL_PANDA_TFORM Trackball : public MouseInterfaceNode {
00041 PUBLISHED:
00042   Trackball(const string &name);
00043   ~Trackball();
00044 
00045   void reset();
00046 
00047   PN_stdfloat get_forward_scale() const;
00048   void set_forward_scale(PN_stdfloat fwdscale);
00049 
00050   /// **** Translation ****
00051 
00052   const LPoint3 &get_pos() const;
00053   PN_stdfloat get_x() const;
00054   PN_stdfloat get_y() const;
00055   PN_stdfloat get_z() const;
00056   void set_pos(const LVecBase3 &vec);
00057   void set_pos(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
00058   void set_x(PN_stdfloat x);
00059   void set_y(PN_stdfloat y);
00060   void set_z(PN_stdfloat z);
00061 
00062   /// **** Rotation ****
00063 
00064   LVecBase3 get_hpr() const;
00065   PN_stdfloat get_h() const;
00066   PN_stdfloat get_p() const;
00067   PN_stdfloat get_r() const;
00068   void set_hpr(const LVecBase3 &hpr);
00069   void set_hpr(PN_stdfloat h, PN_stdfloat p, PN_stdfloat r);
00070   void set_h(PN_stdfloat h);
00071   void set_p(PN_stdfloat p);
00072   void set_r(PN_stdfloat r);
00073 
00074   /// **** Origin of Rotation ****
00075 
00076   void reset_origin_here();
00077   void move_origin(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
00078 
00079   LPoint3 get_origin() const;
00080   void set_origin(const LVecBase3 &origin);
00081 
00082   /// **** Misc ****
00083 
00084   enum ControlMode {
00085     CM_default,
00086     CM_truck,  // Normally mouse 1
00087     CM_pan,    // Normally mouse 2
00088     CM_dolly,  // Normally mouse 3
00089     CM_roll,   // Normally mouse 2 + 3
00090   };
00091 
00092   void set_control_mode(ControlMode control_mode);
00093   ControlMode get_control_mode() const;
00094 
00095   void set_invert(bool flag);
00096   bool get_invert() const;
00097 
00098   void set_rel_to(const NodePath &rel_to);
00099   const NodePath &get_rel_to() const;
00100 
00101   void set_coordinate_system(CoordinateSystem cs);
00102   CoordinateSystem get_coordinate_system() const;
00103 
00104   void set_mat(const LMatrix4 &mat);
00105   const LMatrix4 &get_mat() const;
00106   const LMatrix4 &get_trans_mat() const;
00107 
00108 
00109 private:
00110   void apply(double x, double y, int button);
00111 
00112   void reextract();
00113   void recompute();
00114 
00115   int _last_button;
00116   PN_stdfloat _lastx, _lasty;
00117 
00118   PN_stdfloat _rotscale;
00119   PN_stdfloat _fwdscale;
00120 
00121   LMatrix4 _rotation;
00122   LPoint3 _translation;
00123   LMatrix4 _mat, _orig;
00124   bool _invert;
00125   NodePath _rel_to;
00126   CoordinateSystem _cs;
00127   ControlMode _control_mode;
00128 
00129 protected:
00130   // Inherited from DataNode
00131   virtual void do_transmit_data(DataGraphTraverser *trav,
00132                                 const DataNodeTransmit &input,
00133                                 DataNodeTransmit &output);
00134 
00135 private:
00136   // inputs
00137   int _pixel_xy_input;
00138 
00139   // outputs
00140   int _transform_output;
00141 
00142   CPT(TransformState) _transform;
00143 
00144 public:
00145   static TypeHandle get_class_type() {
00146     return _type_handle;
00147   }
00148   static void init_type() {
00149     MouseInterfaceNode::init_type();
00150     register_type(_type_handle, "Trackball",
00151                   MouseInterfaceNode::get_class_type());
00152   }
00153   virtual TypeHandle get_type() const {
00154     return get_class_type();
00155   }
00156   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00157 
00158 private:
00159   static TypeHandle _type_handle;
00160 };
00161 
00162 #endif
 All Classes Functions Variables Enumerations