Panda3D

Loading...
Searching...
No Matches
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 {
36PUBLISHED:
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
Trackball::reset
void reset()
Reinitializes all transforms to identity.
Definition trackball.cxx:85
Trackball::get_mat
const LMatrix4 & get_mat() const
Returns the matrix represented by the trackball rotation.
Definition trackball.cxx:388
Trackball::get_trans_mat
const LMatrix4 & get_trans_mat() const
Returns the actual transform that will be applied to the scene graph.
Definition trackball.cxx:397
Trackball::set_control_mode
void set_control_mode(ControlMode control_mode)
Sets the control mode.
Definition trackball.cxx:315
Trackball::set_hpr
void set_hpr(const LVecBase3 &hpr)
Directly set the mover's orientation.
Definition trackball.cxx:206
Trackball::get_hpr
LVecBase3 get_hpr() const
Return the trackball's orientation.
Definition trackball.cxx:174
Trackball::get_pos
const LPoint3 & get_pos() const
Return the offset from the center of rotation.
Definition trackball.cxx:116
Trackball::get_invert
bool get_invert() const
Returns the invert flag.
Definition trackball.cxx:303
Trackball::set_origin
void set_origin(const LVecBase3 &origin)
Directly sets the center of rotation.
Definition trackball.cxx:282
Trackball::get_forward_scale
PN_stdfloat get_forward_scale() const
Returns the scale factor applied to forward and backward motion.
Definition trackball.cxx:97
Trackball::get_coordinate_system
CoordinateSystem get_coordinate_system() const
Returns the coordinate system of the Trackball.
Definition trackball.cxx:363
Trackball::move_origin
void move_origin(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Moves the center of rotation by the given amount.
Definition trackball.cxx:266
Trackball::reset_origin_here
void reset_origin_here()
Reposition the center of rotation to coincide with the current translation offset.
Definition trackball.cxx:255
Trackball::set_coordinate_system
void set_coordinate_system(CoordinateSystem cs)
Sets the coordinate system of the Trackball.
Definition trackball.cxx:354
Trackball::set_invert
void set_invert(bool flag)
Sets the invert flag.
Definition trackball.cxx:293
Trackball::get_origin
LPoint3 get_origin() const
Returns the current center of rotation.
Definition trackball.cxx:274
Trackball::set_rel_to
void set_rel_to(const NodePath &rel_to)
Sets the NodePath that all trackball manipulations are to be assumed to be relative to.
Definition trackball.cxx:334
Trackball::set_mat
void set_mat(const LMatrix4 &mat)
Stores the indicated transform in the trackball.
Definition trackball.cxx:372
Trackball::set_pos
void set_pos(const LVecBase3 &vec)
Directly set the offset from the rotational origin.
Definition trackball.cxx:140
Trackball::get_rel_to
const NodePath & get_rel_to() const
Returns the NodePath that all trackball manipulations are relative to, or the empty path.
Definition trackball.cxx:343
Trackball::get_control_mode
ControlMode get_control_mode() const
Returns the control mode.
Definition trackball.cxx:323
Trackball::set_forward_scale
void set_forward_scale(PN_stdfloat fwdscale)
Changes the scale factor applied to forward and backward motion.
Definition trackball.cxx:107
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.