Panda3D
|
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 float get_forward_scale() const; 00048 void set_forward_scale(float fwdscale); 00049 00050 /// **** Translation **** 00051 00052 const LPoint3f &get_pos() const; 00053 float get_x() const; 00054 float get_y() const; 00055 float get_z() const; 00056 void set_pos(const LVecBase3f &vec); 00057 void set_pos(float x, float y, float z); 00058 void set_x(float x); 00059 void set_y(float y); 00060 void set_z(float z); 00061 00062 /// **** Rotation **** 00063 00064 LVecBase3f get_hpr() const; 00065 float get_h() const; 00066 float get_p() const; 00067 float get_r() const; 00068 void set_hpr(const LVecBase3f &hpr); 00069 void set_hpr(float h, float p, float r); 00070 void set_h(float h); 00071 void set_p(float p); 00072 void set_r(float r); 00073 00074 /// **** Origin of Rotation **** 00075 00076 void reset_origin_here(); 00077 void move_origin(float x, float y, float z); 00078 00079 LPoint3f get_origin() const; 00080 void set_origin(const LVecBase3f &origin); 00081 00082 /// **** Misc **** 00083 00084 void set_invert(bool flag); 00085 bool get_invert() const; 00086 00087 void set_rel_to(const NodePath &rel_to); 00088 const NodePath &get_rel_to() const; 00089 00090 void set_coordinate_system(CoordinateSystem cs); 00091 CoordinateSystem get_coordinate_system() const; 00092 00093 void set_mat(const LMatrix4f &mat); 00094 const LMatrix4f &get_mat() const; 00095 const LMatrix4f &get_trans_mat() const; 00096 00097 00098 private: 00099 void apply(double x, double y, int button); 00100 00101 void reextract(); 00102 void recompute(); 00103 00104 int _last_button; 00105 float _lastx, _lasty; 00106 00107 float _rotscale; 00108 float _fwdscale; 00109 00110 LMatrix4f _rotation; 00111 LPoint3f _translation; 00112 LMatrix4f _mat, _orig; 00113 bool _invert; 00114 NodePath _rel_to; 00115 CoordinateSystem _cs; 00116 00117 protected: 00118 // Inherited from DataNode 00119 virtual void do_transmit_data(DataGraphTraverser *trav, 00120 const DataNodeTransmit &input, 00121 DataNodeTransmit &output); 00122 00123 private: 00124 // inputs 00125 int _pixel_xy_input; 00126 00127 // outputs 00128 int _transform_output; 00129 00130 CPT(TransformState) _transform; 00131 00132 public: 00133 static TypeHandle get_class_type() { 00134 return _type_handle; 00135 } 00136 static void init_type() { 00137 MouseInterfaceNode::init_type(); 00138 register_type(_type_handle, "Trackball", 00139 MouseInterfaceNode::get_class_type()); 00140 } 00141 virtual TypeHandle get_type() const { 00142 return get_class_type(); 00143 } 00144 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00145 00146 private: 00147 static TypeHandle _type_handle; 00148 }; 00149 00150 #endif