Panda3D
trackball.h
1 // Filename: trackball.h
2 // Created by: drose (12Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef TRACKBALL_H
16 #define TRACKBALL_H
17 
18 #include "pandabase.h"
19 
20 #include "mouseInterfaceNode.h"
21 #include "nodePath.h"
22 #include "modifierButtons.h"
23 #include "luse.h"
24 #include "transformState.h"
25 
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : Trackball
29 // Description : Trackball acts like Performer in trackball mode. It
30 // can either spin around a piece of geometry directly,
31 // or it can spin around a camera with the inverse
32 // transform to make it appear that the whole world is
33 // spinning.
34 //
35 // The Trackball object actually just places a transform
36 // in the data graph; parent a Transform2SG node under
37 // it to actually transform objects (or cameras) in the
38 // world.
39 ////////////////////////////////////////////////////////////////////
40 class EXPCL_PANDA_TFORM Trackball : public MouseInterfaceNode {
41 PUBLISHED:
42  Trackball(const string &name);
43  ~Trackball();
44 
45  void reset();
46 
47  PN_stdfloat get_forward_scale() const;
48  void set_forward_scale(PN_stdfloat fwdscale);
49 
50  /// **** Translation ****
51 
52  const LPoint3 &get_pos() const;
53  PN_stdfloat get_x() const;
54  PN_stdfloat get_y() const;
55  PN_stdfloat get_z() const;
56  void set_pos(const LVecBase3 &vec);
57  void set_pos(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
58  void set_x(PN_stdfloat x);
59  void set_y(PN_stdfloat y);
60  void set_z(PN_stdfloat z);
61 
62  /// **** Rotation ****
63 
64  LVecBase3 get_hpr() const;
65  PN_stdfloat get_h() const;
66  PN_stdfloat get_p() const;
67  PN_stdfloat get_r() const;
68  void set_hpr(const LVecBase3 &hpr);
69  void set_hpr(PN_stdfloat h, PN_stdfloat p, PN_stdfloat r);
70  void set_h(PN_stdfloat h);
71  void set_p(PN_stdfloat p);
72  void set_r(PN_stdfloat r);
73 
74  /// **** Origin of Rotation ****
75 
76  void reset_origin_here();
77  void move_origin(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
78 
79  LPoint3 get_origin() const;
80  void set_origin(const LVecBase3 &origin);
81 
82  /// **** Misc ****
83 
84  enum ControlMode {
85  CM_default,
86  CM_truck, // Normally mouse 1
87  CM_pan, // Normally mouse 2
88  CM_dolly, // Normally mouse 3
89  CM_roll, // Normally mouse 2 + 3
90  };
91 
92  void set_control_mode(ControlMode control_mode);
93  ControlMode get_control_mode() const;
94 
95  void set_invert(bool flag);
96  bool get_invert() const;
97 
98  void set_rel_to(const NodePath &rel_to);
99  const NodePath &get_rel_to() const;
100 
101  void set_coordinate_system(CoordinateSystem cs);
102  CoordinateSystem get_coordinate_system() const;
103 
104  void set_mat(const LMatrix4 &mat);
105  const LMatrix4 &get_mat() const;
106  const LMatrix4 &get_trans_mat() const;
107 
108 
109 private:
110  void apply(double x, double y, int button);
111 
112  void reextract();
113  void recompute();
114 
115  int _last_button;
116  PN_stdfloat _lastx, _lasty;
117 
118  PN_stdfloat _rotscale;
119  PN_stdfloat _fwdscale;
120 
121  LMatrix4 _rotation;
122  LPoint3 _translation;
123  LMatrix4 _mat, _orig;
124  bool _invert;
125  NodePath _rel_to;
126  CoordinateSystem _cs;
127  ControlMode _control_mode;
128 
129 protected:
130  // Inherited from DataNode
131  virtual void do_transmit_data(DataGraphTraverser *trav,
132  const DataNodeTransmit &input,
133  DataNodeTransmit &output);
134 
135 private:
136  // inputs
137  int _pixel_xy_input;
138 
139  // outputs
140  int _transform_output;
141 
142  CPT(TransformState) _transform;
143 
144 public:
145  static TypeHandle get_class_type() {
146  return _type_handle;
147  }
148  static void init_type() {
149  MouseInterfaceNode::init_type();
150  register_type(_type_handle, "Trackball",
151  MouseInterfaceNode::get_class_type());
152  }
153  virtual TypeHandle get_type() const {
154  return get_class_type();
155  }
156  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
157 
158 private:
159  static TypeHandle _type_handle;
160 };
161 
162 #endif
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
Trackball acts like Performer in trackball mode.
Definition: trackball.h:40
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
ControlMode
**** Misc ****
Definition: trackball.h:84
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
This is the base class for some classes that monitor the mouse and keyboard input and perform some ac...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
Encapsulates the data generated from (or sent into) any particular DataNode.
This object supervises the traversal of the data graph and the moving of data from one DataNode to it...