Developer Documentation
ManipulatorNode.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 
45 
46 
47 //=============================================================================
48 //
49 // CLASS ManipulatorNode
50 //
51 //=============================================================================
52 
53 
54 #ifndef ACG_MANIPULATOR_NODE_HH
55 #define ACG_MANIPULATOR_NODE_HH
56 
57 
58 //== INCLUDES =================================================================
59 
60 // GMU
61 #include "BaseNode.hh"
62 #include "TransformNode.hh"
63 #include <ACG/GL/GLPrimitives.hh>
64 
65 // Qt
66 #include <QEvent>
67 #include <QMouseEvent>
68 
69 
70 
71 
72 //== NAMESPACES ===============================================================
73 
74 namespace ACG {
75 namespace SceneGraph {
76 
77 
78 //== CLASS DEFINITION =========================================================
79 
80 
86 class ACGDLLEXPORT ManipulatorNode : public TransformNode
87 {
88 public:
89 
90 
92  ManipulatorNode( BaseNode* _parent=0,
93  const std::string& _name="<ManipulatorNode>" );
94 
96  ~ManipulatorNode();
97 
98 
100  ACG_CLASSNAME(ManipulatorNode);
101 
102 
103  //
104  // METHODS
105  //
106 
107 
108 
109  virtual void setIdentity() override;
110 
112  void set_draw_cylinder(bool _b) { draw_cylinder_ = _b; }
113 
115  bool draw_cylinder() const { return draw_cylinder_; }
116 
119  void set_direction(Vec3d& _v);
120 
123  Vec3d direction() const;
124 
126  void set_size( double _size) { cylinder_height_ = _size;
127  cylinder_radius_ = _size/10.0;}
128 
130  double size() const { return cylinder_height_; }
131 
133  void translate(double _s) {
134  Vec3d rel_dir = rotation().transform_vector(direction_);
135  TransformNode::translate(_s * rel_dir);
136  }
137 
139  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode) override;
140 
142  void pick(GLState& _state, PickTarget _target) override;
143 
145  virtual void mouseEvent(GLState& _state, QMouseEvent* _event) override;
146 
150  bool touched() { return touched_; };
151 
153  void reset_touched() { touched_ = false; };
154 
155 
156 private:
157 
158  void setup_sphere_system(GLState& _state);
159  void setup_cylinder_system(GLState& _state);
160 
161  bool mapToSphere(GLState& _state, const Vec2i& _v2, Vec3d& _v3);
162  bool hitSphere(GLState& _state, const Vec2i& _v2);
163  bool mapToCylinder (GLState& _state, const Vec2i& _v2, double& axis_hit);
164 
165 
166 
167 
168 
169  // ELEMENTS
170  bool draw_cylinder_;
171 
172  Vec3d direction_;
173  GLCylinder* cylinder_;
174  double cylinder_radius_;
175  double cylinder_height_;
176  int cylinder_slices_;
177  int cylinder_stacks_;
178 
179 
180  bool cylinder_clicked_;
181  bool sphere_clicked_;
182 
183  Vec2i oldPoint2D_;
184 
186  bool touched_;
187 };
188 
189 
190 //=============================================================================
191 } // namespace SceneGraph
192 } // namespace ACG
193 //=============================================================================
194 #endif // ACG_MANIPUKATOR_NODE_HH defined
195 //=============================================================================
196 
void translate(const Vec3d &_v)
Add a translation to the current Transformation.
bool touched_
if the manipulator is cklicked with a mouse, this flag will be set to true
Namespace providing different geometric functions concerning angles.
void reset_touched()
Reset the touched flag ( see touched for details )
bool draw_cylinder() const
get drawCylinder
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
void set_draw_cylinder(bool _b)
set draw_cylinder_
double size() const
get cylindersize
void translate(double _s)
translate in cylinder direction
void set_size(double _size)
set cylindersize (height + radius)