Developer Documentation
TranslationManipulatorNode.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 TranslationManipulatorNode
56 //
57 //=============================================================================
58 
59 
60 #ifndef ACG_TRANSLATIONMANIPULATOR_NODE_HH
61 #define ACG_TRANSLATIONMANIPULATOR_NODE_HH
62 
63 
64 //== INCLUDES =================================================================
65 
66 // GMU
67 #include "BaseNode.hh"
68 #include "TransformNode.hh"
69 
70 // Qt
71 #include <QEvent>
72 #include <QMouseEvent>
73 
74 #include <ACG/GL/GLPrimitives.hh>
75 
76 
77 //== NAMESPACES ===============================================================
78 
79 namespace ACG {
80 namespace SceneGraph {
81 
82 
83 //== CLASS DEFINITION =========================================================
84 
85 
90 class ACGDLLEXPORT TranslationManipulatorNode : public TransformNode
91 {
92 public:
93 
94  enum AutoSizeMode {
95  Never,
96  Once,
97  Always
98  };
99 
109  Rotation,
110  TranslationRotation,
111  LocalRotation,
112  Resize,
113  Place
114  };
115 
122  X_AXIS = 1,
123  Y_AXIS = 1 << 1,
124  Z_AXIS = 1 << 2,
125  ALL_AXIS = X_AXIS | Y_AXIS | Z_AXIS
126  };
127 
130  const std::string& _name="<TranslationTranslationManipulatorNode>" );
131 
134 
135 
137  ACG_CLASSNAME(TranslationManipulatorNode);
138 
139 
140  //
141  // METHODS
142  //
143 
144  virtual void setIdentity();
145 
147  void set_draw_cylinder(bool _b) { draw_manipulator_ = _b; }
148 
150  bool draw_manipulator() const { return draw_manipulator_; }
151 
153  void set_direction(const Vec3d& _directionX, const Vec3d& _directionY);
154 
156  Vec3d directionX() const;
158  Vec3d directionY() const;
160  Vec3d directionZ() const;
161 
163  void set_size( double _size) {
164  if (_size > 0.0)
165  {
166  set_manipulator_height_ = _size;
167  set_manipulator_radius_ = _size/10.0;
168  setDirty ();
169  }
170  }
171 
173  double size() const { return set_manipulator_height_; }
174 
176  void set_autosize (AutoSizeMode _mode) { auto_size_ = _mode; }
177 
179  AutoSizeMode autosize () const { return auto_size_; }
180 
189  activeRotations_ = _active;
190  }
191 
198  return activeRotations_;
199  }
200 
201  void rotate (double _angle, Vec3d _axis)
202  {
203  TransformNode::rotate(_angle, _axis);
204  }
205 
207  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
208 
210  void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
211 
213  GLMatrixd computeWorldMatrix();
214 
216  // void leave(GLState& _state, const DrawModes::DrawMode& _drawMode);
217 
219  void pick(GLState& _state, PickTarget _target);
220 
222  virtual void mouseEvent(GLState& _state, QMouseEvent* _event);
223 
225  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
226 
228  void setMode (ManipulatorMode _mode);
229 
231  ManipulatorMode getMode () const { return mode_; };
232 
233 
234 protected:
236  bool touched_;
237 
238 private:
239 
240  enum StateUpdates {
241  None,
242  Over,
243  Click
244  };
245 
246  enum Elements {
247  Origin = 0,
248  XTop,
249  YTop,
250  ZTop,
251  XAxis,
252  YAxis,
253  ZAxis,
254  XRing,
255  YRing,
256  ZRing,
257  NumElements
258  };
259 
260  class Element {
261  public:
262  Element ();
263 
264  Vec4f active_target_color_;
265  Vec4f active_current_color_;
266  Vec4f inactive_target_color_;
267  Vec4f inactive_current_color_;
268 
269  bool clicked_;
270  bool over_;
271  };
272 
274  void update_manipulator_system(GLState& _state);
275 
277  void update_rotation(GLState& _state);
278 
279  bool hitSphere(GLState& _state, const Vec2i& _v2);
280  bool hitOuterSphere(GLState& _state, const Vec2i& _v2);
281 
282  void drawManipulator (GLState& _state, bool _active);
283 
284  void addManipulatorToRenderer (IRenderer* _renderer, RenderObject* _baseRO, bool _active);
285  void addAxisToRenderer (IRenderer* _renderer, RenderObject* _baseRO, bool _active, int _axis);
286 
287 
288  bool mapToCylinder (GLState& _state, const Vec2i& _v2, StateUpdates _updateStates = None);
289  bool mapToCylinderTop (GLState& _state, const Vec2i& _v2, StateUpdates _updateStates = None);
290 
291  bool mapToSphere (GLState& _state, const Vec2i& _v2, Vec3d& _v3, StateUpdates _updateStates = None);
292 
293  void updateTargetColors ();
294  bool updateCurrentColors (GLState& _state);
295 
296  double get_screen_length (GLState& _state, Vec3d& _point) const;
297 
298  void updateSize (GLState& _state);
299 
300  // ELEMENTS
301  bool draw_manipulator_;
302 
303  Vec3d dirX_;
304  Vec3d dirY_;
305  Vec3d dirZ_;
306 
307  ACG::GLCone* axisBottom_; // axis split up for deferred draw call rendering,
308  ACG::GLCone* axisCenter_; // cone vbo data must be consistent within one frame
309  ACG::GLCone* axisTop_;
310  ACG::GLDisk* circle_;
311  ACG::GLSphere* sphere_;
312 
313  double manipulator_radius_;
314  double manipulator_height_;
315  double set_manipulator_radius_;
316  double set_manipulator_height_;
317  int manipulator_slices_;
318  int manipulator_stacks_;
319 
320  bool any_axis_clicked_;
321  bool any_top_clicked_;
322  bool outer_ring_clicked_;
323 
324  bool any_axis_over_;
325  bool any_top_over_;
326  bool outer_ring_over_;
327 
328 
329  Element element_[NumElements];
330  float resize_current_;
331 
332  ManipulatorMode mode_;
333  bool ignoreTime_;
334 
335  Vec2i oldPoint2D_;
336  Vec3d draggingOrigin3D_;
337  bool dragging_;
338 
339  Vec3d currentScale_;
340 
341  GLMatrixd localTransformation_;
342 
343  AutoSizeMode auto_size_;
344  double auto_size_length_;
345 
346  ActiveRotations activeRotations_;
347 };
348 
349 
350 //=============================================================================
351 } // namespace SceneGraph
352 } // namespace ACG
353 //=============================================================================
354 #endif // ACG_TRANSLATIONMANIPULATOR_NODE_HH defined
355 //=============================================================================
356 
void enable_rotations(ActiveRotations _active)
Enable or disable manipulator handles for specific orientations.
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
ActiveRotations
enum to define which rotation axis should be enabled
Clear all attribute bits.
Definition: Attributes.hh:86
ManipulatorMode
enum to define the manipulator mode
bool touched_
stores if this manipulator was used in order to avoid emitting manipulatorMoved unnecessarily ...
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
AutoSizeMode autosize() const
get autosize mode
void rotate(double _angle, const Vec3d &_axis)
void set_size(double _size)
set cylindersize (height + radius). _size parameter has to be greater than zero
Interface class between scenegraph and renderer.
ActiveRotations enabled_rotations() const
Get the current setting, which rotation handles are active.
void set_autosize(AutoSizeMode _mode)
set auto size mode