Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TranslationManipulatorNode.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
5  * www.openflipper.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenFlipper. *
9  * *
10  * OpenFlipper is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenFlipper is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenFlipper. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 14237 $ *
38  * $Author: moebius $ *
39  * $Date: 2012-03-21 14:30:52 +0100 (Mi, 21 Mär 2012) $ *
40  * *
41 \*===========================================================================*/
42 
43 
44 
45 
46 //=============================================================================
47 //
48 // CLASS TranslationManipulatorNode
49 //
50 //=============================================================================
51 
52 
53 #ifndef ACG_TRANSLATIONMANIPULATOR_NODE_HH
54 #define ACG_TRANSLATIONMANIPULATOR_NODE_HH
55 
56 
57 //== INCLUDES =================================================================
58 
59 // GMU
60 #include "BaseNode.hh"
61 #include "TransformNode.hh"
62 
63 // Qt
64 #include <QEvent>
65 #include <QMouseEvent>
66 
67 #include <ACG/GL/GLPrimitives.hh>
68 
69 
70 //== NAMESPACES ===============================================================
71 
72 namespace ACG {
73 namespace SceneGraph {
74 
75 
76 //== CLASS DEFINITION =========================================================
77 
78 
83 class ACGDLLEXPORT TranslationManipulatorNode : public TransformNode
84 {
85 public:
86 
87  enum AutoSizeMode {
88  Never,
89  Once,
90  Always
91  };
92 
102  Rotation,
103  TranslationRotation,
104  LocalRotation,
105  Resize,
106  Place
107  };
108 
115  X_AXIS = 1,
116  Y_AXIS = 1 << 1,
117  Z_AXIS = 1 << 2,
118  ALL_AXIS = X_AXIS | Y_AXIS | Z_AXIS
119  };
120 
123  const std::string& _name="<TranslationTranslationManipulatorNode>" );
124 
127 
128 
130  ACG_CLASSNAME(TranslationManipulatorNode);
131 
132 
133  //
134  // METHODS
135  //
136 
137  virtual void setIdentity();
138 
140  void set_draw_cylinder(bool _b) { draw_manipulator_ = _b; }
141 
143  bool draw_manipulator() const { return draw_manipulator_; }
144 
146  void set_direction(const Vec3d& _directionX, const Vec3d& _directionY);
147 
149  Vec3d directionX() const;
151  Vec3d directionY() const;
153  Vec3d directionZ() const;
154 
156  void set_size( double _size) { set_manipulator_height_ = _size;
157  set_manipulator_radius_ = _size/10.0;
158  setDirty (); }
159 
161  double size() const { return set_manipulator_height_; }
162 
164  void set_autosize (AutoSizeMode _mode) { auto_size_ = _mode; }
165 
167  AutoSizeMode autosize () const { return auto_size_; }
168 
177  activeRotations_ = _active;
178  }
179 
186  return activeRotations_;
187  }
188 
189  void rotate (double _angle, Vec3d _axis)
190  {
191  TransformNode::rotate(_angle, _axis);
192  }
193 
195  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
196 
198  // void leave(GLState& _state, const DrawModes::DrawMode& _drawMode);
199 
201  void pick(GLState& _state, PickTarget _target);
202 
204  virtual void mouseEvent(GLState& _state, QMouseEvent* _event);
205 
207  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
208 
210  void setMode (ManipulatorMode _mode);
211 
213  ManipulatorMode getMode () const { return mode_; };
214 
215 
216 private:
217 
218  enum StateUpdates {
219  None,
220  Over,
221  Click
222  };
223 
224  enum Elements {
225  Origin = 0,
226  XTop,
227  YTop,
228  ZTop,
229  XAxis,
230  YAxis,
231  ZAxis,
232  XRing,
233  YRing,
234  ZRing,
235  NumElements
236  };
237 
238  class Element {
239  public:
240  Element ();
241 
242  Vec4f active_target_color_;
243  Vec4f active_current_color_;
244  Vec4f inactive_target_color_;
245  Vec4f inactive_current_color_;
246 
247  bool clicked_;
248  bool over_;
249  };
250 
252  void update_manipulator_system(GLState& _state);
253 
255  void update_rotation(GLState& _state);
256 
257  bool hitSphere(GLState& _state, const Vec2i& _v2);
258  bool hitOuterSphere(GLState& _state, const Vec2i& _v2);
259 
260  void drawManipulator (GLState& _state, bool _active);
261 
262  bool mapToCylinder (GLState& _state, const Vec2i& _v2, double& axis_hit, StateUpdates _updateStates = None);
263  bool mapToCylinderTop (GLState& _state, const Vec2i& _v2, double& axis_hit, StateUpdates _updateStates = None);
264 
265  bool mapToSphere (GLState& _state, const Vec2i& _v2, Vec3d& _v3, StateUpdates _updateStates = None);
266 
267  void updateTargetColors ();
268  bool updateCurrentColors (GLState& _state);
269 
270  double get_screen_length (GLState& _state, Vec3d& _point) const;
271 
272  void updateSize (GLState& _state);
273 
274  // ELEMENTS
275  bool draw_manipulator_;
276 
277  Vec3d dirX_;
278  Vec3d dirY_;
279  Vec3d dirZ_;
280 
281  ACG::GLCone* axis_;
282  ACG::GLDisk* circle_;
283  ACG::GLSphere* sphere_;
284 
285  double manipulator_radius_;
286  double manipulator_height_;
287  double set_manipulator_radius_;
288  double set_manipulator_height_;
289  int manipulator_slices_;
290  int manipulator_stacks_;
291 
292  bool any_axis_clicked_;
293  bool any_top_clicked_;
294  bool outer_ring_clicked_;
295 
296  bool any_axis_over_;
297  bool any_top_over_;
298  bool outer_ring_over_;
299 
300 
301  Element element_[NumElements];
302  float resize_current_;
303 
304  ManipulatorMode mode_;
305  bool ignoreTime_;
306 
307  Vec2i oldPoint2D_;
308  Vec3d draggingOrigin3D_;
309  bool dragging_;
310 
311  Vec3d currentScale_;
312 
313  GLMatrixd localTransformation_;
314 
315  AutoSizeMode auto_size_;
316  double auto_size_length_;
317 
318  ActiveRotations activeRotations_;
319 };
320 
321 
322 //=============================================================================
323 } // namespace SceneGraph
324 } // namespace ACG
325 //=============================================================================
326 #endif // ACG_TRANSLATIONMANIPULATOR_NODE_HH defined
327 //=============================================================================
328