00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
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
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
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
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
00083
00084 enum ControlMode {
00085 CM_default,
00086 CM_truck,
00087 CM_pan,
00088 CM_dolly,
00089 CM_roll,
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
00131 virtual void do_transmit_data(DataGraphTraverser *trav,
00132 const DataNodeTransmit &input,
00133 DataNodeTransmit &output);
00134
00135 private:
00136
00137 int _pixel_xy_input;
00138
00139
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