Panda3D

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