Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TrackballNode.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS TrackballNode
56 //
57 //=============================================================================
58 
59 
60 #ifndef ACG_TRACKBALL_NODE_HH
61 #define ACG_TRACKBALL_NODE_HH
62 
63 
64 //== INCLUDES =================================================================
65 
66 // GMU
67 #include "BaseNode.hh"
68 #include "TransformNode.hh"
69 
70 #include <vector>
71 
72 // Qt
73 #include <QEvent>
74 #include <QMouseEvent>
75 
76 #ifdef max
77 # undef max
78 #endif
79 
80 #ifdef min
81 # undef min
82 #endif
83 
84 
85 
86 //== NAMESPACES ===============================================================
87 
88 
89 namespace ACG {
90 namespace SceneGraph {
91 
92 
93 //== CLASS DEFINITION =========================================================
94 
95 
104 class ACGDLLEXPORT TrackballNode : public TransformNode
105 {
106 public:
107 
108 
110  TrackballNode( BaseNode* _parent=0,
111  const std::string& _name="<TrackballNode>" )
112  : TransformNode(_parent, _name),
113  drawTrackball_(false),
114  drawAxes_(false),
115  radius_(1.0),
116  xAxis_(1.0, 0.0, 0.0),
117  yAxis_(0.0, 1.0, 0.0),
118  zAxis_(0.0, 0.0, 1.0)
119  {}
120 
121 
124 
125 
127  ACG_CLASSNAME(TrackballNode);
128 
129 
130  //
131  // METHODS
132  //
133 
134 
136  void set_radius(double _r) { radius_ = _r; }
138  double radius() const { return radius_; }
139 
140 
142  virtual void setIdentity() {
143  Vec3d vec (1.0, 1.0, 1.0);
144 
145  vec = scale ().transform_point(vec);
146  radius_ *= vec.max ();
148  }
149 
150 
152  void set_draw_trackball(bool _b) { drawTrackball_ = _b; }
154  bool draw_trackball() const { return drawTrackball_; }
155 
156 
158  void set_draw_axes(bool _b) { drawAxes_ = _b; }
160  bool draw_axes() const { return drawAxes_; }
161 
162 
164  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
165 
166 
168  virtual void mouseEvent(GLState& _state, QMouseEvent* _event);
169 
170 
171 private:
172 
174  bool mapToSphere(GLState& _state, const Vec2i& _v2, Vec3d& _v3);
175 
176 
177  // ELEMENTS
178  bool drawTrackball_,
179  drawAxes_;
180  double radius_;
181  Vec3d xAxis_, yAxis_, zAxis_;
182  Vec2i oldPoint2D_;
183 };
184 
185 
186 //=============================================================================
187 } // namespace SceneGraph
188 } // namespace ACG
189 //=============================================================================
190 #endif // ACG_TRACKBALL_NODE_HH defined
191 //=============================================================================
192 
double radius() const
Get trackball radius.
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
void set_draw_axes(bool _b)
Turn drawing the axes on/off.
void set_draw_trackball(bool _b)
Turn on/off drawing of the trackball.
virtual void setIdentity()
override TransformNode::setIdentity() (update radius_)
void set_radius(double _r)
Set trackball radius.
bool draw_trackball() const
Is trackball-drawing on?
bool draw_axes() const
Is axes-drawing on?
TrackballNode(BaseNode *_parent=0, const std::string &_name="<TrackballNode>")
Default constructor.